summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/webhelper/smoke-tests/webview.js90
-rw-r--r--test/webhelper/testTranslate.js39
-rw-r--r--test/webhelper/testWebActions.js87
3 files changed, 125 insertions, 91 deletions
diff --git a/test/webhelper/smoke-tests/webview.js b/test/webhelper/smoke-tests/webview.js
index 133d4ce..a3b91e5 100644
--- a/test/webhelper/smoke-tests/webview.js
+++ b/test/webhelper/smoke-tests/webview.js
@@ -60,52 +60,46 @@ const TestApplication = new Lang.Class({
Name: 'TestApplication',
Extends: WebHelper.Application,
- _translationFunction: function(string) {
- return string.italics();
+ /* *** ACTIONS AVAILABLE FROM THE WEB VIEW *** */
+
+ /* dict['name'] is the name of the page to move to */
+ moveToPage: function(dict) {
+ this._pm.visible_page_name = dict['name'];
},
- /* *** ACTIONS AVAILABLE FROM THE WEB VIEW *** */
+ /* 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();
- _webActions: {
- /* dict['name'] is the name of the page to move to */
- moveToPage: function(dict) {
- this._pm.visible_page_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 += '★ ';
- }
+ 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 += '★ ';
},
/* *************************** */
@@ -113,6 +107,16 @@ const TestApplication = new Lang.Class({
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',
diff --git a/test/webhelper/testTranslate.js b/test/webhelper/testTranslate.js
index 10e389c..651ddf5 100644
--- a/test/webhelper/testTranslate.js
+++ b/test/webhelper/testTranslate.js
@@ -49,24 +49,47 @@ function setUp() {
function testStringIsTranslated() {
let translationFunctionWasCalled = false;
let translationFunctionCalledWithString;
- app._translationFunction = function(s) {
+ app.set_translation_function(function(s) {
translationFunctionWasCalled = true;
translationFunctionCalledWithString = s;
return s;
- };
+ });
app.run([]);
assertTrue(translationFunctionWasCalled);
assertEquals('Translate Me', translationFunctionCalledWithString);
}
-// The following two tests are commented out because GJS cannot catch exceptions
+// The following test is commented out because GJS cannot catch exceptions
// across FFI interfaces (e.g. in GObject callbacks.)
// function testMissingTranslationFunctionIsHandled() {
-// assertRaises(app.run([]));
+// assertRaises(function() {
+// app.run([]);
+// });
// }
-// function testBadTranslationFunctionIsHandled() {
-// app._translationFunction = "I am not a function";
-// assertRaises(app.run([]));
-// } \ No newline at end of file
+function testSetBadTranslationFunction() {
+ assertRaises(function() {
+ app.set_translation_function("I am not a function");
+ });
+}
+
+function testGetSetTranslationFunction() {
+ let translationFunction = function(string) {
+ return string;
+ };
+ app.set_translation_function(translationFunction);
+ let actualTranslationFunction = app.get_translation_function();
+ assertEquals(translationFunction, actualTranslationFunction);
+}
+
+function testTranslationFunctionIsNullByDefault() {
+ assertNull(app.get_translation_function());
+}
+
+function testGetSetNullTranslationFunction() {
+ app.set_translation_function(function (s) { return s; });
+ assertNotNull(app.get_translation_function());
+ app.set_translation_function(null);
+ assertNull(app.get_translation_function());
+}
diff --git a/test/webhelper/testWebActions.js b/test/webhelper/testWebActions.js
index 585ab00..72ea6ba 100644
--- a/test/webhelper/testWebActions.js
+++ b/test/webhelper/testWebActions.js
@@ -45,12 +45,10 @@ function setUp() {
function testWebActionIsCalled() {
let actionWasCalled = false;
- app._webActions = {
- quitApplication: function() {
- actionWasCalled = true;
- app.quit();
- }
- };
+ app.define_web_action('quitApplication', function() {
+ actionWasCalled = true;
+ app.quit();
+ });
app.webActionToTest = 'endless://quitApplication';
app.run([]);
assertTrue(actionWasCalled);
@@ -58,12 +56,10 @@ function testWebActionIsCalled() {
function testWebActionIsCalledWithParameter() {
let actionParameter;
- app._webActions = {
- getParameterAndQuit: function(dict) {
- actionParameter = dict['param'];
- app.quit();
- }
- };
+ app.define_web_action('getParameterAndQuit', function(dict) {
+ actionParameter = dict['param'];
+ app.quit();
+ });
app.webActionToTest = 'endless://getParameterAndQuit?param=value';
app.run([]);
assertEquals('value', actionParameter);
@@ -71,14 +67,12 @@ function testWebActionIsCalledWithParameter() {
function testWebActionIsCalledWithManyParameters() {
let firstParameter, secondParameter, thirdParameter;
- app._webActions = {
- getParametersAndQuit: function(dict) {
- firstParameter = dict['first'];
- secondParameter = dict['second'];
- thirdParameter = dict['third'];
- app.quit();
- }
- };
+ app.define_web_action('getParametersAndQuit', function(dict) {
+ firstParameter = dict['first'];
+ secondParameter = dict['second'];
+ thirdParameter = dict['third'];
+ app.quit();
+ });
app.webActionToTest = 'endless://getParametersAndQuit?first=thefirst&second=thesecond&third=thethird';
app.run([]);
assertEquals('thefirst', firstParameter);
@@ -89,12 +83,10 @@ function testWebActionIsCalledWithManyParameters() {
function testParameterNameIsUriDecoded() {
let expectedParameter = 'päräm💩';
let parameterWasFound = false;
- app._webActions = {
- getUriDecodedParameterAndQuit: function(dict) {
- parameterWasFound = (expectedParameter in dict);
- app.quit();
- }
- };
+ app.define_web_action('getUriDecodedParameterAndQuit', function(dict) {
+ parameterWasFound = (expectedParameter in dict);
+ app.quit();
+ });
app.webActionToTest = 'endless://getUriDecodedParameterAndQuit?p%C3%A4r%C3%A4m%F0%9F%92%A9=value';
app.run([]);
assertTrue(parameterWasFound);
@@ -103,12 +95,10 @@ function testParameterNameIsUriDecoded() {
function testParameterValueIsUriDecoded() {
let expectedValue = 'válué💩';
let actualValue;
- app._webActions = {
- getUriDecodedValueAndQuit: function(dict) {
- actualValue = dict['param'];
- app.quit();
- }
- };
+ app.define_web_action('getUriDecodedValueAndQuit', function(dict) {
+ actualValue = dict['param'];
+ app.quit();
+ });
app.webActionToTest = 'endless://getUriDecodedValueAndQuit?param=v%C3%A1lu%C3%A9%F0%9F%92%A9';
app.run([]);
assertEquals(expectedValue, actualValue);
@@ -124,17 +114,34 @@ function testParameterValueIsUriDecoded() {
function testWebActionIsCalledWithBlankParameter() {
let parameterWasFound = false;
let parameterValue;
- app._webActions = {
- getBlankValueAndQuit: function(dict) {
- parameterWasFound = ('param' in dict);
- if(parameterWasFound)
- parameterValue = dict['param'];
- app.quit();
- }
- };
+ app.define_web_action('getBlankValueAndQuit', function(dict) {
+ parameterWasFound = ('param' in dict);
+ if(parameterWasFound)
+ parameterValue = dict['param'];
+ app.quit();
+ });
app.webActionToTest = 'endless://getBlankValueAndQuit?param=';
app.run([]);
assertTrue(parameterWasFound);
assertNotUndefined(parameterValue);
assertEquals('', parameterValue);
}
+
+function testDefineMultipleActionsOverride() {
+ let actionWasCalled = false;
+ app.define_web_actions({
+ quitApplication: function() {
+ actionWasCalled = true;
+ app.quit();
+ }
+ });
+ app.webActionToTest = 'endless://quitApplication';
+ app.run([]);
+ assertTrue(actionWasCalled);
+}
+
+function testDefineBadAction() {
+ assertRaises(function() {
+ app.define_web_action('badAction', 'not a function');
+ });
+}