diff --git a/browser/components/urlbar/moz.build b/browser/components/urlbar/moz.build index 3d61f4217d2e..3b8343cd6af1 100644 --- a/browser/components/urlbar/moz.build +++ b/browser/components/urlbar/moz.build @@ -14,4 +14,5 @@ EXTRA_JS_MODULES += [ 'UrlbarView.jsm', ] +BROWSER_CHROME_MANIFESTS += ['tests/browser/browser.ini'] XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini'] diff --git a/browser/components/urlbar/tests/browser/.eslintrc.js b/browser/components/urlbar/tests/browser/.eslintrc.js new file mode 100644 index 000000000000..b1c842d8a6db --- /dev/null +++ b/browser/components/urlbar/tests/browser/.eslintrc.js @@ -0,0 +1,7 @@ +"use strict"; + +module.exports = { + "extends": [ + "plugin:mozilla/browser-test" + ] +}; diff --git a/browser/components/urlbar/tests/browser/browser.ini b/browser/components/urlbar/tests/browser/browser.ini new file mode 100644 index 000000000000..75dc42e7acbd --- /dev/null +++ b/browser/components/urlbar/tests/browser/browser.ini @@ -0,0 +1,8 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +[DEFAULT] + +[browser_UrlbarInput_unit.js] +support-files = empty.xul diff --git a/browser/components/urlbar/tests/unit/test_UrlbarInput_unit.js b/browser/components/urlbar/tests/browser/browser_UrlbarInput_unit.js similarity index 73% rename from browser/components/urlbar/tests/unit/test_UrlbarInput_unit.js rename to browser/components/urlbar/tests/browser/browser_UrlbarInput_unit.js index 408e6c25cf14..3b594a6a983f 100644 --- a/browser/components/urlbar/tests/unit/test_UrlbarInput_unit.js +++ b/browser/components/urlbar/tests/browser/browser_UrlbarInput_unit.js @@ -14,7 +14,14 @@ let generalListener; let input; let inputOptions; -ChromeUtils.import("resource://gre/modules/PrivateBrowsingUtils.jsm"); +ChromeUtils.import("resource:///modules/UrlbarController.jsm", this); + +/* global sinon */ +Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js"); + +registerCleanupFunction(function() { + delete window.sinon; +}); /** * Asserts that the query context has the expected values. @@ -32,15 +39,6 @@ function assertContextMatches(context, expectedValues) { } } -/** - * @returns {object} A fake element with minimal functions for simulating textbox etc. - */ -function createFakeElement() { - return { - addEventListener() {}, - }; -} - /** * Checks the result of a handleQuery call on the controller. * @@ -68,7 +66,7 @@ function checkHandleQueryCall(stub, expectedQueryContextProps) { } } -add_task(function setup() { +add_task(async function setup() { sandbox = sinon.sandbox.create(); fakeController = new UrlbarController(); @@ -76,17 +74,30 @@ add_task(function setup() { sandbox.stub(fakeController, "handleQuery"); sandbox.stub(PrivateBrowsingUtils, "isWindowPrivate").returns(false); - let textbox = createFakeElement(); - textbox.inputField = createFakeElement(); - textbox.inputField.controllers = { insertControllerAt() {} }; + // Open a new window, so we don't affect other tests by adding extra + // UrbarInput wrappers around the urlbar. + let gTestRoot = getRootDirectory(gTestPath); + + let win = window.openDialog(gTestRoot + "empty.xul", + "", "chrome"); + await BrowserTestUtils.waitForEvent(win, "load"); + + registerCleanupFunction(async () => { + await BrowserTestUtils.closeWindow(win); + sandbox.restore(); + }); + + // Clone the elements into the new window, so we get exact copies without having + // to replicate the xul. + let doc = win.document; + let textbox = doc.importNode(document.getElementById("urlbar"), true); + doc.documentElement.appendChild(textbox); + let panel = doc.importNode(document.getElementById("urlbar-results"), true); + doc.documentElement.appendChild(panel); + inputOptions = { textbox, - panel: { - ownerDocument: {}, - querySelector() { - return createFakeElement(); - }, - }, + panel, controller: fakeController, }; diff --git a/browser/components/urlbar/tests/browser/empty.xul b/browser/components/urlbar/tests/browser/empty.xul new file mode 100644 index 000000000000..fd9d8e5c78b8 --- /dev/null +++ b/browser/components/urlbar/tests/browser/empty.xul @@ -0,0 +1,2 @@ + + diff --git a/browser/components/urlbar/tests/unit/xpcshell.ini b/browser/components/urlbar/tests/unit/xpcshell.ini index 3f8f41362ec8..3aeabecb67c7 100644 --- a/browser/components/urlbar/tests/unit/xpcshell.ini +++ b/browser/components/urlbar/tests/unit/xpcshell.ini @@ -6,4 +6,3 @@ firefox-appdir = browser [test_tokenizer.js] [test_UrlbarController_unit.js] [test_UrlbarController_integration.js] -[test_UrlbarInput_unit.js]