summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMario Sanchez Prada <mario@endlessm.com>2016-04-20 19:03:28 +0100
committerMario Sanchez Prada <mario@endlessm.com>2016-04-21 21:56:53 +0100
commit67582310b542a64583c590c43532e53a5b710d6e (patch)
tree5b9d4f87ca1ab7418afeb06ab6ee41e1fe6e7ba9 /test
parent065e06c6110b191d5a13aa3d8598fc9feac03a46 (diff)
Remove parallel version of WebHelper compatible with WebKit2-3.0
We are no longer shipping the Webkit2-3.0 API on Endless and Virtual School has already been migrated to the newer WebKit2-4.0 API after having fixed all the regressions there and so it makes no sense to keep this any longer. Besides, after the WebKitGTK+ upgrade from 2.4.9 to 2.4.11 debian does no longer ship the WebKit2GTK+-3.0 packages (and there's no point on us bringing them back) so, actually, we can not keep this anyway, so let's remove it. This commit basically reverts 8c837e660853abd03c97a98815f73146eb57c010, but considering all the changes integrated ever since (not a "clean" revert). https://phabricator.endlessm.com/T11388
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am.inc2
-rw-r--r--test/webhelper/testTranslate2Old.js213
-rw-r--r--test/webhelper/testWebActions2Old.js120
3 files changed, 0 insertions, 335 deletions
diff --git a/test/Makefile.am.inc b/test/Makefile.am.inc
index 0fad7a2..727a5df 100644
--- a/test/Makefile.am.inc
+++ b/test/Makefile.am.inc
@@ -47,10 +47,8 @@ javascript_tests = \
test/webhelper/testLocal.js \
test/webhelper/testTranslate.js \
test/webhelper/testTranslate2.js \
- test/webhelper/testTranslate2Old.js \
test/webhelper/testWebActions.js \
test/webhelper/testWebActions2.js \
- test/webhelper/testWebActions2Old.js \
test/webhelper/testUpdateFontSize.js \
test/endless/testCustomContainer.js \
test/endless/testTopbarHomeButton.js \
diff --git a/test/webhelper/testTranslate2Old.js b/test/webhelper/testTranslate2Old.js
deleted file mode 100644
index 66d54ce..0000000
--- a/test/webhelper/testTranslate2Old.js
+++ /dev/null
@@ -1,213 +0,0 @@
-// Copyright 2015 Endless Mobile, Inc.
-
-const Gio = imports.gi.Gio;
-const Gtk = imports.gi.Gtk;
-const Mainloop = imports.mainloop;
-const WebHelper2 = imports.webhelper2_old;
-const WebKit2 = imports.gi.WebKit2;
-
-const WELL_KNOWN_NAME = 'com.endlessm.WebHelper.testTranslate2';
-
-/* CAUTION:
- * All tests trying to use the translation functionality of WebHelper2 must be
- * run in this file, and this file must be run before any other WebHelper2
- * tests in the same process.
- * That is because we can only tell the default web context to load web
- * extensions with user data once per process. WebHelper doesn't support web
- * contexts other than the default one.
- */
-
-Gtk.init(null);
-
-describe('WebHelper2 WebKit2-3.0 translator', function () {
- let webhelper, owner_id, connection;
-
- beforeAll(function (done) {
- owner_id = Gio.DBus.own_name(Gio.BusType.SESSION, WELL_KNOWN_NAME,
- Gio.BusNameOwnerFlags.NONE,
- null, // bus acquired
- (con) => { // name acquired
- connection = con;
- done();
- },
- null); // name lost
- });
-
- afterAll(function () {
- Gio.DBus.unown_name(owner_id);
- });
-
- beforeEach(function () {
- webhelper = new WebHelper2.WebHelper({
- well_known_name: WELL_KNOWN_NAME,
- connection: connection,
- });
- });
-
- afterEach(function () {
- webhelper.unregister();
- });
-
- it('complains about a bad gettext function', function () {
- expect(function () {
- webhelper.set_gettext('I am not a function');
- }).toThrow();
- });
-
- it('gets and sets the gettext function', function () {
- let translation_function = (s) => s;
- webhelper.set_gettext(translation_function);
- expect(webhelper.get_gettext()).toBe(translation_function);
- });
-
- it('has a null gettext function by default', function () {
- expect(webhelper.get_gettext()).toBeNull();
- });
-
- it('can remove the gettext function by setting null', function () {
- webhelper.set_gettext((s) => s);
- expect(webhelper.get_gettext()).not.toBeNull();
- webhelper.set_gettext(null);
- expect(webhelper.get_gettext()).toBeNull();
- });
-
- it('complains about a bad ngettext function', function () {
- expect(function () {
- webhelper.set_ngettext('I am not a function');
- }).toThrow();
- });
-
- it('gets and sets the ngettext function', function () {
- let translation_function = (s, p, n) => n == 1 ? s : p;
- webhelper.set_ngettext(translation_function);
- expect(webhelper.get_ngettext()).toBe(translation_function);
- });
-
- it('has a null ngettext function by default', function () {
- expect(webhelper.get_ngettext()).toBeNull();
- });
-
- it('can remove the ngettext function by setting null', function () {
- webhelper.set_ngettext((s, p, n) => n == 1 ? s : p);
- expect(webhelper.get_ngettext()).not.toBeNull();
- webhelper.set_ngettext(null);
- expect(webhelper.get_ngettext()).toBeNull();
- });
-
- describe('translating a page', function () {
- let webview, gettext_spy;
- const MINIMAL_HTML = '<p name="translatable">Translate Me</p>';
-
- function run_loop(html=MINIMAL_HTML) {
- let error_spy = jasmine.createSpy('error_spy');
- webview.connect('load-failed', error_spy);
- let id = webview.connect('load-changed', (webview, event) => {
- if (event === WebKit2.LoadEvent.FINISHED) {
- webhelper.translate_html(webview, null, (obj, res) => {
- expect(function () {
- webhelper.translate_html_finish(res);
- }).not.toThrow();
- webview.disconnect(id);
- expect(error_spy).not.toHaveBeenCalled();
- Mainloop.quit('webhelper2');
- });
- }
- });
- webview.load_html('<html><body>' + html + '</body></html>', null);
- Mainloop.run('webhelper2');
- }
-
- beforeEach(function () {
- webview = new WebKit2.WebView();
- gettext_spy = jasmine.createSpy('gettext_spy').and.callFake((s) => s);
- webhelper.set_gettext(gettext_spy);
- });
-
- it('translates a string', function () {
- run_loop();
- expect(gettext_spy).toHaveBeenCalledWith('Translate Me');
- });
-
- // The following test is disabled because GJS cannot catch exceptions
- // across FFI interfaces (e.g. in GObject callbacks.)
- xit('complains about a gettext function not being set', function () {
- expect(function () {
- run_loop();
- }).toThrow();
- });
-
- it('can cancel the translation operation', function (done) {
- webhelper.set_gettext((s) => s);
- let error_spy = jasmine.createSpy('error_spy');
- webview.connect('load-failed', error_spy);
- let id = webview.connect('load-changed', (webview, event) => {
- if (event === WebKit2.LoadEvent.FINISHED) {
- let cancellable = new Gio.Cancellable();
- cancellable.cancel();
- webhelper.translate_html(webview, cancellable, (obj, res) => {
- expect(function () {
- webhelper.translate_html_finish(res);
- }).toThrow();
- webview.disconnect(id);
- expect(error_spy).not.toHaveBeenCalled();
- done();
- });
- }
- });
- webview.load_html('<html><body></body></html>', null);
- });
-
- it('normalizes a string before translating it', function () {
- run_loop('<p name="translatable">\n\
- Translate Me\n\
- </p>');
- expect(gettext_spy).toHaveBeenCalledWith('Translate Me');
- });
-
- it('handles quotes correctly', function () {
- run_loop('<p name="translatable">String with "quotes"</p>');
- expect(gettext_spy).toHaveBeenCalledWith('String with "quotes"');
- });
-
- it('handles embedded tags correctly', function () {
- run_loop('<p name="translatable">Embedded<br><b>tags</b></p>');
- expect(gettext_spy).toHaveBeenCalledWith('Embedded<br><b>tags</b>');
- });
- });
-
- describe('used from client-side Javascript', function () {
- let webview;
-
- beforeEach(function () {
- webview = new WebKit2.WebView();
- });
-
- function load_script(view, script) {
- view.load_html('<html><body><script type="text/javascript">' +
- script + '</script></body></html>', null);
- Mainloop.run('webhelper2');
- }
-
- it('translates a string with gettext()', function (done) {
- let gettext_spy = jasmine.createSpy('gettext_spy').and.callFake((s) => {
- Mainloop.quit('webhelper2');
- return s;
- });
- webhelper.set_gettext(gettext_spy);
- load_script(webview, 'gettext("Translate Me");');
- expect(gettext_spy).toHaveBeenCalledWith('Translate Me');
- done();
- });
-
- it('translates a string with ngettext()', function (done) {
- let ngettext_spy = jasmine.createSpy('ngettext_spy').and.callFake((s, p, n) => {
- Mainloop.quit('webhelper2');
- return n == 1 ? s : p;
- });
- webhelper.set_ngettext(ngettext_spy);
- load_script(webview, 'ngettext("File", "Files", 3);');
- expect(ngettext_spy).toHaveBeenCalledWith('File', 'Files', 3);
- done();
- });
- });
-});
diff --git a/test/webhelper/testWebActions2Old.js b/test/webhelper/testWebActions2Old.js
deleted file mode 100644
index a602dc1..0000000
--- a/test/webhelper/testWebActions2Old.js
+++ /dev/null
@@ -1,120 +0,0 @@
-const Gio = imports.gi.Gio;
-const Gtk = imports.gi.Gtk;
-const Mainloop = imports.mainloop;
-const WebHelper2 = imports.webhelper2_old;
-const WebKit2 = imports.gi.WebKit2;
-
-const WELL_KNOWN_NAME = 'com.endlessm.WebHelper.testWebActions2';
-
-Gtk.init(null);
-
-describe('WebKit2-3.0 actions bindings', function () {
- let owner_id, connection, webview, webhelper, web_action_spy;
-
- beforeAll(function (done) {
- owner_id = Gio.DBus.own_name(Gio.BusType.SESSION, WELL_KNOWN_NAME,
- Gio.BusNameOwnerFlags.NONE,
- null, // bus acquired
- (con) => { // name acquired
- connection = con;
- done();
- },
- null); // name lost
- });
-
- afterAll(function () {
- Gio.DBus.unown_name(owner_id);
- });
-
- function run_loop(action_to_test) {
- let string = '<html><head><meta http-equiv="refresh" content="0;url=' +
- action_to_test + '"></head><body></body></html>';
- webview.load_html(string, null);
- Mainloop.run('webhelper2');
- }
-
- beforeEach(function () {
- webhelper = new WebHelper2.WebHelper({
- well_known_name: WELL_KNOWN_NAME,
- connection: connection,
- });
- webview = new WebKit2.WebView();
- web_action_spy = jasmine.createSpy('web_action_spy').and.callFake(() =>
- Mainloop.quit('webhelper2'));
- webhelper.define_web_action('action', web_action_spy);
- });
-
- afterEach(function () {
- webhelper.unregister();
- });
-
- it('calls a web action', function () {
- run_loop('webhelper://action');
- expect(web_action_spy).toHaveBeenCalled();
- });
-
- it('calls a web action with a parameter', function () {
- run_loop('webhelper://action?param=value');
- expect(web_action_spy).toHaveBeenCalledWith(jasmine.objectContaining({
- param: 'value',
- }));
- });
-
- it('calls a web action with many parameters', function () {
- run_loop('webhelper://action?first=thefirst&second=thesecond&third=thethird');
- expect(web_action_spy).toHaveBeenCalledWith(jasmine.objectContaining({
- first: 'thefirst',
- second: 'thesecond',
- third: 'thethird',
- }));
- });
-
- it('uri-decodes parameter names', function () {
- run_loop('webhelper://action?p%C3%A4r%C3%A4m%F0%9F%92%A9=value');
- expect(web_action_spy).toHaveBeenCalledWith(jasmine.objectContaining({
- 'päräm💩': 'value',
- }));
- });
-
- it('uri-decodes parameter values', function () {
- run_loop('webhelper://action?param=v%C3%A1lu%C3%A9%F0%9F%92%A9');
- expect(web_action_spy).toHaveBeenCalledWith(jasmine.objectContaining({
- param: 'válué💩',
- }));
- });
-
- // This is commented out because GJS cannot catch exceptions across FFI
- // interfaces (e.g. in GObject callbacks.)
- xit('raises an exception on a nonexistent action instead of calling it', function () {
- expect(function () {
- run_loop('webhelper://nonexistentAction?param=value');
- }).toThrow();
- });
-
- it('calls a web action with a blank parameter', function () {
- run_loop('webhelper://action?param=');
- expect(web_action_spy).toHaveBeenCalledWith(jasmine.objectContaining({
- param: '',
- }));
- });
-
- it('uri-decodes web action names', function () {
- webhelper.define_web_action('äction💩Quit', web_action_spy);
- run_loop('webhelper://%C3%A4ction%F0%9F%92%A9Quit');
- expect(web_action_spy).toHaveBeenCalled();
- });
-
- it('can define more than one action with define_web_actions()', function () {
- webhelper.define_web_actions({
- action2: web_action_spy,
- });
- run_loop('webhelper://action2');
- expect(web_action_spy).toBeTruthy();
- });
-
- it('complains when defining an action that is not a function', function () {
- expect(function () {
- webhelper.define_web_action('badAction', 'not a function');
- }).toThrow();
- });
-});