Bug 998303 - browser/base/content/test/general/browser_urlbar_search_healthreport.js attempts to connect to www.google.com. r=mak, a=test-only
authorDrew Willcoxon <adw@mozilla.com>
Thu, 15 May 2014 19:04:47 -0700
changeset 199262 3765981445e18c176a6d3cb9fe4ee7b3ef38c17a
parent 199261 e9c50ea636abe8757cc0f86dd2dc84ef6bd60ff3
child 199263 3b4af0a7bee5c5902b6dab51117470c39b131918
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, test-only
bugs998303
milestone31.0a2
Bug 998303 - browser/base/content/test/general/browser_urlbar_search_healthreport.js attempts to connect to www.google.com. r=mak, a=test-only
browser/base/content/test/general/browser_urlbar_search_healthreport.js
--- a/browser/base/content/test/general/browser_urlbar_search_healthreport.js
+++ b/browser/base/content/test/general/browser_urlbar_search_healthreport.js
@@ -37,29 +37,55 @@ function test() {
         if (day.has(field)) {
           oldCount = day.get(field);
         }
       }
 
       let tab = gBrowser.addTab();
       gBrowser.selectedTab = tab;
 
-      gURLBar.value = "firefox health report";
+      let searchStr = "firefox health report";
+      let expectedURL = Services.search.currentEngine.
+                        getSubmission(searchStr, "", "keyword").uri.spec;
+
+      // Expect the search URL to load but stop it as soon as it starts.
+      let loadPromise = waitForDocLoadAndStopIt(expectedURL);
+
+      // Meanwhile, poll for the new measurement.
+      let count = 0;
+      let measurementDeferred = Promise.defer();
+      function getNewMeasurement() {
+        if (count++ >= 10) {
+          ok(false, "Timed out waiting for new measurement");
+          measurementDeferred.resolve();
+          return;
+        }
+        m.getValues().then(function onData(data) {
+          if (data.days.hasDay(now)) {
+            let day = data.days.getDay(now);
+            if (day.has(field)) {
+              let newCount = day.get(field);
+              if (newCount > oldCount) {
+                is(newCount, oldCount + 1,
+                   "Exactly one search has been recorded.");
+                measurementDeferred.resolve();
+                return;
+              }
+            }
+          }
+          executeSoon(getNewMeasurement);
+        });
+      }
+      executeSoon(getNewMeasurement);
+
+      // Trigger the search.
+      gURLBar.value = searchStr;
       gURLBar.handleCommand();
 
-      executeSoon(() => executeSoon(() => {
+      // Wait for the page load and new measurement.
+      Promise.all([loadPromise, measurementDeferred.promise]).then(() => {
         gBrowser.removeTab(tab);
-
-        m.getValues().then(function onData(data) {
-          ok(data.days.hasDay(now), "FHR has data for today.");
-          let day = data.days.getDay(now);
-          ok(day.has(field), "FHR has url bar count for today.");
-
-          let newCount = day.get(field);
-
-          is(newCount, oldCount + 1, "Exactly one search has been recorded.");
-          finish();
-        });
-      }));
+        finish();
+      });
     });
   });
 }