--- a/browser/base/content/test/urlbar/browser_action_keyword.js
+++ b/browser/base/content/test/urlbar/browser_action_keyword.js
@@ -15,17 +15,17 @@ add_task(function*() {
let tab = gBrowser.selectedTab = gBrowser.addTab("about:mozilla");
let tabs = [tab];
registerCleanupFunction(function* () {
for (let tab of tabs)
gBrowser.removeTab(tab);
yield PlacesUtils.bookmarks.remove(bm);
});
- yield promiseTabLoadEvent(tab);
+ yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "http://example.com/?q=%s",
title: "test" });
yield PlacesUtils.keywords.insert({ keyword: "keyword",
url: "http://example.com/?q=%s" });
let result = yield promise_first_result("keyword something");
@@ -34,17 +34,17 @@ add_task(function*() {
let types = new Set(result.getAttribute("type").split(/\s+/));
Assert.ok(types.has("keyword"));
is(result.getAttribute("actiontype"), "keyword", "Expect correct `actiontype` attribute");
is(result.getAttribute("title"), "example.com", "Expect correct title");
// We need to make a real URI out of this to ensure it's normalised for
// comparison.
let uri = NetUtil.newURI(result.getAttribute("url"));
- is(uri.spec, makeActionURI("keyword", {url: "http://example.com/?q=something", input: "keyword something"}).spec, "Expect correct url");
+ is(uri.spec, PlacesUtils.mozActionURI("keyword", {url: "http://example.com/?q=something", input: "keyword something"}), "Expect correct url");
let titleHbox = result._titleText.parentNode.parentNode;
ok(titleHbox.classList.contains("ac-title"), "Title hbox element sanity check");
is_element_visible(titleHbox, "Title element should be visible");
is(result._titleText.textContent, "example.com: something", "Node should contain the name of the bookmark and query");
let urlHbox = result._urlText.parentNode.parentNode;
ok(urlHbox.classList.contains("ac-url"), "URL hbox element sanity check");
@@ -52,30 +52,30 @@ add_task(function*() {
let actionHbox = result._actionText.parentNode.parentNode;
ok(actionHbox.classList.contains("ac-action"), "Action hbox element sanity check");
is_element_visible(actionHbox, "Action element should be visible");
is(result._actionText.textContent, "", "Action text should be empty");
// Click on the result
info("Normal click on result");
- let tabPromise = promiseTabLoadEvent(tab);
+ let tabPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
EventUtils.synthesizeMouseAtCenter(result, {});
yield tabPromise;
is(tab.linkedBrowser.currentURI.spec, "http://example.com/?q=something", "Tab should have loaded from clicking on result");
// Middle-click on the result
info("Middle-click on result");
result = yield promise_first_result("keyword somethingmore");
isnot(result, null, "Expect a keyword result");
// We need to make a real URI out of this to ensure it's normalised for
// comparison.
uri = NetUtil.newURI(result.getAttribute("url"));
- is(uri.spec, makeActionURI("keyword", {url: "http://example.com/?q=somethingmore", input: "keyword somethingmore"}).spec, "Expect correct url");
+ is(uri.spec, PlacesUtils.mozActionURI("keyword", {url: "http://example.com/?q=somethingmore", input: "keyword somethingmore"}), "Expect correct url");
tabPromise = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabOpen");
EventUtils.synthesizeMouseAtCenter(result, {button: 1});
let tabOpenEvent = yield tabPromise;
let newTab = tabOpenEvent.target;
tabs.push(newTab);
- yield promiseTabLoadEvent(newTab);
+ yield BrowserTestUtils.browserLoaded(newTab.linkedBrowser);
is(newTab.linkedBrowser.currentURI.spec, "http://example.com/?q=somethingmore", "Tab should have loaded from middle-clicking on result");
});
--- a/browser/base/content/test/urlbar/browser_action_searchengine.js
+++ b/browser/base/content/test/urlbar/browser_action_searchengine.js
@@ -1,17 +1,16 @@
add_task(function* () {
Services.search.addEngineWithDetails("MozSearch", "", "", "", "GET",
"http://example.com/?q={searchTerms}");
let engine = Services.search.getEngineByName("MozSearch");
let originalEngine = Services.search.currentEngine;
Services.search.currentEngine = engine;
- let tab = gBrowser.selectedTab = gBrowser.addTab("about:mozilla", {animate: false});
- yield promiseTabLoaded(gBrowser.selectedTab);
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
registerCleanupFunction(() => {
Services.search.currentEngine = originalEngine;
let engine = Services.search.getEngineByName("MozSearch");
Services.search.removeEngine(engine);
try {
gBrowser.removeTab(tab);
@@ -24,14 +23,14 @@ add_task(function* () {
let result = gURLBar.popup.richlistbox.firstChild;
isnot(result, null, "Should have a result");
is(result.getAttribute("url"),
`moz-action:searchengine,{"engineName":"MozSearch","input":"open%20a%20search","searchQuery":"open%20a%20search"}`,
"Result should be a moz-action: for the correct search engine");
is(result.hasAttribute("image"), false, "Result shouldn't have an image attribute");
- let tabPromise = promiseTabLoaded(gBrowser.selectedTab);
+ let tabPromise = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
result.click();
yield tabPromise;
is(gBrowser.selectedBrowser.currentURI.spec, "http://example.com/?q=open+a+search", "Correct URL should be loaded");
});
--- a/browser/base/content/test/urlbar/browser_action_searchengine_alias.js
+++ b/browser/base/content/test/urlbar/browser_action_searchengine_alias.js
@@ -1,18 +1,17 @@
add_task(function* () {
let iconURI = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGklEQVQoz2NgGB6AnZ1dUlJSXl4eSDIyMhLW4Ovr%2B%2Fr168uXL69Zs4YoG%2BLi4i5dusTExMTGxsbNzd3f37937976%2BnpmZmagbHR09J49e5YvX66kpATVEBYW9ubNm2nTphkbG7e2tp44cQLIuHfvXm5urpaWFlDKysqqu7v73LlzECMYIiIiHj58mJCQoKKicvXq1bS0NKBgW1vbjh074uPjgeqAXE1NzSdPnvDz84M0AEUvXLgAsW379u1z5swBen3jxo2zZ892cHB4%2BvQp0KlAfwI1cHJyghQFBwfv2rULokFXV%2FfixYu7d%2B8GGqGgoMDKyrpu3br9%2B%2FcDuXl5eVA%2FAEWBfoWHAdAYoNuAYQ0XAeoUERFhGDYAAPoUaT2dfWJuAAAAAElFTkSuQmCC";
Services.search.addEngineWithDetails("MozSearch", iconURI, "moz", "", "GET",
"http://example.com/?q={searchTerms}");
let engine = Services.search.getEngineByName("MozSearch");
let originalEngine = Services.search.currentEngine;
Services.search.currentEngine = engine;
- let tab = gBrowser.selectedTab = gBrowser.addTab("about:mozilla", {animate: false});
- yield promiseTabLoaded(gBrowser.selectedTab);
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
registerCleanupFunction(() => {
Services.search.currentEngine = originalEngine;
let engine = Services.search.getEngineByName("MozSearch");
Services.search.removeEngine(engine);
try {
gBrowser.removeTab(tab);
@@ -23,13 +22,14 @@ add_task(function* () {
yield promiseAutocompleteResultPopup("moz open a search");
let result = gURLBar.popup.richlistbox.children[0];
ok(result.hasAttribute("image"), "Result should have an image attribute");
ok(result.getAttribute("image") === engine.iconURI.spec,
"Image attribute should have the search engine's icon");
+ let tabPromise = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
EventUtils.synthesizeKey("VK_RETURN", { });
- yield promiseTabLoaded(gBrowser.selectedTab);
+ yield tabPromise;
is(gBrowser.selectedBrowser.currentURI.spec, "http://example.com/?q=open+a+search");
});
--- a/browser/base/content/test/urlbar/browser_autocomplete_a11y_label.js
+++ b/browser/base/content/test/urlbar/browser_autocomplete_a11y_label.js
@@ -1,18 +1,17 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const SUGGEST_ALL_PREF = "browser.search.suggest.enabled";
const SUGGEST_URLBAR_PREF = "browser.urlbar.suggest.searches";
const TEST_ENGINE_BASENAME = "searchSuggestionEngine.xml";
add_task(function* switchToTab() {
- let tab = gBrowser.addTab("about:about");
- yield promiseTabLoaded(tab);
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:about");
yield promiseAutocompleteResultPopup("% about");
ok(gURLBar.popup.richlistbox.children.length > 1, "Should get at least 2 results");
let result = gURLBar.popup.richlistbox.children[1];
is(result.getAttribute("type"), "switchtab", "Expect right type attribute");
is(result.label, "about:about about:about Tab", "Result a11y label should be: <title> <url> Tab");
--- a/browser/base/content/test/urlbar/browser_autocomplete_autoselect.js
+++ b/browser/base/content/test/urlbar/browser_autocomplete_autoselect.js
@@ -37,18 +37,17 @@ add_task(function*() {
let visits = [];
repeat(maxResults, i => {
visits.push({
uri: makeURI("http://example.com/autocomplete/?" + i),
});
});
yield PlacesTestUtils.addVisits(visits);
- let tab = gBrowser.selectedTab = gBrowser.addTab("about:mozilla", {animate: false});
- yield promiseTabLoaded(tab);
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
yield promiseAutocompleteResultPopup("example.com/autocomplete");
let popup = gURLBar.popup;
let results = popup.richlistbox.children;
is(results.length, maxResults,
"Should get maxResults=" + maxResults + " results");
is_selected(0);
--- a/browser/base/content/test/urlbar/browser_autocomplete_cursor.js
+++ b/browser/base/content/test/urlbar/browser_autocomplete_cursor.js
@@ -1,11 +1,10 @@
add_task(function*() {
- let tab = gBrowser.selectedTab = gBrowser.addTab("about:mozilla", {animate: false});
- yield promiseTabLoaded(tab);
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
yield promiseAutocompleteResultPopup("www.mozilla.org");
gURLBar.selectTextRange(4, 4);
is(gURLBar.popup.state, "open", "Popup should be open");
is(gURLBar.popup.richlistbox.selectedIndex, 0, "Should have selected something");
EventUtils.synthesizeKey("VK_RIGHT", {});
--- a/browser/base/content/test/urlbar/browser_autocomplete_no_title.js
+++ b/browser/base/content/test/urlbar/browser_autocomplete_no_title.js
@@ -1,11 +1,10 @@
add_task(function*() {
- let tab = gBrowser.selectedTab = gBrowser.addTab("about:mozilla", {animate: false});
- yield promiseTabLoaded(tab);
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
let uri = NetUtil.newURI("http://bug1060642.example.com/beards/are/pretty/great");
yield PlacesTestUtils.addVisits([{uri: uri, title: ""}]);
yield promiseAutocompleteResultPopup("bug1060642");
ok(gURLBar.popup.richlistbox.children.length > 1, "Should get at least 2 results");
let result = gURLBar.popup.richlistbox.children[1];
is(result._titleText.textContent, "bug1060642.example.com", "Result title should be as expected");
--- a/browser/base/content/test/urlbar/browser_bug1003461-switchtab-override.js
+++ b/browser/base/content/test/urlbar/browser_bug1003461-switchtab-override.js
@@ -1,32 +1,29 @@
/* 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/. */
add_task(function* test_switchtab_override() {
let testURL = "http://example.org/browser/browser/base/content/test/urlbar/dummy_page.html";
info("Opening first tab");
- let tab = gBrowser.addTab(testURL);
- let deferred = Promise.defer();
- whenTabLoaded(tab, deferred.resolve);
- yield deferred.promise;
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, testURL);
info("Opening and selecting second tab");
let secondTab = gBrowser.selectedTab = gBrowser.addTab();
registerCleanupFunction(() => {
try {
gBrowser.removeTab(tab);
gBrowser.removeTab(secondTab);
} catch (ex) { /* tabs may have already been closed in case of failure */ }
});
info("Wait for autocomplete")
- deferred = Promise.defer();
+ let deferred = Promise.defer();
let onSearchComplete = gURLBar.onSearchComplete;
registerCleanupFunction(() => {
gURLBar.onSearchComplete = onSearchComplete;
});
gURLBar.onSearchComplete = function () {
ok(gURLBar.popupOpen, "The autocomplete popup is correctly open");
onSearchComplete.apply(gURLBar);
deferred.resolve();
@@ -47,17 +44,17 @@ add_task(function* test_switchtab_overri
let onTabSelect = event => {
deferred.reject(new Error("Should have overridden switch to tab"));
};
gBrowser.tabContainer.addEventListener("TabSelect", onTabSelect, false);
registerCleanupFunction(() => {
gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect, false);
});
// Otherwise it would load the page.
- whenTabLoaded(secondTab, deferred.resolve);
+ BrowserTestUtils.browserLoaded(secondTab.linkedBrowser).then(deferred.resolve);
EventUtils.synthesizeKey("VK_SHIFT", { type: "keydown" });
EventUtils.synthesizeKey("VK_RETURN", { });
info(`gURLBar.value = ${gURLBar.value}`);
EventUtils.synthesizeKey("VK_SHIFT", { type: "keyup" });
yield deferred.promise;
yield PlacesTestUtils.clearHistory();
--- a/browser/base/content/test/urlbar/browser_bug1024133-switchtab-override-keynav.js
+++ b/browser/base/content/test/urlbar/browser_bug1024133-switchtab-override-keynav.js
@@ -1,20 +1,17 @@
/* 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/. */
add_task(function* test_switchtab_override_keynav() {
let testURL = "http://example.org/browser/browser/base/content/test/urlbar/dummy_page.html";
info("Opening first tab");
- let tab = gBrowser.addTab(testURL);
- let tabLoadDeferred = Promise.defer();
- whenTabLoaded(tab, tabLoadDeferred.resolve);
- yield tabLoadDeferred.promise;
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, testURL);
info("Opening and selecting second tab");
let secondTab = gBrowser.selectedTab = gBrowser.addTab();
registerCleanupFunction(() => {
try {
gBrowser.removeTab(tab);
gBrowser.removeTab(secondTab);
} catch (ex) { /* tabs may have already been closed in case of failure */ }
--- a/browser/base/content/test/urlbar/browser_bug1025195_switchToTabHavingURI_aOpenParams.js
+++ b/browser/base/content/test/urlbar/browser_bug1025195_switchToTabHavingURI_aOpenParams.js
@@ -1,110 +1,100 @@
/* 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/. */
-add_task(function *test_ignoreFragment() {
- let tabRefAboutHome = gBrowser.addTab("about:home#1");
- yield promiseTabLoaded(tabRefAboutHome);
- let tabRefAboutMozilla = gBrowser.addTab("about:mozilla");
- yield promiseTabLoaded(tabRefAboutMozilla);
-
- gBrowser.selectedTab = tabRefAboutMozilla;
+add_task(function* test_ignoreFragment() {
+ let tabRefAboutHome =
+ yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:home#1");
+ yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
let numTabsAtStart = gBrowser.tabs.length;
switchTab("about:home#1", true);
switchTab("about:mozilla", true);
- let hashChangePromise = new Promise(resolve => {
- tabRefAboutHome.linkedBrowser.contentWindow.addEventListener("hashchange", resolve, false);
+ let hashChangePromise = ContentTask.spawn(tabRefAboutHome.linkedBrowser, null, function* () {
+ yield ContentTaskUtils.waitForEvent(this, "hashchange", false);
});
switchTab("about:home#2", true, { ignoreFragment: "whenComparingAndReplace" });
is(tabRefAboutHome, gBrowser.selectedTab, "The same about:home tab should be switched to");
yield hashChangePromise;
is(gBrowser.currentURI.ref, "2", "The ref should be updated to the new ref");
switchTab("about:mozilla", true);
switchTab("about:home#3", true, { ignoreFragment: "whenComparing" });
is(tabRefAboutHome, gBrowser.selectedTab, "The same about:home tab should be switched to");
is(gBrowser.currentURI.ref, "2", "The ref should be unchanged since the fragment is only ignored when comparing");
switchTab("about:mozilla", true);
switchTab("about:home#1", false);
isnot(tabRefAboutHome, gBrowser.selectedTab, "Selected tab should not be initial about:blank tab");
is(gBrowser.tabs.length, numTabsAtStart + 1, "Should have one new tab opened");
switchTab("about:mozilla", true);
switchTab("about:home", true, {ignoreFragment: "whenComparingAndReplace"});
- yield promiseWaitForCondition(function() {
+ yield BrowserTestUtils.waitForCondition(function() {
return tabRefAboutHome.linkedBrowser.currentURI.spec == "about:home";
});
is(tabRefAboutHome.linkedBrowser.currentURI.spec, "about:home", "about:home shouldn't have hash");
switchTab("about:about", false, { ignoreFragment: "whenComparingAndReplace" });
cleanupTestTabs();
});
add_task(function* test_ignoreQueryString() {
- let tabRefAboutHome = gBrowser.addTab("about:home?hello=firefox");
- yield promiseTabLoaded(tabRefAboutHome);
- let tabRefAboutMozilla = gBrowser.addTab("about:mozilla");
- yield promiseTabLoaded(tabRefAboutMozilla);
- gBrowser.selectedTab = tabRefAboutMozilla;
+ let tabRefAboutHome =
+ yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:home?hello=firefox");
+ yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
switchTab("about:home?hello=firefox", true);
switchTab("about:home?hello=firefoxos", false);
// Remove the last opened tab to test ignoreQueryString option.
gBrowser.removeCurrentTab();
switchTab("about:home?hello=firefoxos", true, { ignoreQueryString: true });
is(tabRefAboutHome, gBrowser.selectedTab, "Selected tab should be the initial about:home tab");
is(gBrowser.currentURI.spec, "about:home?hello=firefox", "The spec should NOT be updated to the new query string");
cleanupTestTabs();
});
add_task(function* test_replaceQueryString() {
- let tabRefAboutHome = gBrowser.addTab("about:home?hello=firefox");
- yield promiseTabLoaded(tabRefAboutHome);
- let tabRefAboutMozilla = gBrowser.addTab("about:mozilla");
- yield promiseTabLoaded(tabRefAboutMozilla);
- gBrowser.selectedTab = tabRefAboutMozilla;
+ let tabRefAboutHome =
+ yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:home?hello=firefox");
+ yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
switchTab("about:home", false);
switchTab("about:home?hello=firefox", true);
switchTab("about:home?hello=firefoxos", false);
// Remove the last opened tab to test replaceQueryString option.
gBrowser.removeCurrentTab();
switchTab("about:home?hello=firefoxos", true, { replaceQueryString: true });
is(tabRefAboutHome, gBrowser.selectedTab, "Selected tab should be the initial about:home tab");
// Wait for the tab to load the new URI spec.
- yield promiseTabLoaded(tabRefAboutHome);
+ yield BrowserTestUtils.browserLoaded(tabRefAboutHome.linkedBrowser);
is(gBrowser.currentURI.spec, "about:home?hello=firefoxos", "The spec should be updated to the new spec");
cleanupTestTabs();
});
add_task(function* test_replaceQueryStringAndFragment() {
- let tabRefAboutHome = gBrowser.addTab("about:home?hello=firefox#aaa");
- yield promiseTabLoaded(tabRefAboutHome);
- let tabRefAboutMozilla = gBrowser.addTab("about:mozilla?hello=firefoxos#aaa");
- yield promiseTabLoaded(tabRefAboutMozilla);
- gBrowser.selectedTab = tabRefAboutMozilla;
+ let tabRefAboutHome =
+ yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:home?hello=firefox#aaa");
+ let tabRefAboutMozilla =
+ yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla?hello=firefoxos#aaa");
switchTab("about:home", false);
gBrowser.removeCurrentTab();
switchTab("about:home?hello=firefox#aaa", true);
is(tabRefAboutHome, gBrowser.selectedTab, "Selected tab should be the initial about:home tab");
switchTab("about:mozilla?hello=firefox#bbb", true, { replaceQueryString: true, ignoreFragment: "whenComparingAndReplace" });
is(tabRefAboutMozilla, gBrowser.selectedTab, "Selected tab should be the initial about:mozilla tab");
switchTab("about:home?hello=firefoxos#bbb", true, { ignoreQueryString: true, ignoreFragment: "whenComparingAndReplace" });
is(tabRefAboutHome, gBrowser.selectedTab, "Selected tab should be the initial about:home tab");
cleanupTestTabs();
});
add_task(function* test_ignoreQueryStringIgnoresFragment() {
- let tabRefAboutHome = gBrowser.addTab("about:home?hello=firefox#aaa");
- yield promiseTabLoaded(tabRefAboutHome);
- let tabRefAboutMozilla = gBrowser.addTab("about:mozilla?hello=firefoxos#aaa");
- yield promiseTabLoaded(tabRefAboutMozilla);
- gBrowser.selectedTab = tabRefAboutMozilla;
+ let tabRefAboutHome =
+ yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:home?hello=firefox#aaa");
+ yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla?hello=firefoxos#aaa");
switchTab("about:home?hello=firefox#bbb", false, { ignoreQueryString: true });
gBrowser.removeCurrentTab();
switchTab("about:home?hello=firefoxos#aaa", true, { ignoreQueryString: true });
is(tabRefAboutHome, gBrowser.selectedTab, "Selected tab should be the initial about:home tab");
cleanupTestTabs();
});
--- a/browser/base/content/test/urlbar/browser_bug1070778.js
+++ b/browser/base/content/test/urlbar/browser_bug1070778.js
@@ -22,18 +22,17 @@ add_task(function*() {
title: "keyword abc" })));
registerCleanupFunction(function* () {
for (let bm of bookmarks) {
yield PlacesUtils.bookmarks.remove(bm);
}
});
- let tab = gBrowser.selectedTab = gBrowser.addTab("about:mozilla", {animate: false});
- yield promiseTabLoaded(tab);
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
yield promiseAutocompleteResultPopup("keyword a");
// First item should already be selected
is_selected(0);
// Select next one (important!)
EventUtils.synthesizeKey("VK_DOWN", {});
is_selected(1);
// Re-select keyword item
@@ -43,14 +42,14 @@ add_task(function*() {
EventUtils.synthesizeKey("b", {});
yield promiseSearchComplete();
is(gURLBar.textValue, "keyword ab", "urlbar should have expected input");
let result = gURLBar.popup.richlistbox.firstChild;
isnot(result, null, "Should have first item");
let uri = NetUtil.newURI(result.getAttribute("url"));
- is(uri.spec, makeActionURI("keyword", {url: "http://example.com/?q=ab", input: "keyword ab"}).spec, "Expect correct url");
+ is(uri.spec, PlacesUtils.mozActionURI("keyword", {url: "http://example.com/?q=ab", input: "keyword ab"}), "Expect correct url");
EventUtils.synthesizeKey("VK_ESCAPE", {});
yield promisePopupHidden(gURLBar.popup);
gBrowser.removeTab(tab);
});
--- a/browser/base/content/test/urlbar/browser_bug1104165-switchtab-decodeuri.js
+++ b/browser/base/content/test/urlbar/browser_bug1104165-switchtab-decodeuri.js
@@ -1,12 +1,12 @@
add_task(function* test_switchtab_decodeuri() {
info("Opening first tab");
- let tab = gBrowser.addTab("http://example.org/browser/browser/base/content/test/urlbar/dummy_page.html#test%7C1");
- yield promiseTabLoadEvent(tab);
+ const TEST_URL = "http://example.org/browser/browser/base/content/test/urlbar/dummy_page.html#test%7C1";
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL);
info("Opening and selecting second tab");
gBrowser.selectedTab = gBrowser.addTab();
info("Wait for autocomplete")
yield promiseAutocompleteResultPopup("dummy_page");
info("Select autocomplete popup entry");
--- a/browser/base/content/test/urlbar/browser_bug1225194-remotetab.js
+++ b/browser/base/content/test/urlbar/browser_bug1225194-remotetab.js
@@ -2,17 +2,15 @@ add_task(function* test_remotetab_opens(
const url = "http://example.org/browser/browser/base/content/test/urlbar/dummy_page.html";
yield BrowserTestUtils.withNewTab({url: "about:robots", gBrowser}, function* () {
// Set the urlbar to include the moz-action
gURLBar.value = "moz-action:remotetab," + JSON.stringify({ url });
// Focus the urlbar so we can press enter
gURLBar.focus();
// The URL is going to open in the current tab as it is currently about:blank
- let promiseTabLoaded = promiseTabLoadEvent(gBrowser.selectedTab);
-
+ let promiseTabLoaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
EventUtils.synthesizeKey("VK_RETURN", {});
-
yield promiseTabLoaded;
Assert.equal(gBrowser.selectedTab.linkedBrowser.currentURI.spec, url, "correct URL loaded");
});
});
--- a/browser/base/content/test/urlbar/browser_locationBarCommand.js
+++ b/browser/base/content/test/urlbar/browser_locationBarCommand.js
@@ -49,17 +49,17 @@ add_task(function* shift_left_click_test
info("URL should be loaded in a new window");
is(gURLBar.value, "", "Urlbar reverted to original value");
yield promiseCheckChildNoFocusedElement(gBrowser.selectedBrowser);
is(document.activeElement, gBrowser.selectedBrowser, "Content window should be focused");
is(win.gURLBar.textValue, TEST_VALUE, "New URL is loaded in new window");
// Cleanup.
- yield promiseWindowClosed(win);
+ yield BrowserTestUtils.closeWindow(win);
});
add_task(function* right_click_test() {
info("Running test: Right click on go button");
// Add a new tab.
yield* promiseOpenNewTab();
--- a/browser/base/content/test/urlbar/browser_locationBarExternalLoad.js
+++ b/browser/base/content/test/urlbar/browser_locationBarExternalLoad.js
@@ -30,25 +30,25 @@ function promiseNewTabSwitched() {
});
}
function* testURL(url, loadFunc, endFunc) {
let tabSwitchedPromise = promiseNewTabSwitched();
let tab = gBrowser.selectedTab = gBrowser.addTab();
let browser = gBrowser.selectedBrowser;
- let pageshowPromise = promiseWaitForEvent(browser, "pageshow");
+ let pageshowPromise = BrowserTestUtils.waitForContentEvent(browser, "pageshow");
yield tabSwitchedPromise;
yield pageshowPromise;
let pagePrincipal = gBrowser.contentPrincipal;
loadFunc(url);
- yield promiseWaitForEvent(browser, "pageshow");
+ yield BrowserTestUtils.waitForContentEvent(browser, "pageshow");
yield ContentTask.spawn(browser, { isRemote: gMultiProcessBrowser },
function* (arg) {
const fm = Components.classes["@mozilla.org/focus-manager;1"].
getService(Components.interfaces.nsIFocusManager);
Assert.equal(fm.focusedElement, null, "focusedElement not null");
if (arg.isRemote) {
--- a/browser/base/content/test/urlbar/browser_search_favicon.js
+++ b/browser/base/content/test/urlbar/browser_search_favicon.js
@@ -20,18 +20,17 @@ add_task(function*() {
gEngine = Services.search.getEngineByName("SearchEngine");
gEngine.addParam("q", "{searchTerms}", null);
gOriginalEngine = Services.search.currentEngine;
Services.search.currentEngine = gEngine;
let uri = NetUtil.newURI("http://s.example.com/search?q=foo&client=1");
yield PlacesTestUtils.addVisits({ uri: uri, title: "Foo - SearchEngine Search" });
- gBrowser.selectedTab = gBrowser.addTab("about:mozilla", {animate: false});
- yield promiseTabLoaded(gBrowser.selectedTab);
+ yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
// The first autocomplete result has the action searchengine, while
// the second result is the "search favicon" element.
yield promiseAutocompleteResultPopup("foo");
let result = gURLBar.popup.richlistbox.children[1];
isnot(result, null, "Expect a search result");
is(result.getAttribute("type"), "searchengine", "Expect correct `type` attribute");
--- a/browser/base/content/test/urlbar/browser_urlbarSearchSingleWordNotification.js
+++ b/browser/base/content/test/urlbar/browser_urlbarSearchSingleWordNotification.js
@@ -1,11 +1,8 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-
"use strict";
var notificationObserver;
registerCleanupFunction(function() {
Services.prefs.clearUserPref("browser.fixup.domainwhitelist.localhost");
if (notificationObserver) {
notificationObserver.disconnect();
}
@@ -126,26 +123,27 @@ add_task(function* test_navigate_large_h
gBrowser.removeTab(tab);
});
function get_test_function_for_localhost_with_hostname(hostName, isPrivate) {
return function* test_navigate_single_host() {
const pref = "browser.fixup.domainwhitelist.localhost";
let win;
if (isPrivate) {
- win = yield promiseOpenAndLoadWindow({private: true}, true);
+ let promiseWin = BrowserTestUtils.waitForNewWindow();
+ win = OpenBrowserWindow({private: true});
+ yield promiseWin;
let deferredOpenFocus = Promise.defer();
waitForFocus(deferredOpenFocus.resolve, win);
yield deferredOpenFocus.promise;
} else {
win = window;
}
let browser = win.gBrowser;
- let tab = browser.selectedTab = browser.addTab("about:blank");
- yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ let tab = yield BrowserTestUtils.openNewForegroundTab(browser);
Services.prefs.setBoolPref(pref, false);
yield* runURLBarSearchTest({
valueToOpen: hostName,
expectSearch: true,
expectNotification: true,
aWindow: win,
});
@@ -170,17 +168,17 @@ function get_test_function_for_localhost
valueToOpen: hostName,
expectSearch: isPrivate,
expectNotification: isPrivate,
aWindow: win,
});
browser.removeTab(tab);
if (isPrivate) {
info("Waiting for private window to close");
- yield promiseWindowClosed(win);
+ yield BrowserTestUtils.closeWindow(win);
let deferredFocus = Promise.defer();
info("Waiting for focus");
waitForFocus(deferredFocus.resolve, window);
yield deferredFocus.promise;
}
}
}
--- a/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions.js
+++ b/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions.js
@@ -17,51 +17,50 @@ add_task(function* prepare() {
// Make sure the popup is closed for the next test.
gURLBar.blur();
Assert.ok(!gURLBar.popup.popupOpen, "popup should be closed");
});
});
add_task(function* clickSuggestion() {
- gBrowser.selectedTab = gBrowser.addTab();
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser);
gURLBar.focus();
yield promiseAutocompleteResultPopup("foo");
let [idx, suggestion, engineName] = yield promiseFirstSuggestion();
Assert.equal(engineName,
"browser_searchSuggestionEngine%20searchSuggestionEngine.xml",
"Expected suggestion engine");
let item = gURLBar.popup.richlistbox.getItemAtIndex(idx);
- let loadPromise = promiseTabLoaded(gBrowser.selectedTab);
+
+ let uri = Services.search.currentEngine.getSubmission(suggestion).uri;
+ let loadPromise = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser,
+ false, uri.spec);
item.click();
yield loadPromise;
- let uri = Services.search.currentEngine.getSubmission(suggestion).uri;
- Assert.ok(uri.equals(gBrowser.currentURI),
- "The search results page should have loaded");
- gBrowser.removeTab(gBrowser.selectedTab);
+ yield BrowserTestUtils.removeTab(tab);
});
function getFirstSuggestion() {
let controller = gURLBar.popup.input.controller;
let matchCount = controller.matchCount;
for (let i = 0; i < matchCount; i++) {
let url = controller.getValueAt(i);
let mozActionMatch = url.match(/^moz-action:([^,]+),(.*)$/);
if (mozActionMatch) {
let [, type, paramStr] = mozActionMatch;
let params = JSON.parse(paramStr);
if (type == "searchengine" && "searchSuggestion" in params) {
return [i, params.searchSuggestion, params.engineName];
}
}
}
- return [-1, null];
+ return [-1, null, null];
}
-function promiseFirstSuggestion() {
- return new Promise(resolve => {
- let tuple;
- waitForCondition(() => {
- tuple = getFirstSuggestion();
- return tuple[0] >= 0;
- }, () => resolve(tuple));
+function* promiseFirstSuggestion() {
+ let tuple = [-1, null, null];
+ yield BrowserTestUtils.waitForCondition(() => {
+ tuple = getFirstSuggestion();
+ return tuple[0] >= 0;
});
+ return tuple;
}
--- a/browser/base/content/test/urlbar/browser_urlbarSearchSuggestionsNotification.js
+++ b/browser/base/content/test/urlbar/browser_urlbarSearchSuggestionsNotification.js
@@ -109,17 +109,18 @@ add_task(function* enable() {
gURLBar.blur();
gURLBar.focus();
yield promiseAutocompleteResultPopup("foo");
assertVisible(true);
Assert.ok(!suggestionsPresent());
let enableButton = document.getAnonymousElementByAttribute(
gURLBar.popup, "anonid", "search-suggestions-notification-enable"
);
- let searchPromise = promiseSuggestionsPresent();
+ let searchPromise = BrowserTestUtils.waitForCondition(suggestionsPresent,
+ "waiting for suggestions");
enableButton.click();
yield searchPromise;
// Clicking Yes should trigger a new search so that suggestions appear
// immediately.
Assert.ok(suggestionsPresent());
gURLBar.blur();
gURLBar.focus();
// Suggestions should still be present in a new search of course.
@@ -230,22 +231,16 @@ function suggestionsPresent() {
if (type == "searchengine" && "searchSuggestion" in params) {
return true;
}
}
}
return false;
}
-function promiseSuggestionsPresent() {
- return new Promise(resolve => {
- waitForCondition(suggestionsPresent, resolve);
- });
-}
-
function assertVisible(visible, win=window) {
let style =
win.getComputedStyle(win.gURLBar.popup.searchSuggestionsNotification);
Assert.equal(style.visibility, visible ? "visible" : "collapse");
}
function promiseTransition(win=window) {
return new Promise(resolve => {
--- a/browser/base/content/test/urlbar/head.js
+++ b/browser/base/content/test/urlbar/head.js
@@ -3,123 +3,19 @@ Components.utils.import("resource://gre/
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
"resource://gre/modules/Promise.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
"resource://testing-common/PlacesTestUtils.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "TabCrashHandler",
- "resource:///modules/ContentCrashHandlers.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Preferences",
"resource://gre/modules/Preferences.jsm");
-function waitForCondition(condition, nextTest, errorMsg, retryTimes) {
- retryTimes = typeof retryTimes !== 'undefined' ? retryTimes : 30;
- var tries = 0;
- var interval = setInterval(function() {
- if (tries >= retryTimes) {
- ok(false, errorMsg);
- moveOn();
- }
- var conditionPassed;
- try {
- conditionPassed = condition();
- } catch (e) {
- ok(false, e + "\n" + e.stack);
- conditionPassed = false;
- }
- if (conditionPassed) {
- moveOn();
- }
- tries++;
- }, 100);
- var moveOn = function() { clearInterval(interval); nextTest(); };
-}
-
-function promiseWaitForCondition(aConditionFn) {
- let deferred = Promise.defer();
- waitForCondition(aConditionFn, deferred.resolve, "Condition didn't pass.");
- return deferred.promise;
-}
-
-function promiseWaitForEvent(object, eventName, capturing = false, chrome = false) {
- return new Promise((resolve) => {
- function listener(event) {
- info("Saw " + eventName);
- object.removeEventListener(eventName, listener, capturing, chrome);
- resolve(event);
- }
-
- info("Waiting for " + eventName);
- object.addEventListener(eventName, listener, capturing, chrome);
- });
-}
-
-function promiseWindowWillBeClosed(win) {
- return new Promise((resolve, reject) => {
- Services.obs.addObserver(function observe(subject, topic) {
- if (subject == win) {
- Services.obs.removeObserver(observe, topic);
- resolve();
- }
- }, "domwindowclosed", false);
- });
-}
-
-function promiseWindowClosed(win) {
- let promise = promiseWindowWillBeClosed(win);
- win.close();
- return promise;
-}
-
-function promiseOpenAndLoadWindow(aOptions, aWaitForDelayedStartup=false) {
- let deferred = Promise.defer();
- let win = OpenBrowserWindow(aOptions);
- if (aWaitForDelayedStartup) {
- Services.obs.addObserver(function onDS(aSubject, aTopic, aData) {
- if (aSubject != win) {
- return;
- }
- Services.obs.removeObserver(onDS, "browser-delayed-startup-finished");
- deferred.resolve(win);
- }, "browser-delayed-startup-finished", false);
-
- } else {
- win.addEventListener("load", function onLoad() {
- win.removeEventListener("load", onLoad);
- deferred.resolve(win);
- });
- }
- return deferred.promise;
-}
-
-function whenNewTabLoaded(aWindow, aCallback) {
- aWindow.BrowserOpenTab();
-
- let browser = aWindow.gBrowser.selectedBrowser;
- if (browser.contentDocument.readyState === "complete") {
- aCallback();
- return;
- }
-
- whenTabLoaded(aWindow.gBrowser.selectedTab, aCallback);
-}
-
-function whenTabLoaded(aTab, aCallback) {
- promiseTabLoadEvent(aTab).then(aCallback);
-}
-
-function promiseTabLoaded(aTab) {
- let deferred = Promise.defer();
- whenTabLoaded(aTab, deferred.resolve);
- return deferred.promise;
-}
-
/**
* Waits for the next top-level document load in the current browser. The URI
* of the document is compared against aExpectedURL. The load is then stopped
* before it actually starts.
*
* @param aExpectedURL
* The URL of the document that is expected to load.
* @param aStopFromProgressListener
@@ -188,61 +84,16 @@ function waitForDocLoadAndStopIt(aExpect
let mm = aBrowser.messageManager;
mm.loadFrameScript("data:,(" + content_script.toString() + ")(" + aStopFromProgressListener + ");", true);
mm.addMessageListener("Test:WaitForDocLoadAndStopIt", complete);
info("waitForDocLoadAndStopIt: Waiting for URL: " + aExpectedURL);
});
}
-/**
- * Waits for a load (or custom) event to finish in a given tab. If provided
- * load an uri into the tab.
- *
- * @param tab
- * The tab to load into.
- * @param [optional] url
- * The url to load, or the current url.
- * @return {Promise} resolved when the event is handled.
- * @resolves to the received event
- * @rejects if a valid load event is not received within a meaningful interval
- */
-function promiseTabLoadEvent(tab, url)
-{
- info("Wait tab event: load");
-
- function handle(loadedUrl) {
- if (loadedUrl === "about:blank" || (url && loadedUrl !== url)) {
- info(`Skipping spurious load event for ${loadedUrl}`);
- return false;
- }
-
- info("Tab event received: load");
- return true;
- }
-
- // Create two promises: one resolved from the content process when the page
- // loads and one that is rejected if we take too long to load the url.
- let loaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, handle);
-
- if (url)
- BrowserTestUtils.loadURI(tab.linkedBrowser, url);
-
- return loaded;
-}
-
-function makeActionURI(action, params) {
- let encodedParams = {};
- for (let key in params) {
- encodedParams[key] = encodeURIComponent(params[key]);
- }
- let url = "moz-action:" + action + "," + JSON.stringify(encodedParams);
- return NetUtil.newURI(url);
-}
-
function is_hidden(element) {
var style = element.ownerGlobal.getComputedStyle(element);
if (style.display == "none")
return true;
if (style.visibility != "visible")
return true;
if (style.display == "-moz-popup")
return ["hiding", "closed"].indexOf(element.state) != -1;
@@ -307,17 +158,17 @@ function promisePopupHidden(popup) {
function promiseSearchComplete(win = window) {
return promisePopupShown(win.gURLBar.popup).then(() => {
function searchIsComplete() {
return win.gURLBar.controller.searchStatus >=
Ci.nsIAutoCompleteController.STATUS_COMPLETE_NO_MATCH;
}
// Wait until there are at least two matches.
- return new Promise(resolve => waitForCondition(searchIsComplete, resolve));
+ return BrowserTestUtils.waitForCondition(searchIsComplete, "waiting urlbar search to complete");
});
}
function promiseAutocompleteResultPopup(inputText,
win = window,
fireInputEvent = false) {
waitForFocus(() => {
win.gURLBar.focus();