зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1406860 - Make urlbar tests a bit more reliable. r=standard8
MozReview-Commit-ID: 71ZzDbCq8n0 --HG-- extra : rebase_source : f919a0f84ff46fcfa56ddbfb2ba8b060b34cb12a
This commit is contained in:
Родитель
04945c8950
Коммит
ac4197582b
|
@ -10,7 +10,7 @@ add_task(async function() {
|
|||
});
|
||||
|
||||
await promiseAutocompleteResultPopup("keyword search");
|
||||
let result = gURLBar.popup.richlistbox.children[0];
|
||||
let result = await waitForAutocompleteResultAt(0);
|
||||
|
||||
info("Before override");
|
||||
let titleHbox = result._titleText.parentNode.parentNode;
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
add_task(async function() {
|
||||
Services.search.addEngineWithDetails("MozSearch", "", "", "", "GET",
|
||||
"http://example.com/?q={searchTerms}");
|
||||
|
@ -7,20 +10,17 @@ add_task(async function() {
|
|||
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
|
||||
|
||||
registerCleanupFunction(() => {
|
||||
registerCleanupFunction(async function() {
|
||||
Services.search.currentEngine = originalEngine;
|
||||
Services.search.removeEngine(engine);
|
||||
|
||||
try {
|
||||
gBrowser.removeTab(tab);
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
} catch (ex) { /* tab may have already been closed in case of failure */ }
|
||||
|
||||
return PlacesTestUtils.clearHistory();
|
||||
await PlacesUtils.history.clear();
|
||||
});
|
||||
|
||||
await promiseAutocompleteResultPopup("open a search");
|
||||
let result = gURLBar.popup.richlistbox.firstChild;
|
||||
|
||||
let result = await waitForAutocompleteResultAt(0);
|
||||
isnot(result, null, "Should have a result");
|
||||
is(result.getAttribute("url"),
|
||||
`moz-action:searchengine,{"engineName":"MozSearch","input":"open%20a%20search","searchQuery":"open%20a%20search"}`,
|
||||
|
@ -32,4 +32,7 @@ add_task(async function() {
|
|||
await tabPromise;
|
||||
|
||||
is(gBrowser.selectedBrowser.currentURI.spec, "http://example.com/?q=open+a+search", "Correct URL should be loaded");
|
||||
|
||||
gURLBar.popup.hidePopup();
|
||||
await promisePopupHidden(gURLBar.popup);
|
||||
});
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
add_task(async 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",
|
||||
|
@ -8,20 +11,17 @@ add_task(async function() {
|
|||
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
|
||||
|
||||
registerCleanupFunction(() => {
|
||||
registerCleanupFunction(async function() {
|
||||
Services.search.currentEngine = originalEngine;
|
||||
Services.search.removeEngine(engine);
|
||||
|
||||
try {
|
||||
gBrowser.removeTab(tab);
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
} catch (ex) { /* tab may have already been closed in case of failure */ }
|
||||
|
||||
return PlacesTestUtils.clearHistory();
|
||||
await PlacesUtils.history.clear();
|
||||
});
|
||||
|
||||
await promiseAutocompleteResultPopup("moz open a search");
|
||||
|
||||
let result = gURLBar.popup.richlistbox.children[0];
|
||||
let result = await waitForAutocompleteResultAt(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");
|
||||
|
@ -31,4 +31,7 @@ add_task(async function() {
|
|||
await tabPromise;
|
||||
|
||||
is(gBrowser.selectedBrowser.currentURI.spec, "http://example.com/?q=open+a+search");
|
||||
|
||||
gURLBar.popup.hidePopup();
|
||||
await promisePopupHidden(gURLBar.popup);
|
||||
});
|
||||
|
|
|
@ -9,9 +9,7 @@ add_task(async function switchToTab() {
|
|||
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:about");
|
||||
|
||||
await promiseAutocompleteResultPopup("% about");
|
||||
|
||||
ok(gURLBar.popup.richlistbox.children.length > 1, "Should get at least 2 results");
|
||||
let result = gURLBar.popup.richlistbox.children[1];
|
||||
let result = await waitForAutocompleteResultAt(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");
|
||||
|
||||
|
@ -34,6 +32,7 @@ add_task(async function searchSuggestions() {
|
|||
});
|
||||
|
||||
await promiseAutocompleteResultPopup("foo");
|
||||
await waitForAutocompleteResultAt(2);
|
||||
// Don't assume that the search doesn't match history or bookmarks left around
|
||||
// by earlier tests.
|
||||
Assert.ok(gURLBar.popup.richlistbox.children.length >= 3,
|
||||
|
@ -54,5 +53,6 @@ add_task(async function searchSuggestions() {
|
|||
}
|
||||
}
|
||||
Assert.ok(expectedSearches.length == 0);
|
||||
gURLBar.closePopup();
|
||||
gURLBar.popup.hidePopup();
|
||||
await promisePopupHidden(gURLBar.popup);
|
||||
});
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
const ONEOFF_URLBAR_PREF = "browser.urlbar.oneOffSearches";
|
||||
|
||||
function repeat(limit, func) {
|
||||
|
@ -27,11 +30,12 @@ function is_selected_one_off(index) {
|
|||
|
||||
add_task(async function() {
|
||||
let maxResults = Services.prefs.getIntPref("browser.urlbar.maxRichResults");
|
||||
|
||||
Services.prefs.setBoolPref(ONEOFF_URLBAR_PREF, true);
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
|
||||
registerCleanupFunction(async function() {
|
||||
await PlacesTestUtils.clearHistory();
|
||||
Services.prefs.clearUserPref(ONEOFF_URLBAR_PREF);
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
let visits = [];
|
||||
|
@ -42,8 +46,8 @@ add_task(async function() {
|
|||
});
|
||||
await PlacesTestUtils.addVisits(visits);
|
||||
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
|
||||
await promiseAutocompleteResultPopup("example.com/autocomplete");
|
||||
await waitForAutocompleteResultAt(maxResults - 1);
|
||||
|
||||
let popup = gURLBar.popup;
|
||||
let results = popup.richlistbox.children;
|
||||
|
@ -88,5 +92,4 @@ add_task(async function() {
|
|||
|
||||
EventUtils.synthesizeKey("VK_ESCAPE", {});
|
||||
await promisePopupHidden(gURLBar.popup);
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
add_task(async function() {
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
|
||||
await promiseAutocompleteResultPopup("www.mozilla.org");
|
||||
|
@ -13,5 +16,5 @@ add_task(async function() {
|
|||
is(gURLBar.selectionStart, 5, "Should have moved the cursor");
|
||||
is(gURLBar.selectionEnd, 5, "And not selected anything");
|
||||
|
||||
gBrowser.removeTab(tab);
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
add_task(async function() {
|
||||
await PlacesTestUtils.clearHistory();
|
||||
await PlacesUtils.history.clear();
|
||||
|
||||
await PlacesTestUtils.addVisits([
|
||||
{ uri: makeURI("http://example.com/foo") },
|
||||
{ uri: makeURI("http://example.com/foo/bar") },
|
||||
]);
|
||||
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
|
||||
registerCleanupFunction(async function() {
|
||||
await PlacesTestUtils.clearHistory();
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
await PlacesUtils.history.clear();
|
||||
});
|
||||
|
||||
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "about:blank");
|
||||
gURLBar.focus();
|
||||
|
||||
await promiseAutocompleteResultPopup("http://example.com");
|
||||
await waitForAutocompleteResultAt(1);
|
||||
|
||||
let popup = gURLBar.popup;
|
||||
let list = popup.richlistbox;
|
||||
|
@ -44,5 +44,4 @@ add_task(async function() {
|
|||
docLoad,
|
||||
]);
|
||||
|
||||
gBrowser.removeTab(gBrowser.selectedTab);
|
||||
});
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
|
||||
add_task(async function setup() {
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
|
||||
let bm = await PlacesUtils.bookmarks.insert({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
url: "http://example.com/?q=%s",
|
||||
title: "test" });
|
||||
let bm = await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
url: "http://example.com/?q=%s",
|
||||
title: "test"
|
||||
});
|
||||
registerCleanupFunction(async function() {
|
||||
await PlacesUtils.bookmarks.remove(bm);
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
add_task(async function() {
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
|
||||
|
||||
let uri = NetUtil.newURI("http://bug1060642.example.com/beards/are/pretty/great");
|
||||
await PlacesTestUtils.addVisits([{uri, title: ""}]);
|
||||
await PlacesUtils.history.clear();
|
||||
const uri = "http://bug1060642.example.com/beards/are/pretty/great";
|
||||
await PlacesTestUtils.addVisits([{ uri, title: "" }]);
|
||||
registerCleanupFunction(async function() {
|
||||
await PlacesUtils.history.clear();
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
await promiseAutocompleteResultPopup("bug1060642");
|
||||
ok(gURLBar.popup.richlistbox.children.length > 1, "Should get at least 2 results");
|
||||
let result = gURLBar.popup.richlistbox.children[1];
|
||||
let result = await waitForAutocompleteResultAt(1);
|
||||
is(result._titleText.textContent, "bug1060642.example.com", "Result title should be as expected");
|
||||
|
||||
gURLBar.popup.hidePopup();
|
||||
await promisePopupHidden(gURLBar.popup);
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
add_task(async function() {
|
||||
registerCleanupFunction(() => {
|
||||
PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
|
||||
registerCleanupFunction(async function() {
|
||||
await PlacesUtils.bookmarks.eraseEverything();
|
||||
});
|
||||
|
||||
async function addTagItem(tagName) {
|
||||
let uri = NetUtil.newURI(`http://example.com/this/is/tagged/${tagName}`);
|
||||
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
|
||||
uri,
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
`test ${tagName}`);
|
||||
PlacesUtils.tagging.tagURI(uri, [tagName]);
|
||||
await PlacesTestUtils.addVisits([{uri, title: `Test page with tag ${tagName}`}]);
|
||||
let url = `http://example.com/this/is/tagged/${tagName}`;
|
||||
await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
url,
|
||||
title: `test ${tagName}`
|
||||
});
|
||||
PlacesUtils.tagging.tagURI(Services.io.newURI(url), [tagName]);
|
||||
await PlacesTestUtils.addVisits({uri: url, title: `Test page with tag ${tagName}`});
|
||||
}
|
||||
|
||||
// We use different tags for each part of the test, as otherwise the
|
||||
|
@ -83,7 +84,7 @@ add_task(async function() {
|
|||
}
|
||||
|
||||
await promiseAutocompleteResultPopup(testcase.input);
|
||||
let result = gURLBar.popup.richlistbox.children[1];
|
||||
let result = await waitForAutocompleteResultAt(1);
|
||||
ok(result && !result.collasped, "Should have result");
|
||||
|
||||
is(result.getAttribute("type"), testcase.expected.type, "Result should have expected type");
|
||||
|
|
|
@ -30,8 +30,7 @@ add_task(async function() {
|
|||
// The first autocomplete result has the action searchengine, while
|
||||
// the second result is the "search favicon" element.
|
||||
await promiseAutocompleteResultPopup("foo");
|
||||
let result = gURLBar.popup.richlistbox.children[1];
|
||||
|
||||
let result = await waitForAutocompleteResultAt(1);
|
||||
isnot(result, null, "Expect a search result");
|
||||
is(result.getAttribute("type"), "searchengine", "Expect correct `type` attribute");
|
||||
|
||||
|
|
|
@ -72,11 +72,12 @@ add_task(async function click_on_focused() {
|
|||
gURLBar.blur();
|
||||
// Won't show the hint since it's not user initiated.
|
||||
gURLBar.focus();
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
Assert.ok(!gURLBar.popup.popupOpen, "popup should be closed");
|
||||
Assert.ok(gURLBar.focused, "The input field should be focused");
|
||||
|
||||
let popupPromise = promisePopupShown(gURLBar.popup);
|
||||
EventUtils.synthesizeMouseAtCenter(gURLBar.inputField, { button: 0, type: "mousedown" });
|
||||
EventUtils.synthesizeMouseAtCenter(gURLBar.inputField, {});
|
||||
await popupPromise;
|
||||
|
||||
Assert.ok(gURLBar.popup.popupOpen, "popup should be open");
|
||||
|
|
|
@ -12,11 +12,11 @@ add_task(async function test_remove_history() {
|
|||
|
||||
let promiseVisitRemoved = PlacesTestUtils.waitForNotification(
|
||||
"onDeleteURI", uri => uri.spec == TEST_URL, "history");
|
||||
|
||||
await promiseAutocompleteResultPopup("remove.me/from_urlbar");
|
||||
await BrowserTestUtils.waitForCondition(
|
||||
() => gURLBar.popup.richlistbox.children.length > 1 &&
|
||||
gURLBar.popup.richlistbox.children[1].getAttribute("ac-value") == TEST_URL,
|
||||
"Waiting for the result to appear");
|
||||
let result = await waitForAutocompleteResultAt(1);
|
||||
Assert.equal(result.getAttribute("ac-value"), TEST_URL, "Found the expected result");
|
||||
|
||||
EventUtils.synthesizeKey("VK_DOWN", {});
|
||||
Assert.equal(gURLBar.popup.richlistbox.selectedIndex, 1);
|
||||
let options = AppConstants.platform == "macosx" ? { shiftKey: true } : {};
|
||||
|
|
|
@ -150,19 +150,17 @@ add_task(async function popup_mousedown_no_client_cert_dialog_until_navigate_tes
|
|||
};
|
||||
info(`Searching for '${test.search}'`);
|
||||
await promiseAutocompleteResultPopup(test.search, window, true);
|
||||
await waitForAutocompleteResultAt(1);
|
||||
let controller = gURLBar.popup.input.controller;
|
||||
// The first item should be 'Search with ...' thus we want the second.
|
||||
let value = controller.getFinalCompleteValueAt(1);
|
||||
info(`The value of the second item is ${value}`);
|
||||
is(value, test.completeValue, "The second item has the url we visited.");
|
||||
|
||||
await BrowserTestUtils.waitForCondition(() => {
|
||||
return !!gURLBar.popup.richlistbox.childNodes[1] &&
|
||||
is_visible(gURLBar.popup.richlistbox.childNodes[1]);
|
||||
}, "the node is there.");
|
||||
let listitem = await waitForAutocompleteResultAt(1);
|
||||
Assert.ok(is_visible(listitem), "The node is there.");
|
||||
|
||||
expectingChooseCertificate = false;
|
||||
let listitem = gURLBar.popup.richlistbox.childNodes[1];
|
||||
EventUtils.synthesizeMouseAtCenter(listitem, {type: "mousedown"}, window);
|
||||
is(gURLBar.popup.richlistbox.selectedIndex, 1, "The second item is selected");
|
||||
|
||||
|
|
|
@ -313,3 +313,12 @@ function promiseSpeculativeConnection(httpserver) {
|
|||
return false;
|
||||
}, "Waiting for connection setup");
|
||||
}
|
||||
|
||||
async function waitForAutocompleteResultAt(index) {
|
||||
let searchString = gURLBar.controller.searchString;
|
||||
await BrowserTestUtils.waitForCondition(
|
||||
() => gURLBar.popup.richlistbox.children.length > index &&
|
||||
gURLBar.popup.richlistbox.children[index].getAttribute("ac-text") == searchString,
|
||||
`Waiting for the autocomplete result for "${searchString}" at [${index}] to appear`);
|
||||
return gURLBar.popup.richlistbox.children[index];
|
||||
}
|
||||
|
|
|
@ -90,7 +90,6 @@ skip-if = (os == 'win' && !debug) # bug 1352668
|
|||
[browser_ext_lastError.js]
|
||||
[browser_ext_menus.js]
|
||||
[browser_ext_omnibox.js]
|
||||
skip-if = debug || asan # Bug 1354681
|
||||
[browser_ext_openPanel.js]
|
||||
[browser_ext_optionsPage_browser_style.js]
|
||||
[browser_ext_optionsPage_modals.js]
|
||||
|
|
|
@ -94,8 +94,10 @@ add_task(async function() {
|
|||
// Wait for the autocomplete search. Note that we cannot wait for the search
|
||||
// to be complete, since the add-on doesn't communicate when it's done, so
|
||||
// just check matches count.
|
||||
await BrowserTestUtils.waitForCondition(() => gURLBar.controller.matchCount >= 2,
|
||||
"waiting urlbar search to complete");
|
||||
await BrowserTestUtils.waitForCondition(
|
||||
() => gURLBar.controller.matchCount >= 2 &&
|
||||
gURLBar.popup.richlistbox.children[1].getAttribute("ac-text") == gURLBar.controller.searchString,
|
||||
"waiting urlbar search to complete");
|
||||
return "t";
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|||
Cu.import("resource://gre/modules/AppConstants.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/Timer.jsm");
|
||||
Cu.import("resource://testing-common/TestUtils.jsm");
|
||||
Cu.import("resource://testing-common/ContentTask.jsm");
|
||||
|
||||
|
@ -1311,53 +1310,8 @@ this.BrowserTestUtils = {
|
|||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Will poll a condition function until it returns true.
|
||||
*
|
||||
* @param condition
|
||||
* A condition function that must return true or false. If the
|
||||
* condition ever throws, this is also treated as a false. The
|
||||
* function can be a generator.
|
||||
* @param interval
|
||||
* The time interval to poll the condition function. Defaults
|
||||
* to 100ms.
|
||||
* @param attempts
|
||||
* The number of times to poll before giving up and rejecting
|
||||
* if the condition has not yet returned true. Defaults to 50
|
||||
* (~5 seconds for 100ms intervals)
|
||||
* @return Promise
|
||||
* Resolves when condition is true.
|
||||
* Rejects if timeout is exceeded or condition ever throws.
|
||||
*/
|
||||
waitForCondition(condition, msg, interval=100, maxTries=50) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let tries = 0;
|
||||
let intervalID = setInterval(async function() {
|
||||
if (tries >= maxTries) {
|
||||
clearInterval(intervalID);
|
||||
msg += ` - timed out after ${maxTries} tries.`;
|
||||
reject(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
let conditionPassed = false;
|
||||
try {
|
||||
conditionPassed = await condition();
|
||||
} catch(e) {
|
||||
msg += ` - threw exception: ${e}`;
|
||||
clearInterval(intervalID);
|
||||
reject(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (conditionPassed) {
|
||||
clearInterval(intervalID);
|
||||
resolve();
|
||||
}
|
||||
tries++;
|
||||
}, interval);
|
||||
});
|
||||
},
|
||||
// TODO: Fix consumers and remove me.
|
||||
waitForCondition: TestUtils.waitForCondition,
|
||||
|
||||
/**
|
||||
* Waits for a <xul:notification> with a particular value to appear
|
||||
|
|
|
@ -21,6 +21,7 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/Timer.jsm");
|
||||
|
||||
this.TestUtils = {
|
||||
executeSoon(callbackFn) {
|
||||
|
@ -83,5 +84,53 @@ this.TestUtils = {
|
|||
ctx.scale(ratio, ratio);
|
||||
ctx.drawWindow(win, left, top, width, height, "#fff");
|
||||
return canvas.toDataURL();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Will poll a condition function until it returns true.
|
||||
*
|
||||
* @param condition
|
||||
* A condition function that must return true or false. If the
|
||||
* condition ever throws, this is also treated as a false. The
|
||||
* function can be a generator.
|
||||
* @param interval
|
||||
* The time interval to poll the condition function. Defaults
|
||||
* to 100ms.
|
||||
* @param attempts
|
||||
* The number of times to poll before giving up and rejecting
|
||||
* if the condition has not yet returned true. Defaults to 50
|
||||
* (~5 seconds for 100ms intervals)
|
||||
* @return Promise
|
||||
* Resolves when condition is true.
|
||||
* Rejects if timeout is exceeded or condition ever throws.
|
||||
*/
|
||||
waitForCondition(condition, msg, interval = 100, maxTries = 50) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let tries = 0;
|
||||
let intervalID = setInterval(async function() {
|
||||
if (tries >= maxTries) {
|
||||
clearInterval(intervalID);
|
||||
msg += ` - timed out after ${maxTries} tries.`;
|
||||
reject(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
let conditionPassed = false;
|
||||
try {
|
||||
conditionPassed = await condition();
|
||||
} catch (e) {
|
||||
msg += ` - threw exception: ${e}`;
|
||||
clearInterval(intervalID);
|
||||
reject(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (conditionPassed) {
|
||||
clearInterval(intervalID);
|
||||
resolve();
|
||||
}
|
||||
tries++;
|
||||
}, interval);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
@ -12,8 +12,8 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
|
||||
"resource://gre/modules/PlacesUtils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
|
||||
"resource://gre/modules/NetUtil.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "TestUtils",
|
||||
"resource://testing-common/TestUtils.jsm");
|
||||
|
||||
this.PlacesTestUtils = Object.freeze({
|
||||
/**
|
||||
|
@ -55,9 +55,9 @@ this.PlacesTestUtils = Object.freeze({
|
|||
let info = {url: place.uri};
|
||||
info.title = (typeof place.title === "string") ? place.title : "test visit for " + info.url.spec ;
|
||||
if (typeof place.referrer == "string") {
|
||||
place.referrer = NetUtil.newURI(place.referrer);
|
||||
place.referrer = Services.io.newURI(place.referrer);
|
||||
} else if (place.referrer && place.referrer instanceof URL) {
|
||||
place.referrer = NetUtil.newURI(place.referrer.href);
|
||||
place.referrer = Services.io.newURI(place.referrer.href);
|
||||
}
|
||||
let visitDate = place.visitDate;
|
||||
if (visitDate) {
|
||||
|
@ -82,7 +82,11 @@ this.PlacesTestUtils = Object.freeze({
|
|||
}];
|
||||
infos.push(info);
|
||||
}
|
||||
return PlacesUtils.history.insertMany(infos);
|
||||
await PlacesUtils.history.insertMany(infos);
|
||||
await TestUtils.waitForCondition(
|
||||
() => PlacesUtils.history.fetch(infos[infos.length - 1].url),
|
||||
"Ensure history has been updated and is visible to read-only connections"
|
||||
);
|
||||
},
|
||||
|
||||
/*
|
||||
|
@ -104,8 +108,8 @@ this.PlacesTestUtils = Object.freeze({
|
|||
throw new Error("URL does not exist");
|
||||
}
|
||||
faviconPromises.push(new Promise((resolve, reject) => {
|
||||
let uri = NetUtil.newURI(key);
|
||||
let faviconURI = NetUtil.newURI(val);
|
||||
let uri = Services.io.newURI(key);
|
||||
let faviconURI = Services.io.newURI(val);
|
||||
try {
|
||||
PlacesUtils.favicons.setAndFetchFaviconForPage(
|
||||
uri,
|
||||
|
|
Загрузка…
Ссылка в новой задаче