Bug 1100291 - Fix browser/base/content/test/general/browser_urlbarEnter.js to work with an async getShortcutOrURIAndPostData() r=dao

This commit is contained in:
Tim Taubert 2015-03-06 22:55:20 +01:00
parent d04ed886cd
commit 25f7753fcc

View File

@ -1,69 +1,40 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_VALUE = "example.com/\xF7?\xF7";
const START_VALUE = "example.com/%C3%B7?%C3%B7";
function test() {
waitForExplicitFinish();
runNextTest();
}
function locationBarEnter(aEvent, aClosure) {
executeSoon(function() {
gURLBar.focus();
EventUtils.synthesizeKey("VK_RETURN", aEvent);
addPageShowListener(aClosure);
});
}
function runNextTest() {
let test = gTests.shift();
if (!test) {
finish();
return;
}
info("Running test: " + test.desc);
add_task(function* () {
info("Simple return keypress");
let tab = gBrowser.selectedTab = gBrowser.addTab(START_VALUE);
addPageShowListener(function() {
locationBarEnter(test.event, function() {
test.check(tab);
// Clean up
while (gBrowser.tabs.length > 1)
gBrowser.removeTab(gBrowser.selectedTab)
runNextTest();
});
});
}
gURLBar.focus();
EventUtils.synthesizeKey("VK_RETURN", {});
yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
let gTests = [
{ desc: "Simple return keypress",
event: {},
check: checkCurrent
},
{ desc: "Alt+Return keypress",
event: { altKey: true },
check: checkNewTab,
},
]
function checkCurrent(aTab) {
// Check url bar and selected tab.
is(gURLBar.textValue, TEST_VALUE, "Urlbar should preserve the value on return keypress");
is(gBrowser.selectedTab, aTab, "New URL was loaded in the current tab");
}
is(gBrowser.selectedTab, tab, "New URL was loaded in the current tab");
function checkNewTab(aTab) {
// Cleanup.
gBrowser.removeCurrentTab();
});
add_task(function* () {
info("Alt+Return keypress");
let tab = gBrowser.selectedTab = gBrowser.addTab(START_VALUE);
gURLBar.focus();
EventUtils.synthesizeKey("VK_RETURN", {altKey: true});
yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
// Check url bar and selected tab.
is(gURLBar.textValue, TEST_VALUE, "Urlbar should preserve the value on return keypress");
isnot(gBrowser.selectedTab, aTab, "New URL was loaded in a new tab");
}
function addPageShowListener(aFunc) {
gBrowser.selectedBrowser.addEventListener("pageshow", function loadListener() {
gBrowser.selectedBrowser.removeEventListener("pageshow", loadListener, false);
aFunc();
});
}
isnot(gBrowser.selectedTab, tab, "New URL was loaded in a new tab");
// Cleanup.
gBrowser.removeTab(tab);
gBrowser.removeCurrentTab();
});