Bug 1236554 - enable browser_visituri in e10s, r=mak
authorNeil Deakin <neil@mozilla.com>
Wed, 20 Jan 2016 08:45:58 -0500
changeset 280780 9d2c02559cdf964aa1a8d0da1c61f6b1780cdf9f
parent 280779 530d3160f8e775af4efde14aa9985cfe31333c6d
child 280781 7d55178b297d3b120ef659c9b24aaf67c24f6d5c
push id29922
push usercbook@mozilla.com
push dateThu, 21 Jan 2016 10:51:00 +0000
treeherdermozilla-central@977d78a8dd78 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1236554
milestone46.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 1236554 - enable browser_visituri in e10s, r=mak
toolkit/components/places/tests/browser/browser_visituri.js
--- a/toolkit/components/places/tests/browser/browser_visituri.js
+++ b/toolkit/components/places/tests/browser/browser_visituri.js
@@ -1,91 +1,63 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-gBrowser.selectedTab = gBrowser.addTab();
-
-function finishAndCleanUp()
-{
-  gBrowser.removeCurrentTab();
-  PlacesTestUtils.clearHistory().then(finish);
-}
-
 /**
  * One-time observer callback.
  */
-function waitForObserve(name, callback)
-{
-  var observerService = Cc["@mozilla.org/observer-service;1"]
-                        .getService(Ci.nsIObserverService);
-  var observer = {
-    QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
-    observe: function(subject, topic, data) {
-      observerService.removeObserver(observer, name);
-      observer = null;
-      callback(subject, topic, data);
-    }
-  };
-
-  observerService.addObserver(observer, name, false);
-}
-
-/**
- * One-time DOMContentLoaded callback.
- */
-function waitForLoad(callback)
-{
-  gBrowser.addEventListener("DOMContentLoaded", function() {
-    gBrowser.removeEventListener("DOMContentLoaded", arguments.callee, true);
-    callback();
-  }, true);
+function promiseObserve(name, checkFn) {
+  return new Promise(resolve => {
+    Services.obs.addObserver(function observer(subject) {
+      if (checkFn(subject)) {
+        Services.obs.removeObserver(observer, name);
+        resolve();
+      }
+    }, name, false);
+  });
 }
 
 var conn = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
 
 /**
  * Gets a single column value from either the places or historyvisits table.
  */
-function getColumn(table, column, fromColumnName, fromColumnValue)
-{
+function getColumn(table, column, fromColumnName, fromColumnValue) {
   let sql = `SELECT ${column}
              FROM ${table}
              WHERE ${fromColumnName} = :val
              LIMIT 1`;
   let stmt = conn.createStatement(sql);
   try {
     stmt.params.val = fromColumnValue;
     ok(stmt.executeStep(), "Expect to get a row");
     return stmt.row[column];
   }
   finally {
     stmt.reset();
   }
 }
 
-function test()
-{
+add_task(function* () {
   // Make sure places visit chains are saved correctly with a redirect
   // transitions.
 
-  waitForExplicitFinish();
-
   // Part 1: observe history events that fire when a visit occurs.
   // Make sure visits appear in order, and that the visit chain is correct.
   var expectedUrls = [
     "http://example.com/tests/toolkit/components/places/tests/browser/begin.html",
     "http://example.com/tests/toolkit/components/places/tests/browser/redirect_twice.sjs",
     "http://example.com/tests/toolkit/components/places/tests/browser/redirect_once.sjs",
     "http://example.com/tests/toolkit/components/places/tests/browser/final.html"
   ];
   var currentIndex = 0;
 
-  waitForObserve("uri-visit-saved", function(subject, topic, data) {
+  function checkObserver(subject) {
     var uri = subject.QueryInterface(Ci.nsIURI);
     var expected = expectedUrls[currentIndex];
     is(uri.spec, expected, "Saved URL visit " + uri.spec);
 
     var placeId = getColumn("moz_places", "id", "url", uri.spec);
     var fromVisitId = getColumn("moz_historyvisits", "from_visit", "place_id", placeId);
 
     if (currentIndex == 0) {
@@ -94,25 +66,23 @@ function test()
     else {
       var lastVisitId = getColumn("moz_historyvisits", "place_id", "id", fromVisitId);
       var fromVisitUrl = getColumn("moz_places", "url", "id", lastVisitId);
       is(fromVisitUrl, expectedUrls[currentIndex - 1],
          "From visit was " + expectedUrls[currentIndex - 1]);
     }
 
     currentIndex++;
-    if (currentIndex < expectedUrls.length) {
-      waitForObserve("uri-visit-saved", arguments.callee);
-    }
-    else {
-      finishAndCleanUp();
-    }
-  });
+    return (currentIndex >= expectedUrls.length);
+  }
+  let visitUriPromise = promiseObserve("uri-visit-saved", checkObserver);
+
+  const testUrl = "http://example.com/tests/toolkit/components/places/tests/browser/begin.html";
+  yield BrowserTestUtils.openNewForegroundTab(gBrowser, testUrl);
 
   // Load begin page, click link on page to record visits.
-  content.location.href = "http://example.com/tests/toolkit/components/places/tests/browser/begin.html";
-  waitForLoad(function() {
-    EventUtils.sendMouseEvent({type: 'click'}, 'clickme', content.window);
-    waitForLoad(function() {
-      content.location.href = "about:blank";
-    });
-  });
-}
+  yield BrowserTestUtils.synthesizeMouseAtCenter("#clickme", { }, gBrowser.selectedBrowser);
+  yield visitUriPromise;
+
+  yield PlacesTestUtils.clearHistory();
+
+  gBrowser.removeCurrentTab();
+});