summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@gnome.org>2017-04-12 18:23:07 -0700
committerGitHub <noreply@github.com>2017-04-12 18:23:07 -0700
commitbd875ca5cacbb82691394ee689dd56dd04035832 (patch)
treee86d9c5ff13eaf6b7b5498d68624a413a18b544d /test
parent07be6b5e57ce61536b699934e023952509f42d21 (diff)
parente54bec3feb08b09de64945f72885c8c37258de60 (diff)
Merge pull request #4164 from endlessm/T16203
build: Remove Webhelper
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am.inc16
-rw-r--r--test/smoke-tests/webhelper/webview.js160
-rw-r--r--test/smoke-tests/webhelper/webview2.js147
-rw-r--r--test/webhelper/testLocal.js59
-rw-r--r--test/webhelper/testTranslate.js102
-rw-r--r--test/webhelper/testTranslate2.js214
-rw-r--r--test/webhelper/testUpdateFontSize.js97
-rw-r--r--test/webhelper/testWebActions.js141
-rw-r--r--test/webhelper/testWebActions2.js121
9 files changed, 0 insertions, 1057 deletions
diff --git a/test/Makefile.am.inc b/test/Makefile.am.inc
index 6fac9d0..98ec69e 100644
--- a/test/Makefile.am.inc
+++ b/test/Makefile.am.inc
@@ -56,17 +56,6 @@ EXTRA_DIST += \
test/utils.js \
$(NULL)
-if ENABLE_WEBHELPER
-javascript_tests += \
- test/webhelper/testLocal.js \
- test/webhelper/testTranslate.js \
- test/webhelper/testTranslate2.js \
- test/webhelper/testWebActions.js \
- test/webhelper/testWebActions2.js \
- test/webhelper/testUpdateFontSize.js \
- $(NULL)
-endif ENABLE_WEBHELPER
-
# Run tests when running 'make check'
TESTS = \
test/endless/run-tests \
@@ -92,10 +81,6 @@ EXTRA_DIST += \
$(NULL)
CLEANFILES += stderr.log
-if ENABLE_WEBHELPER
-AM_JS_LOG_FLAGS += --include-path=$(top_srcdir)/webhelper
-endif ENABLE_WEBHELPER
-
# Use locally built versions of Endless-0.gir and libraries; this may need to be
# changed to AM_TESTS_ENVIRONMENT in a future version of Automake
# Set XDG_CONFIG_HOME so as to avoid cluttering the user's actual config
@@ -105,7 +90,6 @@ TESTS_ENVIRONMENT = \
export GI_TYPELIB_PATH="$(top_builddir)$${GI_TYPELIB_PATH:+:$$GI_TYPELIB_PATH}"; \
export LD_LIBRARY_PATH="$(top_builddir)/.libs$${LD_LIBRARY_PATH:+:$$LD_LIBRARY_PATH}"; \
export XDG_CONFIG_HOME=`mktemp -d $${TMPDIR:-/tmp}/sdktestconfig.XXXXXXXX`; \
- export WEBHELPER_UNINSTALLED_EXTENSION_DIR="$(top_builddir)/.libs"; \
export TOP_SRCDIR="$(abs_top_srcdir)"; \
export BUILDDIR="."; \
$(NULL)
diff --git a/test/smoke-tests/webhelper/webview.js b/test/smoke-tests/webhelper/webview.js
deleted file mode 100644
index a1dba65..0000000
--- a/test/smoke-tests/webhelper/webview.js
+++ /dev/null
@@ -1,160 +0,0 @@
-//Copyright 2013 Endless Mobile, Inc.
-
-const Endless = imports.gi.Endless;
-const GLib = imports.gi.GLib;
-const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
-const WebHelper = imports.webhelper;
-const WebKit = imports.gi.WebKit;
-
-const TEST_APPLICATION_ID = 'com.endlessm.example.test-webview';
-
-const TEST_HTML = '\
-<html> \
-<head> \
-<title>First page</title> \
-<style> \
-p, form { \
- width: 50%; \
- padding: 1em; \
- background: #FFFFFF; \
-} \
-body { \
- background: #EEEEEE; \
-} \
-</style> \
-</head> \
-\
-<body> \
-<h1>First page</h1> \
-\
-<p><a href="endless://moveToPage?name=page2">Move to page 2</a></p> \
-\
-<p><a \
-href="endless://showMessageFromParameter?msg=This%20is%20a%20message%20from%20the%20URL%20parameter">Show \
-message from parameter in this URL</a></p> \
-\
-<form action="endless://showMessageFromParameter"> \
-<input name="msg" value="I am in a form!"/> \
-<input type="submit" value="Show message using a form"/> \
-</form> \
-\
-<p> \
-<input id="inputformessage" value="my ID is inputformessage"/> \
-<a href="endless://showMessageFromInputField?id=inputformessage">Show message \
-using the &lt;input&gt;\'s ID</a> \
-</p> \
-\
-<p><a href="http://wikipedia.org">Regular link to a Web site</a></p> \
-\
-<p><a href="endless://addStars?id=starspan">I want \
-stars!</a> <span id="starspan"/></p> \
-\
-<p>This is text that will be italicized: <span name="translatable">Hello, \
-world!</span></p> \
-\
-</body> \
-</html>';
-
-const TestApplication = new Lang.Class({
- Name: 'TestApplication',
- Extends: WebHelper.Application,
-
- /* *** ACTIONS AVAILABLE FROM THE WEB VIEW *** */
-
- /* dict['name'] is the name of the page to move to */
- moveToPage: function(dict) {
- this._pm.visible_child_name = dict['name'];
- },
-
- /* dict['msg'] is the message to display */
- showMessageFromParameter: function(dict) {
- let dialog = new Gtk.MessageDialog({
- buttons: Gtk.ButtonsType.CLOSE,
- message_type: Gtk.MessageType.INFO,
- text: dict['msg']
- });
- dialog.set_transient_for(this._window);
- dialog.run();
- dialog.destroy();
- },
-
- /* dict['id'] is the ID of the input field to use */
- showMessageFromInputField: function(dict) {
- let input = this._getElementById(this._webview, dict['id']);
-
- // WebKitDOMHTMLInputElement
- let msg = input.get_value();
-
- let dialog = new Gtk.MessageDialog({
- buttons: Gtk.ButtonsType.CLOSE,
- message_type: Gtk.MessageType.INFO,
- text: msg
- });
- dialog.set_transient_for(this._window);
- dialog.run();
- dialog.destroy();
- },
-
- /* dict['id'] is the ID of the element to use */
- addStars: function(dict) {
- let e = this._getElementById(this._webview, dict['id']);
- e.inner_text += '★ ';
- },
-
- /* *************************** */
-
- vfunc_startup: function() {
- this.parent();
-
- this.set_translation_function(function(string) {
- return string.italics();
- });
- this.define_web_actions({
- moveToPage: this.moveToPage,
- showMessageFromParameter: this.showMessageFromParameter,
- showMessageFromInputField: this.showMessageFromInputField,
- addStars: this.addStars
- });
-
- this._webview = new WebKit.WebView();
- this._webview.load_string(TEST_HTML, 'text/html', 'UTF-8', 'file://');
- this._webview.connect('notify::load-status',
- Lang.bind(this, function (webview) {
- if (webview.load_status == WebKit.LoadStatus.FINISHED)
- this.translate_html(webview);
- }));
-
- this._webview.connect('navigation-policy-decision-requested',
- Lang.bind(this, this.web_actions_handler));
-
- this._page1 = new Gtk.ScrolledWindow();
- this._page1.add(this._webview);
-
- this._page2 = new Gtk.Grid();
- let back_button = new Gtk.Button({ label:"Go back to page 1" });
- back_button.connect('clicked', Lang.bind(this, function() {
- this._pm.visible_child_name = 'page1';
- }));
- this._page2.add(back_button);
-
- this._window = new Endless.Window({
- application: this,
- border_width: 16
- });
-
- this._pm = this._window.page_manager;
- this._pm.set_transition_type(Gtk.StackTransitionType.CROSSFADE);
- this._pm.add(this._page1, { name: 'page1' });
- this._pm.add(this._page2, { name: 'page2' });
- this._pm.visible_child = this._page1;
-
- this._window.show_all();
- }
-});
-
-let app = new TestApplication({
- application_id: TEST_APPLICATION_ID,
- flags: 0
-});
-app.run(ARGV);
diff --git a/test/smoke-tests/webhelper/webview2.js b/test/smoke-tests/webhelper/webview2.js
deleted file mode 100644
index f50c42d..0000000
--- a/test/smoke-tests/webhelper/webview2.js
+++ /dev/null
@@ -1,147 +0,0 @@
-// Copyright 2015 Endless Mobile, Inc.
-
-const Endless = imports.gi.Endless;
-const Gettext = imports.gettext;
-const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
-const WebHelper2 = imports.webhelper2;
-const WebKit2 = imports.gi.WebKit2;
-
-const TEST_APPLICATION_ID = 'com.endlessm.example.test-webview2';
-const TEST_HTML = '\
-<html> \
-<head> \
-<title>First page</title> \
-<style> \
-p, form { \
- width: 50%; \
- padding: 1em; \
- background: #FFFFFF; \
-} \
-body { \
- background: #EEEEEE; \
-} \
-</style> \
-</head> \
-\
-<body> \
-<script type="text/javascript"> \
- window.ngettextButton = (function () { \
- var times = 0; \
- return function () { \
- times++; \
- var message = ngettext("You have clicked me __ time", "You have clicked me __ times", times); \
- alert(message.replace("__", times.toString())); \
- }; \
- })(); \
-</script> \
-<h1>First page</h1> \
-\
-<p><a href="webhelper://moveToPage?name=page2">Move to page 2</a></p> \
-\
-<p><a \
-href="webhelper://showMessageFromParameter?msg=This%20is%20a%20message%20from%20the%20URL%20parameter">Show \
-message from parameter in this URL</a></p> \
-\
-<form action="webhelper://showMessageFromParameter"> \
-<input name="msg" value="I am in a form!"/> \
-<input type="submit" value="Show message using a form"/> \
-</form> \
-\
-<p><a href="http://wikipedia.org">Regular link to a Web site</a></p> \
-\
-<p>This is text that will be italicized: <span name="translatable">Hello, \
-world!</span></p> \
-\
-<p> \
- <button onclick="alert(gettext(\'I came from gettext\'));"> \
- Click me to use gettext \
- </button> \
- <button onclick="ngettextButton();">Click me to use ngettext</button> \
-</p> \
-\
-</body> \
-</html>';
-
-const TestApplication = new Lang.Class({
- Name: 'TestApplication',
- Extends: Endless.Application,
-
- vfunc_dbus_register: function (connection, object_path) {
- this._webhelper = new WebHelper2.WebHelper({
- well_known_name: this.application_id,
- connection: connection,
- });
- return this.parent(connection, object_path);
- },
-
- vfunc_startup: function () {
- this.parent();
-
- this._webhelper.set_gettext((s) => s.italics());
- this._webhelper.set_ngettext((s, p, n) =>
- '** ' + (n == 1 ? s : p) + ' **');
- this._webhelper.define_web_actions({
- moveToPage: this.moveToPage.bind(this),
- showMessageFromParameter: this.showMessageFromParameter.bind(this),
- });
-
- this._webview = new WebKit2.WebView();
- this._webview.connect('load-changed', (webview, event) => {
- if (event === WebKit2.LoadEvent.FINISHED)
- this._webhelper.translate_html(webview, null, (obj, res) => {
- this._webhelper.translate_html_finish(res);
- });
- });
- this._webview.load_html(TEST_HTML, null);
-
- this._page2 = new Gtk.Grid();
- let back_button = new Gtk.Button({ label: 'Go back to page 1' });
- back_button.connect('clicked', () => {
- this._pm.visible_child_name = 'page1';
- });
- this._page2.add(back_button);
-
- this._window = new Endless.Window({
- application: this,
- border_width: 16,
- });
-
- this._pm = this._window.page_manager;
- this._pm.set_transition_type(Gtk.StackTransitionType.CROSSFADE);
- this._pm.add(this._webview, { name: 'page1' });
- this._pm.add(this._page2, { name: 'page2' });
- this._pm.visible_child_name = 'page1';
-
- this._window.show_all();
- },
-
- vfunc_dbus_unregister: function (connection, object_path) {
- this.parent(connection, object_path);
- this._webhelper.unregister();
- },
-
- // WEB ACTIONS
-
- // dict['name'] is the name of the page to move to
- moveToPage: function (dict) {
- this._pm.visible_child_name = dict['name'];
- },
-
- // dict['msg'] is the message to display
- showMessageFromParameter: function (dict) {
- let dialog = new Gtk.MessageDialog({
- buttons: Gtk.ButtonsType.CLOSE,
- message_type: Gtk.MessageType.INFO,
- text: dict['msg'],
- transient_for: this._window,
- });
- dialog.run();
- dialog.destroy();
- },
-});
-
-let app = new TestApplication({
- application_id: TEST_APPLICATION_ID,
-});
-app.run(ARGV);
diff --git a/test/webhelper/testLocal.js b/test/webhelper/testLocal.js
deleted file mode 100644
index d65e6c7..0000000
--- a/test/webhelper/testLocal.js
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2015 Endless Mobile, Inc.
-
-const Gio = imports.gi.Gio;
-const GLib = imports.gi.GLib;
-const Gtk = imports.gi.Gtk;
-const WebHelper2 = imports.webhelper2;
-const WebKit2 = imports.gi.WebKit2;
-
-const WELL_KNOWN_NAME = 'com.endlessm.WebHelper.testLocal';
-
-Gtk.init(null);
-
-describe('Local URI scheme', function () {
- let owner_id, connection, webview, webhelper;
-
- beforeAll(function (done) {
- owner_id = Gio.DBus.own_name(Gio.BusType.SESSION, WELL_KNOWN_NAME,
- Gio.BusNameOwnerFlags.NONE,
- null, // bus acquired
- (con, name) => { // 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,
- });
- webview = new WebKit2.WebView();
- });
-
- afterEach(function () {
- webhelper.unregister();
- });
-
- it('loads a local file', function (done) {
- let path = GLib.build_filenamev([GLib.getenv('TOP_SRCDIR'), 'test',
- 'tools', 'test.html']);
- let test_file = Gio.File.new_for_path(path);
-
- 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) {
- webview.disconnect(id);
- expect(error_spy).not.toHaveBeenCalled();
- done();
- }
- });
- webview.load_uri(test_file.get_uri().replace(/^file:/, 'local:'));
- });
-});
diff --git a/test/webhelper/testTranslate.js b/test/webhelper/testTranslate.js
deleted file mode 100644
index da8c77a..0000000
--- a/test/webhelper/testTranslate.js
+++ /dev/null
@@ -1,102 +0,0 @@
-const Endless = imports.gi.Endless;
-const GLib = imports.gi.GLib;
-const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
-const WebHelper = imports.webhelper;
-const WebKit = imports.gi.WebKit;
-
-const WebHelperApplicationWithTranslatableText = new Lang.Class({
- Name: 'WebHelperApplicationWithTranslatableText',
- Extends: WebHelper.Application,
-
- get_translation_string: function() {
- return 'Translate Me';
- },
-
- vfunc_startup: function() {
- this.parent();
- this.webview = new WebKit.WebView();
- let string = '<html><body><p name="translatable">' +
- this.get_translation_string() +
- '</p></body></html>';
- this.webview.load_string(string, 'text/html', 'UTF-8', 'file://');
- this.win = new Endless.Window({
- application: this
- });
- this.scrolled = new Gtk.ScrolledWindow();
- this.scrolled.add(this.webview);
- this.win.page_manager.add(this.scrolled);
-
- this.webview.connect('notify::load-status', Lang.bind(this, function() {
- if(this.webview.load_status === WebKit.LoadStatus.FINISHED) {
- this.translate_html(this.webview);
- this.quit();
- }
- }));
- }
-});
-
-describe("Translation strategy", function() {
- let app;
-
- beforeEach(function() {
- // FIXME In this version of GJS there is no Posix module, so fake the PID
- let id_string = 'com.endlessm.webhelper.test' + GLib.get_real_time() + fake_pid;
- // Generate a unique ID for each app instance that we test
- let fake_pid = GLib.random_int();
- app = new WebHelperApplicationWithTranslatableText({
- application_id: id_string
- });
- });
-
- describe("translation function", function() {
- let translationFunctionSpy;
- beforeEach(function() {
- translationFunctionSpy = jasmine.createSpy('translate').and.returnValue('Translated');
- });
- it("gets called with string to translate on run", function() {
- app.set_translation_function(translationFunctionSpy);
- app.run([]);
- expect(translationFunctionSpy).toHaveBeenCalledWith(app.get_translation_string());
- });
- });
-
- it("throws when an incompatible type is set as the translation function", function() {
- expect(function() {
- app.set_translation_function({});
- }).toThrow();
- });
-
- // Can't test this right now as there is no support for propagating exceptions across
- // GI interfaces
- xit("throws when there isn't a translation function set", function() {
- expect(function() {
- app.run([]);
- }).toThrow();
- });
-
- it("has a null translation function by default", function() {
- expect(app.get_translation_function()).toBe(null);
- });
-
- it("stores the expected translation function", function() {
- let translation = function(str) {
- return str;
- };
-
- app.set_translation_function(translation);
- expect(app.get_translation_function()).toBe(translation);
- });
-
- it("allows us to store a null translation function", function() {
- let nonNullTranslation = function(str) {
- return str;
- }
-
- // set a non-null translation function first so that we get
- // the non-default behaviour for get_translation_function
- app.set_translation_function(nonNullTranslation);
- app.set_translation_function(null);
- expect(app.get_translation_function()).toBe(null);
- });
-});
diff --git a/test/webhelper/testTranslate2.js b/test/webhelper/testTranslate2.js
deleted file mode 100644
index 6ce4776..0000000
--- a/test/webhelper/testTranslate2.js
+++ /dev/null
@@ -1,214 +0,0 @@
-// Copyright 2015 Endless Mobile, Inc.
-
-const Gio = imports.gi.Gio;
-const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
-const Mainloop = imports.mainloop;
-const WebHelper2 = imports.webhelper2;
-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 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) => { // 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/testUpdateFontSize.js b/test/webhelper/testUpdateFontSize.js
deleted file mode 100644
index dd45d6f..0000000
--- a/test/webhelper/testUpdateFontSize.js
+++ /dev/null
@@ -1,97 +0,0 @@
-const Endless = imports.gi.Endless;
-const Gio = imports.gi.Gio;
-const GLib = imports.gi.GLib;
-const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
-const WebHelper = imports.webhelper;
-const WebKit = imports.gi.WebKit;
-
-const WebUpdateFontSizeTestApplication = new Lang.Class({
- Name: 'WebUpdateFontSizeTestApplication',
- Extends: WebHelper.Application,
-
- vfunc_startup: function () {
- this.parent();
-
- this.webview = new WebKit.WebView();
- this.websettings = this.webview.get_settings();
- this.webview.set_settings(this.websettings);
- this.win = new Endless.Window({
- application: this,
- font_scaling_active: true
- });
-
- /* Typically logic in tests is bad. In this case, we need to inject these
- * callbacks to test specific cases that only occur during the runtime main
- * loop of the test application. */
- if (this.set_font_resizable_callback !== null) {
- this.set_font_resizable_callback(this.win, this.websettings);
- this.websettings.connect('notify::default-font-size', Lang.bind(this, function () {
- this.default_font_size_changed_callback(this.win, this.websettings);
- }));
- }
-
- if (this.accept_callback !== null)
- this.accept_callback(this.win, this.websettings.default_font_size);
- },
-
- accept_callback: null,
-
- set_font_resizable_callback: null,
-
- default_font_size_changed_callback: null
-});
-
-// TODO: These tests depend on a running X Server and Window Manager. That means
-// that they are not runnable in a continuous-integration server
-describe("Web Helper Font Sizes", function () {
- let app;
-
- beforeEach(function () {
- // Generate a unique ID for each app instance that we test
- let fake_pid = GLib.random_int();
- // FIXME In this version of GJS there is no Posix module, so fake the PID
- let id_string = 'com.endlessm.webhelper.test' + GLib.get_real_time() + fake_pid;
-
- app = new WebUpdateFontSizeTestApplication({
- application_id: id_string
- });
- });
-
- it("does not have the default font scale for a tiny window", function () {
- let test_initial_font_size = function (my_win, default_font_size) {
- my_win.font_scaling_default_window_size = 200; // Force a ridiculous value
- // Window's font scaling is a double, web settings' is an integer
- expect(my_win.font_scaling_calculated_font_size).not.toBeCloseTo(default_font_size, 0);
-
- /* This does not immediately quit the application. It sets a flag for termination
- * which will cause the application to be disposed on the next main loop iteration. */
- app.quit();
- };
-
- app.accept_callback = test_initial_font_size;
-
- spyOn(app, 'accept_callback').and.callThrough();
- app.run([]);
- expect(app.accept_callback).toHaveBeenCalled();
- });
-
- it("takes the provided settings default font size on setting resizable", function () {
- app.set_font_resizable_callback = app.set_web_settings_font_resizable;
-
- let test_font_sizing = function (my_win, my_websettings) {
- // Window's font scaling is a double, web settings' is an integer
- expect(my_win.font_scaling_calculated_font_size).toBeCloseTo(my_websettings.default_font_size, 0);
-
- /* This does not immediately quit the application. It sets a flag for termination
- * which will cause the application to be disposed on the next main loop iteration. */
- app.quit();
- };
-
- app.default_font_size_changed_callback = test_font_sizing;
-
- spyOn(app, 'default_font_size_changed_callback').and.callThrough();
- app.run([]);
- expect(app.default_font_size_changed_callback).toHaveBeenCalled();
- });
-});
diff --git a/test/webhelper/testWebActions.js b/test/webhelper/testWebActions.js
deleted file mode 100644
index e937fb6..0000000
--- a/test/webhelper/testWebActions.js
+++ /dev/null
@@ -1,141 +0,0 @@
-const Endless = imports.gi.Endless;
-const Gio = imports.gi.Gio;
-const GLib = imports.gi.GLib;
-const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
-const WebHelper = imports.webhelper;
-const WebKit = imports.gi.WebKit;
-
-const WebActionTestApplication = new Lang.Class({
- Name: 'WebActionTestApplication',
- Extends: WebHelper.Application,
-
- vfunc_startup: function() {
- this.parent();
- this.webview = new WebKit.WebView();
- this.webview.connect('navigation-policy-decision-requested',
- Lang.bind(this, this.web_actions_handler));
- let string = ('<html><head><meta http-equiv="refresh" content="0;url=' +
- this.webActionToTest + '"></head><body></body></html>');
- this.webview.load_string(string, 'text/html', 'UTF-8', 'file://');
- this.win = new Endless.Window({
- application: this
- });
- this.scrolled = new Gtk.ScrolledWindow();
- this.scrolled.add(this.webview);
- this.win.page_manager.add(this.scrolled);
- }
-});
-
-// TODO: These tests depend on a running X Server and Window Manager. That means
-// that they are not runnable in a continuous-integration server
-describe("Web Actions Bindings", function() {
- let app;
- let webActionSpy;
-
- beforeEach(function() {
- // Generate a unique ID for each app instance that we test
- let fake_pid = GLib.random_int();
- // FIXME In this version of GJS there is no Posix module, so fake the PID
- let id_string = 'com.endlessm.webhelper.test' + GLib.get_real_time() + fake_pid;
- app = new WebActionTestApplication({
- application_id: id_string
- });
- webActionSpy = jasmine.createSpy('quitAction').and.callFake(function() {
- // Calls destroy on the applications window, which decrements the hold count on the
- // application and implicitly causes the application to close.
- app.win.destroy();
- });
- });
-
- let RunApplicationWithWebAction = function(app, action) {
- app.webActionToTest = action;
- app.run([]);
- }
- it("has a working quitApplication uri upon defining quitApplication as a string", function() {
- app.define_web_action('quitApplication', webActionSpy);
- RunApplicationWithWebAction(app, 'endless://quitApplication');
-
- expect(webActionSpy).toHaveBeenCalled();
- });
-
- it("is called with a parameter", function() {
- app.define_web_action('getParameterAndQuit', webActionSpy);
- RunApplicationWithWebAction(app, 'endless://getParameterAndQuit?param=value');
-
- expect(webActionSpy).toHaveBeenCalledWith(new jasmine.ObjectContaining({ param: 'value' }));
- });
-
- it("can be called with many parameters", function() {
- app.define_web_action('getParametersAndQuit', webActionSpy);
- RunApplicationWithWebAction(app, 'endless://getParametersAndQuit?first=thefirst&second=thesecond&third=thethird');
-
- expect(webActionSpy).toHaveBeenCalledWith(new jasmine.ObjectContaining({
- first: 'thefirst',
- second: 'thesecond',
- third: 'thethird'
- }));
- });
-
- it("decodes parameter URI names", function() {
- app.define_web_action('getUriDecodedParameterAndQuit', webActionSpy);
- RunApplicationWithWebAction(app, 'endless://getUriDecodedParameterAndQuit?p%C3%A4r%C3%A4m%F0%9F%92%A9=value');
-
- expect(webActionSpy).toHaveBeenCalledWith(new jasmine.ObjectContaining({
- 'päräm💩' : 'value'
- }));
- });
-
- it("decodes parameter URI values", function() {
- app.define_web_action('getUriDecodedParameterValueAndQuit', webActionSpy);
- RunApplicationWithWebAction(app, 'endless://getUriDecodedParameterValueAndQuit?param=v%C3%A1lu%C3%A9%F0%9F%92%A9');
-
- expect(webActionSpy).toHaveBeenCalledWith(new jasmine.ObjectContaining({
- param : 'válué💩'
- }));
- });
-
- // We currently can't catch exceptions across GObject-Introspection callbacks
- xit('bad action is not called', function() {
- expect(function() { RunApplicationWithWebAction(app, 'endless://nonexistentWebAction') }).toThrow();
- });
-
- describe("with blank parameters", function() {
- beforeEach(function() {
- app.define_web_action('getBlankValueAndQuit', webActionSpy);
- RunApplicationWithWebAction(app, 'endless://getBlankValueAndQuit?param=');
- });
-
- it("can be called", function() {
- expect(webActionSpy).toHaveBeenCalled();
- });
-
- it("is called with a paramater that is an empty string", function() {
- expect(webActionSpy).toHaveBeenCalledWith(new jasmine.ObjectContaining({
- 'param' : ''
- }));
- });
- });
-
- it("URI decodes the action", function() {
- app.define_web_action('äction💩Quit', webActionSpy);
- RunApplicationWithWebAction(app, 'endless://%C3%A4ction%F0%9F%92%A9Quit');
- expect(webActionSpy).toHaveBeenCalled();
- });
-
- it("allows web actions to be defined as object properties", function() {
- app.define_web_actions({
- quitApplication: webActionSpy
- });
-
- RunApplicationWithWebAction(app, 'endless://quitApplication');
-
- expect(webActionSpy).toHaveBeenCalled();
- });
-
- it("throws an error when trying to define an action that is not a function", function() {
- expect(function() {
- app.define_web_action('action', {});
- }).toThrow();
- });
-});
diff --git a/test/webhelper/testWebActions2.js b/test/webhelper/testWebActions2.js
deleted file mode 100644
index 5af5e2b..0000000
--- a/test/webhelper/testWebActions2.js
+++ /dev/null
@@ -1,121 +0,0 @@
-const Gio = imports.gi.Gio;
-const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
-const Mainloop = imports.mainloop;
-const WebHelper2 = imports.webhelper2;
-const WebKit2 = imports.gi.WebKit2;
-
-const WELL_KNOWN_NAME = 'com.endlessm.WebHelper.testWebActions2';
-
-Gtk.init(null);
-
-describe('WebKit2 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) => { // 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();
- });
-});