From b71ccdd0f0718fdea5da42108afcf194507a84fd Mon Sep 17 00:00:00 2001 From: Patrick Ward Date: Fri, 17 Jan 2014 11:13:01 -0800 Subject: Add publicly available font size property Added a publicly available calculated font size property. This allows Endless applications to perform actions based on the calculated font size of an EosWindow. In particular, the WebHelper application now uses the property to update the 'default-font-size' property of a WebSettings object. [endlessm/eos-sdk#484] --- test/Makefile.am.inc | 1 + test/webhelper/testUpdateFontSize.js | 101 +++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 test/webhelper/testUpdateFontSize.js (limited to 'test') diff --git a/test/Makefile.am.inc b/test/Makefile.am.inc index 74f6fe6..5a95942 100644 --- a/test/Makefile.am.inc +++ b/test/Makefile.am.inc @@ -14,6 +14,7 @@ javascript_tests = \ test/tools/eos-application-manifest/testInit.js \ test/webhelper/testTranslate.js \ test/webhelper/testWebActions.js \ + test/webhelper/testUpdateFontSize.js \ test/wikipedia/models/testCategoryModel.js \ test/wikipedia/models/testArticleModel.js \ test/wikipedia/models/testDomainWikiModel.js \ diff --git a/test/webhelper/testUpdateFontSize.js b/test/webhelper/testUpdateFontSize.js new file mode 100644 index 0000000..4aaaefb --- /dev/null +++ b/test/webhelper/testUpdateFontSize.js @@ -0,0 +1,101 @@ +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); + + // Add an upper bound on how long the app runs, in case app.quit() does + // not get called + GLib.timeout_add_seconds(GLib.PRIORITY_HIGH, 5, Lang.bind(this, function () { + this.quit(); + })); + }, + + 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 + expect(my_win.font_scaling_calculated_font_size).not.toEqual(default_font_size); + + /* 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) { + expect(my_win.font_scaling_calculated_font_size).toEqual(my_websettings.default_font_size); + + /* 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(); + }); +}); -- cgit v1.2.3