diff options
Diffstat (limited to 'toolkit/components/formautofill/test/browser')
6 files changed, 169 insertions, 0 deletions
diff --git a/toolkit/components/formautofill/test/browser/.eslintrc.js b/toolkit/components/formautofill/test/browser/.eslintrc.js new file mode 100644 index 000000000..7c8021192 --- /dev/null +++ b/toolkit/components/formautofill/test/browser/.eslintrc.js @@ -0,0 +1,7 @@ +"use strict"; + +module.exports = { + "extends": [ + "../../../../../testing/mochitest/browser.eslintrc.js" + ] +}; diff --git a/toolkit/components/formautofill/test/browser/browser.ini b/toolkit/components/formautofill/test/browser/browser.ini new file mode 100644 index 000000000..dff9c3381 --- /dev/null +++ b/toolkit/components/formautofill/test/browser/browser.ini @@ -0,0 +1,10 @@ +[DEFAULT] +# The following files starting with ".." are installed in the current folder. +support-files = + ../head_common.js + ../loader_common.js + head.js + loader.js + +[browser_infrastructure.js] +[browser_ui_requestAutocomplete.js] diff --git a/toolkit/components/formautofill/test/browser/browser_infrastructure.js b/toolkit/components/formautofill/test/browser/browser_infrastructure.js new file mode 100644 index 000000000..af27cfdb5 --- /dev/null +++ b/toolkit/components/formautofill/test/browser/browser_infrastructure.js @@ -0,0 +1,48 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +/* + * Tests the local testing infrastructure. + */ + +"use strict"; + +/** + * Tests the truth assertion function. + */ +add_task(function* test_assert_truth() { + Assert.ok(1 != 2); +}); + +/** + * Tests the equality assertion function. + */ +add_task(function* test_assert_equality() { + Assert.equal(1 + 1, 2); +}); + +/** + * Uses some of the utility functions provided by the framework. + */ +add_task(function* test_utility_functions() { + // The "print" function is useful to log information that is not known before. + let randomString = "R" + Math.floor(Math.random() * 10); + Output.print("The random contents will be '" + randomString + "'."); + + // Create the text file with the random contents. + let path = yield TestUtils.getTempFile("test-infrastructure.txt"); + yield OS.File.writeAtomic(path, new TextEncoder().encode(randomString)); + + // Test a few utility functions. + yield TestUtils.waitForTick(); + yield TestUtils.waitMs(50); + + let promiseMyNotification = TestUtils.waitForNotification("my-topic"); + Services.obs.notifyObservers(null, "my-topic", ""); + yield promiseMyNotification; + + // Check the file size. The file will be deleted automatically later. + Assert.equal((yield OS.File.stat(path)).size, randomString.length); +}); + +add_task(terminationTaskFn); diff --git a/toolkit/components/formautofill/test/browser/browser_ui_requestAutocomplete.js b/toolkit/components/formautofill/test/browser/browser_ui_requestAutocomplete.js new file mode 100644 index 000000000..2a7b58f12 --- /dev/null +++ b/toolkit/components/formautofill/test/browser/browser_ui_requestAutocomplete.js @@ -0,0 +1,48 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +/* + * Tests the requestAutocomplete user interface. + */ + +"use strict"; + +/** + * Open the requestAutocomplete UI and test that selecting a profile results in + * the correct data being sent back to the opener. + */ +add_task(function* test_select_profile() { + // Request an e-mail address. + let { uiWindow, promiseResult } = yield FormAutofillTest.showUI( + TestData.requestEmailOnly); + + // Accept the dialog. + let acceptButton = uiWindow.document.getElementById("accept"); + EventUtils.synthesizeMouseAtCenter(acceptButton, {}, uiWindow); + + let result = yield promiseResult; + Assert.equal(result.fields.length, 1); + Assert.equal(result.fields[0].section, ""); + Assert.equal(result.fields[0].addressType, ""); + Assert.equal(result.fields[0].contactType, ""); + Assert.equal(result.fields[0].fieldName, "email"); + Assert.equal(result.fields[0].value, "email@example.org"); +}); + +/** + * Open the requestAutocomplete UI and cancel the dialog. + */ +add_task(function* test_cancel() { + // Request an e-mail address. + let { uiWindow, promiseResult } = yield FormAutofillTest.showUI( + TestData.requestEmailOnly); + + // Cancel the dialog. + let acceptButton = uiWindow.document.getElementById("cancel"); + EventUtils.synthesizeMouseAtCenter(acceptButton, {}, uiWindow); + + let result = yield promiseResult; + Assert.ok(result.canceled); +}); + +add_task(terminationTaskFn); diff --git a/toolkit/components/formautofill/test/browser/head.js b/toolkit/components/formautofill/test/browser/head.js new file mode 100644 index 000000000..882f3fd5e --- /dev/null +++ b/toolkit/components/formautofill/test/browser/head.js @@ -0,0 +1,18 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +/* + * Initialization specific to Form Autofill mochitest-browser tests. + */ + +"use strict"; + +// We cannot start initialization from "loader.js" like we do in the xpcshell +// and mochitest-chrome frameworks, thus we load the script here. +Services.scriptloader.loadSubScript(getRootDirectory(gTestPath) + "loader.js", + this); + +// The testing framework is fully initialized at this point, you can add +// mochitest-browser specific test initialization here. If you need shared +// functions or initialization that are not specific to mochitest-browser, +// consider adding them to "head_common.js" in the parent folder instead. diff --git a/toolkit/components/formautofill/test/browser/loader.js b/toolkit/components/formautofill/test/browser/loader.js new file mode 100644 index 000000000..bfd5b9ee0 --- /dev/null +++ b/toolkit/components/formautofill/test/browser/loader.js @@ -0,0 +1,38 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +/* + * Infrastructure for the mochitest-browser tests located in this folder. + * + * See "loader_common.js" in the parent folder for a general overview. + * + * Unless you are adding new features to the framework, you shouldn't have to + * modify this file. Use "head_common.js" or "head.js" for shared code. + */ + +"use strict"; + +Services.scriptloader.loadSubScript(getRootDirectory(gTestPath) + + "loader_common.js", this); + +// Define output functions so they look the same across all frameworks. +var Output = { + print: info, +}; + +// Define assertion functions so they look the same across all frameworks. +var Assert = { + ok: _mochitestAssert.ok, + equal: _mochitestAssert.equal, +}; + +// Define task registration functions, see description in "loader_common.js". +var add_task_in_parent_process = add_task; +var add_task_in_child_process = function () {}; +var add_task_in_both_processes = add_task; + +Services.scriptloader.loadSubScript(getRootDirectory(gTestPath) + + "head_common.js", this); + +// Reminder: unless you are adding new features to the framework, you shouldn't +// have to modify this file. Use "head_common.js" or "head.js" for shared code. |