Bug 1250958 - fix browser_markPageAsFollowedLink.js for e10s (and fix framed link coloring to make it pass). r=jaws draft
authorMarco Bonardo <mbonardo@mozilla.com>
Fri, 26 Feb 2016 18:55:36 +0100
changeset 336094 4b3bc268f3c010bcc65a9aa8f319574673cc5608
parent 336085 952e06e0b849d497546ad42bfff4d3a7873e810f
child 515302 f26f4d375ead8488e6d80b90587ba4efbb9a2ec0
push id11970
push usermak77@bonardo.net
push dateWed, 02 Mar 2016 12:25:41 +0000
reviewersjaws
bugs1250958
milestone47.0a1
Bug 1250958 - fix browser_markPageAsFollowedLink.js for e10s (and fix framed link coloring to make it pass). r=jaws MozReview-Commit-ID: 9k58B16nPL8
browser/components/places/tests/browser/browser.ini
browser/components/places/tests/browser/browser_markPageAsFollowedLink.js
browser/modules/ContentClick.jsm
--- a/browser/components/places/tests/browser/browser.ini
+++ b/browser/components/places/tests/browser/browser.ini
@@ -41,15 +41,14 @@ skip-if = e10s # Bug ?????? - test fails
 [browser_library_left_pane_select_hierarchy.js]
 [browser_library_middleclick.js]
 [browser_library_open_leak.js]
 [browser_library_openFlatContainer.js]
 [browser_library_panel_leak.js]
 [browser_library_search.js]
 [browser_library_views_liveupdate.js]
 [browser_markPageAsFollowedLink.js]
-skip-if = e10s # Bug 933103 - mochitest's EventUtils.synthesizeMouse functions not e10s friendly (test does EventUtils.sendMouseEvent...)
 [browser_sidebarpanels_click.js]
 skip-if = true # temporarily disabled for breaking the treeview - bug 658744
 [browser_sort_in_library.js]
 [browser_toolbar_migration.js]
 [browser_toolbarbutton_menu_context.js]
 [browser_views_liveupdate.js]
--- a/browser/components/places/tests/browser/browser_markPageAsFollowedLink.js
+++ b/browser/components/places/tests/browser/browser_markPageAsFollowedLink.js
@@ -1,86 +1,67 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- */
-
 /**
  * Tests that visits across frames are correctly represented in the database.
  */
 
 const BASE_URL = "http://mochi.test:8888/browser/browser/components/places/tests/browser";
 const PAGE_URL = BASE_URL + "/framedPage.html";
 const LEFT_URL = BASE_URL + "/frameLeft.html";
 const RIGHT_URL = BASE_URL + "/frameRight.html";
 
-var gTabLoaded = false;
-var gLeftFrameVisited = false;
+add_task(function* test() {
+  // We must wait for both frames to be loaded and the visits to be registered.
+  let deferredLeftFrameVisit = PromiseUtils.defer();
+  let deferredRightFrameVisit = PromiseUtils.defer();
 
-var observer = {
-  observe: function(aSubject, aTopic, aData)
-  {
-    let url = aSubject.QueryInterface(Ci.nsIURI).spec;
-    if (url == LEFT_URL ) {
-      is(getTransitionForUrl(url), null,
-         "Embed visits should not get a database entry.");
-      gLeftFrameVisited = true;
-      maybeClickLink();
-    }
-    else if (url == RIGHT_URL ) {
-      is(getTransitionForUrl(url), PlacesUtils.history.TRANSITION_FRAMED_LINK,
-         "User activated visits should get a FRAMED_LINK transition.");
-      finish();
-    }
-  },
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver])
-};
-Services.obs.addObserver(observer, "uri-visit-saved", false);
+  Services.obs.addObserver(function observe(subject) {
+    Task.spawn(function* () {
+      let url = subject.QueryInterface(Ci.nsIURI).spec;
+      if (url == LEFT_URL ) {
+        is((yield getTransitionForUrl(url)), null,
+           "Embed visits should not get a database entry.");
+        deferredLeftFrameVisit.resolve();
+      }
+      else if (url == RIGHT_URL ) {
+        is((yield getTransitionForUrl(url)),
+           PlacesUtils.history.TRANSITION_FRAMED_LINK,
+           "User activated visits should get a FRAMED_LINK transition.");
+        Services.obs.removeObserver(observe, "uri-visit-saved");
+        deferredRightFrameVisit.resolve();
+      }
+    });
+  }, "uri-visit-saved", false);
+
+  // Open a tab and wait for all the subframes to load.
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE_URL);
 
-function test()
-{
-  waitForExplicitFinish();
-  gBrowser.selectedTab = gBrowser.addTab(PAGE_URL);
-  let frameCount = 0;
-  gBrowser.selectedBrowser.addEventListener("DOMContentLoaded",
-    function (event)
-    {
-      // Wait for all the frames.
-      if (frameCount++ < 2)
-        return;
-      gBrowser.selectedBrowser.removeEventListener("DOMContentLoaded", arguments.callee, false)
-      gTabLoaded = true;
-      maybeClickLink();
-    }, false
-  );
-}
+  // Wait for the left frame visit to be registered.
+  info("Waiting left frame visit");
+  yield deferredLeftFrameVisit.promise;
+
+  // Click on the link in the left frame to cause a page load in the
+  // right frame.
+  info("Clicking link");
+  yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
+    content.frames[0].document.getElementById("clickme").click();
+  });
+
+  // Wait for the right frame visit to be registered.
+  info("Waiting right frame visit");
+  yield deferredRightFrameVisit.promise;
 
-function maybeClickLink() {
-  if (gTabLoaded && gLeftFrameVisited) {
-    // Click on the link in the left frame to cause a page load in the
-    // right frame.
-    EventUtils.sendMouseEvent({type: "click"}, "clickme", content.frames[0]);
+  yield BrowserTestUtils.removeTab(tab);
+});
+
+function* getTransitionForUrl(url) {
+  // Ensure all the transactions completed.
+  yield PlacesTestUtils.promiseAsyncUpdates();
+  let db = yield PlacesUtils.promiseDBConnection();
+  let rows = yield db.execute(`
+    SELECT visit_type
+    FROM moz_historyvisits
+    WHERE place_id = (SELECT id FROM moz_places WHERE url = :url)`,
+    { url });
+  if (rows.length) {
+    return rows[0].getResultByName("visit_type");
   }
+  return null;
 }
-
-function getTransitionForUrl(aUrl)
-{
-  let dbConn = PlacesUtils.history
-                          .QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
-  let stmt = dbConn.createStatement(
-    "SELECT visit_type FROM moz_historyvisits WHERE place_id = " +
-      "(SELECT id FROM moz_places WHERE url = :page_url)");
-  stmt.params.page_url = aUrl;
-  try {
-    if (!stmt.executeStep()) {
-      return null;
-    }
-    return stmt.row.visit_type;
-  }
-  finally {
-    stmt.finalize();
-  }
-}
-
-registerCleanupFunction(function ()
-{
-  gBrowser.removeTab(gBrowser.selectedTab);
-  Services.obs.removeObserver(observer, "uri-visit-saved");
-})
--- a/browser/modules/ContentClick.jsm
+++ b/browser/modules/ContentClick.jsm
@@ -56,31 +56,30 @@ var ContentClick = {
                                                      , "location"
                                                      , "keyword" ]
                                        }, window);
       return;
     }
 
     // Note: We don't need the sidebar code here.
 
-    // This part is based on handleLinkClick.
-    var where = window.whereToOpenLink(json);
-    if (where == "current")
-      return;
-
-    // Todo(903022): code for where == save
-
-    let params = { charset: browser.characterSet,
-                   referrerURI: browser.documentURI,
-                   referrerPolicy: json.referrerPolicy,
-                   noReferrer: json.noReferrer };
-    window.openLinkIn(json.href, where, params);
-
     // Mark the page as a user followed link.  This is done so that history can
     // distinguish automatic embed visits from user activated ones.  For example
     // pages loaded in frames are embed visits and lost with the session, while
     // visits across frames should be preserved.
     try {
       if (!PrivateBrowsingUtils.isWindowPrivate(window))
         PlacesUIUtils.markPageAsFollowedLink(json.href);
     } catch (ex) { /* Skip invalid URIs. */ }
+
+    // This part is based on handleLinkClick.
+    var where = window.whereToOpenLink(json);
+    if (where == "current")
+      return;
+
+    // Todo(903022): code for where == save
+    let params = { charset: browser.characterSet,
+                   referrerURI: browser.documentURI,
+                   referrerPolicy: json.referrerPolicy,
+                   noReferrer: json.noReferrer };
+    window.openLinkIn(json.href, where, params);
   }
 };