Bug 1398080 - Fix intermittent failures related to about:home search. r=Mardak
authorAndrei Oprea <andrei.br92@gmail.com>
Wed, 06 Sep 2017 10:34:26 +0300
changeset 429337 d2e927cb3a6302862690e95a6f480af268f0020a
parent 429336 fcbd8cdd83082eb65837432c372efbea0a177721
child 429338 ac970269bcc3c168fb8d7f76d655ace6c4625462
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMardak
bugs1398080
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1398080 - Fix intermittent failures related to about:home search. r=Mardak MozReview-Commit-ID: 1SRe0a0nIDT
browser/modules/test/browser/browser_UsageTelemetry_content_aboutHome.js
--- a/browser/modules/test/browser/browser_UsageTelemetry_content_aboutHome.js
+++ b/browser/modules/test/browser/browser_UsageTelemetry_content_aboutHome.js
@@ -35,24 +35,23 @@ add_task(async function setup() {
 
   // Make sure to restore the engine once we're done.
   registerCleanupFunction(async function() {
     Services.search.currentEngine = originalEngine;
     Services.search.removeEngine(engineDefault);
     Services.search.removeEngine(engineOneOff);
     await PlacesTestUtils.clearHistory();
     Services.telemetry.setEventRecordingEnabled("navigation", false);
+    Services.prefs.clearUserPref("browser.newtabpage.activity-stream.aboutHome.enabled");
   });
 });
 
 add_task(async function test_abouthome_simpleQuery() {
   // Make sure Activity Stream about:home is disabled.
-  await SpecialPowers.pushPrefEnv({set: [
-    ["browser.newtabpage.activity-stream.aboutHome.enabled", false]
-  ]});
+  Services.prefs.setBoolPref("browser.newtabpage.activity-stream.aboutHome.enabled", false);
 
   // Let's reset the counts.
   Services.telemetry.clearScalars();
   Services.telemetry.clearEvents();
   let search_hist = getAndClearKeyedHistogram("SEARCH_COUNTS");
 
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
 
@@ -64,16 +63,21 @@ add_task(async function test_abouthome_s
     }, true, true);
   });
 
   info("Load about:home.");
   tab.linkedBrowser.loadURI("about:home");
   info("Wait for AboutHomeLoadSnippetsCompleted.");
   await promiseAboutHomeLoaded;
 
+  info("Wait for ContentSearchUI search provider to initialize.");
+  await ContentTask.spawn(tab.linkedBrowser, null, async function() {
+    await ContentTaskUtils.waitForCondition(() => content.wrappedJSObject.gContentSearchController.defaultEngine);
+  });
+
   info("Trigger a simple serch, just test + enter.");
   let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
   await typeInSearchField(tab.linkedBrowser, "test query", "searchText");
   await BrowserTestUtils.synthesizeKey("VK_RETURN", {}, tab.linkedBrowser);
   await p;
 
   // Check if the scalars contain the expected values.
   const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, false);
@@ -89,40 +93,43 @@ add_task(async function test_abouthome_s
   events = (events.parent || []).filter(e => e[1] == "navigation" && e[2] == "search");
   checkEvents(events, [["navigation", "search", "about_home", "enter", {engine: "other-MozSearch"}]]);
 
   await BrowserTestUtils.removeTab(tab);
 });
 
 add_task(async function test_abouthome_activitystream_simpleQuery() {
   // Make sure Activity Stream about:home is enabled.
-  await SpecialPowers.pushPrefEnv({set: [
-    ["browser.newtabpage.activity-stream.aboutHome.enabled", true]
-  ]});
+  Services.prefs.setBoolPref("browser.newtabpage.activity-stream.aboutHome.enabled", true);
 
   // Let's reset the counts.
   Services.telemetry.clearScalars();
   Services.telemetry.clearEvents();
   let search_hist = getAndClearKeyedHistogram("SEARCH_COUNTS");
 
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
 
   info("Setup waiting for search input to initialise.");
   let promiseAboutHomeSearchLoaded = new Promise(resolve => {
     tab.linkedBrowser.addEventListener("ContentSearchClient", function loadListener(event) {
       tab.linkedBrowser.removeEventListener("ContentSearchClient", loadListener, true);
-      resolve();
+      executeSoon(resolve);
     }, true, true);
   });
 
   info("Load about:home.");
   tab.linkedBrowser.loadURI("about:home");
   info("Wait for ActivityStream search input.");
   await promiseAboutHomeSearchLoaded;
 
+  info("Wait for ContentSearchUI search provider to initialize.");
+  await ContentTask.spawn(tab.linkedBrowser, null, async function() {
+    await ContentTaskUtils.waitForCondition(() => content.wrappedJSObject.gContentSearchController.defaultEngine);
+  });
+
   info("Trigger a simple serch, just test + enter.");
   let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
   await typeInSearchField(tab.linkedBrowser, "test query", "newtab-search-text");
   await BrowserTestUtils.synthesizeKey("VK_RETURN", {}, tab.linkedBrowser);
   await p;
 
   // Check if the scalars contain the expected values.
   const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, false);