Backed out changeset 1ac7fce0b369 (bug 1406860) for failing xpcshell tests, e.g. toolkit/components/places/tests/unit/test_000_frecency.js. r=backout

--HG--
extra : amend_source : d56cb30d1aa7bb64597e273eef64e9d35056914e
This commit is contained in:
Sebastian Hengst 2017-10-11 18:25:57 +02:00
Родитель 8c8887d39d
Коммит d4cf5c3f6e
20 изменённых файлов: 120 добавлений и 151 удалений

Просмотреть файл

@ -10,7 +10,7 @@ add_task(async function() {
});
await promiseAutocompleteResultPopup("keyword search");
let result = await waitForAutocompleteResultAt(0);
let result = gURLBar.popup.richlistbox.children[0];
info("Before override");
let titleHbox = result._titleText.parentNode.parentNode;

Просмотреть файл

@ -1,6 +1,3 @@
/* 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}");
@ -10,17 +7,20 @@ add_task(async function() {
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
registerCleanupFunction(async function() {
registerCleanupFunction(() => {
Services.search.currentEngine = originalEngine;
Services.search.removeEngine(engine);
try {
await BrowserTestUtils.removeTab(tab);
gBrowser.removeTab(tab);
} catch (ex) { /* tab may have already been closed in case of failure */ }
await PlacesUtils.history.clear();
return PlacesTestUtils.clearHistory();
});
await promiseAutocompleteResultPopup("open a search");
let result = await waitForAutocompleteResultAt(0);
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"}`,
@ -32,7 +32,4 @@ 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,6 +1,3 @@
/* 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",
@ -11,17 +8,20 @@ add_task(async function() {
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
registerCleanupFunction(async function() {
registerCleanupFunction(() => {
Services.search.currentEngine = originalEngine;
Services.search.removeEngine(engine);
try {
await BrowserTestUtils.removeTab(tab);
gBrowser.removeTab(tab);
} catch (ex) { /* tab may have already been closed in case of failure */ }
await PlacesUtils.history.clear();
return PlacesTestUtils.clearHistory();
});
await promiseAutocompleteResultPopup("moz open a search");
let result = await waitForAutocompleteResultAt(0);
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");
@ -31,7 +31,4 @@ 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,7 +9,9 @@ add_task(async function switchToTab() {
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:about");
await promiseAutocompleteResultPopup("% about");
let result = await waitForAutocompleteResultAt(1);
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");
@ -32,7 +34,6 @@ 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,
@ -53,6 +54,5 @@ add_task(async function searchSuggestions() {
}
}
Assert.ok(expectedSearches.length == 0);
gURLBar.popup.hidePopup();
await promisePopupHidden(gURLBar.popup);
gURLBar.closePopup();
});

Просмотреть файл

@ -1,6 +1,3 @@
/* 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) {
@ -30,12 +27,11 @@ 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 = [];
@ -46,8 +42,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;
@ -92,4 +88,5 @@ add_task(async function() {
EventUtils.synthesizeKey("VK_ESCAPE", {});
await promisePopupHidden(gURLBar.popup);
gBrowser.removeTab(tab);
});

Просмотреть файл

@ -1,6 +1,3 @@
/* 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");
@ -16,5 +13,5 @@ add_task(async function() {
is(gURLBar.selectionStart, 5, "Should have moved the cursor");
is(gURLBar.selectionEnd, 5, "And not selected anything");
await BrowserTestUtils.removeTab(tab);
gBrowser.removeTab(tab);
});

Просмотреть файл

@ -1,19 +1,19 @@
add_task(async function() {
await PlacesUtils.history.clear();
await PlacesTestUtils.clearHistory();
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 BrowserTestUtils.removeTab(tab);
await PlacesUtils.history.clear();
await PlacesTestUtils.clearHistory();
});
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,4 +44,5 @@ add_task(async function() {
docLoad,
]);
gBrowser.removeTab(gBrowser.selectedTab);
});

Просмотреть файл

@ -2,11 +2,9 @@
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,17 +1,15 @@
add_task(async function() {
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
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);
});
let uri = NetUtil.newURI("http://bug1060642.example.com/beards/are/pretty/great");
await PlacesTestUtils.addVisits([{uri, title: ""}]);
await promiseAutocompleteResultPopup("bug1060642");
let result = await waitForAutocompleteResultAt(1);
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");
gURLBar.popup.hidePopup();
await promisePopupHidden(gURLBar.popup);
gBrowser.removeTab(tab);
});

Просмотреть файл

@ -1,17 +1,16 @@
add_task(async function() {
registerCleanupFunction(async function() {
await PlacesUtils.bookmarks.eraseEverything();
registerCleanupFunction(() => {
PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
});
async function addTagItem(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}`});
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}`}]);
}
// We use different tags for each part of the test, as otherwise the
@ -84,7 +83,7 @@ add_task(async function() {
}
await promiseAutocompleteResultPopup(testcase.input);
let result = await waitForAutocompleteResultAt(1);
let result = gURLBar.popup.richlistbox.children[1];
ok(result && !result.collasped, "Should have result");
is(result.getAttribute("type"), testcase.expected.type, "Result should have expected type");

Просмотреть файл

@ -30,7 +30,8 @@ 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 = await waitForAutocompleteResultAt(1);
let result = gURLBar.popup.richlistbox.children[1];
isnot(result, null, "Expect a search result");
is(result.getAttribute("type"), "searchengine", "Expect correct `type` attribute");

Просмотреть файл

@ -72,12 +72,11 @@ 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, 1000));
await new Promise(resolve => setTimeout(resolve, 500));
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, {});
EventUtils.synthesizeMouseAtCenter(gURLBar.inputField, { button: 0, type: "mousedown" });
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");
let result = await waitForAutocompleteResultAt(1);
Assert.equal(result.getAttribute("ac-value"), TEST_URL, "Found the expected result");
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");
EventUtils.synthesizeKey("VK_DOWN", {});
Assert.equal(gURLBar.popup.richlistbox.selectedIndex, 1);
let options = AppConstants.platform == "macosx" ? { shiftKey: true } : {};

Просмотреть файл

@ -150,17 +150,19 @@ 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.");
let listitem = await waitForAutocompleteResultAt(1);
Assert.ok(is_visible(listitem), "The node is there.");
await BrowserTestUtils.waitForCondition(() => {
return !!gURLBar.popup.richlistbox.childNodes[1] &&
is_visible(gURLBar.popup.richlistbox.childNodes[1]);
}, "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,12 +313,3 @@ 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,6 +90,7 @@ 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,10 +94,8 @@ 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 &&
gURLBar.popup.richlistbox.children[1].getAttribute("ac-text") == gURLBar.controller.searchString,
"waiting urlbar search to complete");
await BrowserTestUtils.waitForCondition(() => gURLBar.controller.matchCount >= 2,
"waiting urlbar search to complete");
return "t";
}

Просмотреть файл

@ -20,6 +20,7 @@ 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");
@ -1310,8 +1311,53 @@ this.BrowserTestUtils = {
});
},
// TODO: Fix consumers and remove me.
waitForCondition: TestUtils.waitForCondition,
/**
* 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);
});
},
/**
* Waits for a <xul:notification> with a particular value to appear

Просмотреть файл

@ -21,7 +21,6 @@ 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) {
@ -84,53 +83,5 @@ 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, "TestUtils",
"resource://testing-common/TestUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
"resource://gre/modules/NetUtil.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 = Services.io.newURI(place.referrer);
place.referrer = NetUtil.newURI(place.referrer);
} else if (place.referrer && place.referrer instanceof URL) {
place.referrer = Services.io.newURI(place.referrer.href);
place.referrer = NetUtil.newURI(place.referrer.href);
}
let visitDate = place.visitDate;
if (visitDate) {
@ -82,11 +82,7 @@ this.PlacesTestUtils = Object.freeze({
}];
infos.push(info);
}
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"
);
return PlacesUtils.history.insertMany(infos);
},
/*
@ -108,8 +104,8 @@ this.PlacesTestUtils = Object.freeze({
throw new Error("URL does not exist");
}
faviconPromises.push(new Promise((resolve, reject) => {
let uri = Services.io.newURI(key);
let faviconURI = Services.io.newURI(val);
let uri = NetUtil.newURI(key);
let faviconURI = NetUtil.newURI(val);
try {
PlacesUtils.favicons.setAndFetchFaviconForPage(
uri,