Bug 1493668 - Change UrlbarInput unit test to be a mochitest for easier setup. r=dao

Differential Revision: https://phabricator.services.mozilla.com/D6664

--HG--
rename : browser/components/urlbar/tests/unit/test_UrlbarInput_unit.js => browser/components/urlbar/tests/browser/browser_UrlbarInput_unit.js
extra : moz-landing-system : lando
This commit is contained in:
Mark Banner 2018-09-27 15:04:07 +00:00
parent 5a1eb609f9
commit d50e3a7301
6 changed files with 49 additions and 21 deletions

View File

@ -14,4 +14,5 @@ EXTRA_JS_MODULES += [
'UrlbarView.jsm',
]
BROWSER_CHROME_MANIFESTS += ['tests/browser/browser.ini']
XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini']

View File

@ -0,0 +1,7 @@
"use strict";
module.exports = {
"extends": [
"plugin:mozilla/browser-test"
]
};

View File

@ -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

View File

@ -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,
};

View File

@ -0,0 +1,2 @@
<?xml version="1.0"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"/>

View File

@ -6,4 +6,3 @@ firefox-appdir = browser
[test_tokenizer.js]
[test_UrlbarController_unit.js]
[test_UrlbarController_integration.js]
[test_UrlbarInput_unit.js]