From d4cf5c3f6eba2dfee9c0424ac013ce01ffbd26d5 Mon Sep 17 00:00:00 2001 From: Sebastian Hengst Date: Wed, 11 Oct 2017 18:25:57 +0200 Subject: [PATCH] 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 --- .../urlbar/browser_action_keyword_override.js | 2 +- .../urlbar/browser_action_searchengine.js | 17 +++---- .../browser_action_searchengine_alias.js | 17 +++---- .../urlbar/browser_autocomplete_a11y_label.js | 8 +-- .../urlbar/browser_autocomplete_autoselect.js | 9 ++-- .../urlbar/browser_autocomplete_cursor.js | 5 +- .../browser_autocomplete_edit_completed.js | 11 ++-- .../urlbar/browser_autocomplete_enter_race.js | 8 ++- .../urlbar/browser_autocomplete_no_title.js | 14 +++-- ...rowser_autocomplete_tag_star_visibility.js | 21 ++++---- .../test/urlbar/browser_search_favicon.js | 3 +- ...browser_urlbarSearchSuggestions_opt-out.js | 5 +- .../urlbar/browser_urlbar_remove_match.js | 8 +-- ...no_speculative_connect_with_client_cert.js | 8 +-- browser/base/content/test/urlbar/head.js | 9 ---- .../test/browser/browser-common.ini | 1 + .../test/browser/browser_ext_omnibox.js | 6 +-- .../BrowserTestUtils/BrowserTestUtils.jsm | 50 +++++++++++++++++- testing/modules/TestUtils.jsm | 51 +------------------ .../places/tests/PlacesTestUtils.jsm | 18 +++---- 20 files changed, 120 insertions(+), 151 deletions(-) diff --git a/browser/base/content/test/urlbar/browser_action_keyword_override.js b/browser/base/content/test/urlbar/browser_action_keyword_override.js index 8e57fc88a9fa..45842276879b 100644 --- a/browser/base/content/test/urlbar/browser_action_keyword_override.js +++ b/browser/base/content/test/urlbar/browser_action_keyword_override.js @@ -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; diff --git a/browser/base/content/test/urlbar/browser_action_searchengine.js b/browser/base/content/test/urlbar/browser_action_searchengine.js index 4c3b4dff57dd..bb23bd4b2806 100644 --- a/browser/base/content/test/urlbar/browser_action_searchengine.js +++ b/browser/base/content/test/urlbar/browser_action_searchengine.js @@ -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); }); diff --git a/browser/base/content/test/urlbar/browser_action_searchengine_alias.js b/browser/base/content/test/urlbar/browser_action_searchengine_alias.js index 9824b2d09dc7..bf84aa017b69 100644 --- a/browser/base/content/test/urlbar/browser_action_searchengine_alias.js +++ b/browser/base/content/test/urlbar/browser_action_searchengine_alias.js @@ -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); }); diff --git a/browser/base/content/test/urlbar/browser_autocomplete_a11y_label.js b/browser/base/content/test/urlbar/browser_autocomplete_a11y_label.js index ea9f5f46e9d0..6904940cd183 100644 --- a/browser/base/content/test/urlbar/browser_autocomplete_a11y_label.js +++ b/browser/base/content/test/urlbar/browser_autocomplete_a11y_label.js @@ -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: <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(); }); diff --git a/browser/base/content/test/urlbar/browser_autocomplete_autoselect.js b/browser/base/content/test/urlbar/browser_autocomplete_autoselect.js index fe7c4eb818e2..261876c6f364 100644 --- a/browser/base/content/test/urlbar/browser_autocomplete_autoselect.js +++ b/browser/base/content/test/urlbar/browser_autocomplete_autoselect.js @@ -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); }); diff --git a/browser/base/content/test/urlbar/browser_autocomplete_cursor.js b/browser/base/content/test/urlbar/browser_autocomplete_cursor.js index 7cf9da9f3b70..a0af6f43df89 100644 --- a/browser/base/content/test/urlbar/browser_autocomplete_cursor.js +++ b/browser/base/content/test/urlbar/browser_autocomplete_cursor.js @@ -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); }); diff --git a/browser/base/content/test/urlbar/browser_autocomplete_edit_completed.js b/browser/base/content/test/urlbar/browser_autocomplete_edit_completed.js index 27834623cef0..76b06923cf6b 100644 --- a/browser/base/content/test/urlbar/browser_autocomplete_edit_completed.js +++ b/browser/base/content/test/urlbar/browser_autocomplete_edit_completed.js @@ -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); }); diff --git a/browser/base/content/test/urlbar/browser_autocomplete_enter_race.js b/browser/base/content/test/urlbar/browser_autocomplete_enter_race.js index 466616069d67..5983e034f417 100644 --- a/browser/base/content/test/urlbar/browser_autocomplete_enter_race.js +++ b/browser/base/content/test/urlbar/browser_autocomplete_enter_race.js @@ -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); diff --git a/browser/base/content/test/urlbar/browser_autocomplete_no_title.js b/browser/base/content/test/urlbar/browser_autocomplete_no_title.js index 7b0ef2f7503b..8fd3aa282c54 100644 --- a/browser/base/content/test/urlbar/browser_autocomplete_no_title.js +++ b/browser/base/content/test/urlbar/browser_autocomplete_no_title.js @@ -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); }); diff --git a/browser/base/content/test/urlbar/browser_autocomplete_tag_star_visibility.js b/browser/base/content/test/urlbar/browser_autocomplete_tag_star_visibility.js index 18474f36a938..cd934771ad3c 100644 --- a/browser/base/content/test/urlbar/browser_autocomplete_tag_star_visibility.js +++ b/browser/base/content/test/urlbar/browser_autocomplete_tag_star_visibility.js @@ -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"); diff --git a/browser/base/content/test/urlbar/browser_search_favicon.js b/browser/base/content/test/urlbar/browser_search_favicon.js index 5d4f9976fb43..175f74bb0fc9 100644 --- a/browser/base/content/test/urlbar/browser_search_favicon.js +++ b/browser/base/content/test/urlbar/browser_search_favicon.js @@ -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"); diff --git a/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions_opt-out.js b/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions_opt-out.js index a7ed5a1e5617..2accabb3833f 100644 --- a/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions_opt-out.js +++ b/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions_opt-out.js @@ -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"); diff --git a/browser/base/content/test/urlbar/browser_urlbar_remove_match.js b/browser/base/content/test/urlbar/browser_urlbar_remove_match.js index aed457c16442..e7a89e09feb1 100644 --- a/browser/base/content/test/urlbar/browser_urlbar_remove_match.js +++ b/browser/base/content/test/urlbar/browser_urlbar_remove_match.js @@ -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 } : {}; diff --git a/browser/base/content/test/urlbar/browser_urlbar_search_no_speculative_connect_with_client_cert.js b/browser/base/content/test/urlbar/browser_urlbar_search_no_speculative_connect_with_client_cert.js index 40eaa399c36b..3d050bd60571 100644 --- a/browser/base/content/test/urlbar/browser_urlbar_search_no_speculative_connect_with_client_cert.js +++ b/browser/base/content/test/urlbar/browser_urlbar_search_no_speculative_connect_with_client_cert.js @@ -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"); diff --git a/browser/base/content/test/urlbar/head.js b/browser/base/content/test/urlbar/head.js index e002292a9c28..0dfe22791309 100644 --- a/browser/base/content/test/urlbar/head.js +++ b/browser/base/content/test/urlbar/head.js @@ -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]; -} diff --git a/browser/components/extensions/test/browser/browser-common.ini b/browser/components/extensions/test/browser/browser-common.ini index ee8b963d4ef1..a3b72b55bdf9 100644 --- a/browser/components/extensions/test/browser/browser-common.ini +++ b/browser/components/extensions/test/browser/browser-common.ini @@ -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] diff --git a/browser/components/extensions/test/browser/browser_ext_omnibox.js b/browser/components/extensions/test/browser/browser_ext_omnibox.js index d7b95386b572..ec224991140d 100644 --- a/browser/components/extensions/test/browser/browser_ext_omnibox.js +++ b/browser/components/extensions/test/browser/browser_ext_omnibox.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"; } diff --git a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm index 2c73279860f5..34436a736d61 100644 --- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm +++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm @@ -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 diff --git a/testing/modules/TestUtils.jsm b/testing/modules/TestUtils.jsm index 0b1fbb9ce132..1b552b499b65 100644 --- a/testing/modules/TestUtils.jsm +++ b/testing/modules/TestUtils.jsm @@ -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); - }); - }, + } }; diff --git a/toolkit/components/places/tests/PlacesTestUtils.jsm b/toolkit/components/places/tests/PlacesTestUtils.jsm index a80bd99d0f30..5892f10d4e67 100644 --- a/toolkit/components/places/tests/PlacesTestUtils.jsm +++ b/toolkit/components/places/tests/PlacesTestUtils.jsm @@ -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,