mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
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:
parent
5a1eb609f9
commit
d50e3a7301
@ -14,4 +14,5 @@ EXTRA_JS_MODULES += [
|
||||
'UrlbarView.jsm',
|
||||
]
|
||||
|
||||
BROWSER_CHROME_MANIFESTS += ['tests/browser/browser.ini']
|
||||
XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini']
|
||||
|
7
browser/components/urlbar/tests/browser/.eslintrc.js
Normal file
7
browser/components/urlbar/tests/browser/.eslintrc.js
Normal file
@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
"extends": [
|
||||
"plugin:mozilla/browser-test"
|
||||
]
|
||||
};
|
8
browser/components/urlbar/tests/browser/browser.ini
Normal file
8
browser/components/urlbar/tests/browser/browser.ini
Normal 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
|
@ -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,
|
||||
};
|
||||
|
2
browser/components/urlbar/tests/browser/empty.xul
Normal file
2
browser/components/urlbar/tests/browser/empty.xul
Normal file
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0"?>
|
||||
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"/>
|
@ -6,4 +6,3 @@ firefox-appdir = browser
|
||||
[test_tokenizer.js]
|
||||
[test_UrlbarController_unit.js]
|
||||
[test_UrlbarController_integration.js]
|
||||
[test_UrlbarInput_unit.js]
|
||||
|
Loading…
Reference in New Issue
Block a user