Bug 1330332 - Update prerendering tests to validate global history state, r=smaug
authorMichael Layzell <michael@thelayzells.com>
Wed, 11 Jan 2017 13:34:17 -0500
changeset 375227 031e8ac3457d8beb672b253291a801797016f6b0
parent 375226 d00ea9cc0fc5590bd111a624ab75ea767645dcd2
child 375228 357422df05cd565f9799bc10317e7f7986ed6634
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1330332
milestone53.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 1330332 - Update prerendering tests to validate global history state, r=smaug MozReview-Commit-ID: BlmyzkURF9t
dom/tests/browser/browser.ini
dom/tests/browser/browser_prerendering.js
dom/tests/browser/prerender.html
dom/tests/browser/prerender_target.html
--- a/dom/tests/browser/browser.ini
+++ b/dom/tests/browser/browser.ini
@@ -47,10 +47,12 @@ tags = openwindow
 skip-if = toolkit == 'android'  || (os == "linux" && debug) # see bug 1261495 for Linux debug time outs
 support-files =
   test_new_window_from_content_child.html
 [browser_test_toolbars_visibility.js]
 support-files =
   test_new_window_from_content_child.html
 [browser_xhr_sandbox.js]
 [browser_prerendering.js]
-support-files = prerender.html
+support-files =
+  prerender.html
+  prerender_target.html
 skip-if = !e10s # Prerendering requires e10s
--- a/dom/tests/browser/browser_prerendering.js
+++ b/dom/tests/browser/browser_prerendering.js
@@ -1,9 +1,23 @@
 const URL = "https://example.com/browser/dom/tests/browser/prerender.html";
+const PRERENDERED_URL = "https://example.com/browser/dom/tests/browser/prerender_target.html";
+
+XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
+                                  "resource://gre/modules/PlacesUtils.jsm");
+
+// Returns a promise which resolves to whether or not PRERENDERED_URL has been visited.
+function prerenderedVisited() {
+  let uri = Services.io.newURI(PRERENDERED_URL, null, null);
+  return new Promise(resolve => {
+    PlacesUtils.asyncHistory.isURIVisited(uri, (aUri, aIsVisited) => {
+      resolve(aIsVisited);
+    });
+  });
+}
 
 // Wait for a process change and then fulfil the promise.
 function awaitProcessChange(browser) {
   return new Promise(resolve => {
     browser.addEventListener("BrowserChangedProcess", function bcp(e) {
       browser.removeEventListener("BrowserChangedProcess", bcp);
       info("The browser changed process!");
       resolve();
@@ -33,60 +47,63 @@ add_task(function* () {
           ["dom.linkPrerender.enabled", true],
           ["dom.require_user_interaction_for_beforeunload", false]]
   });
 });
 
 // Test 1: Creating a prerendered browser, and clicking on a link to that browser,
 // will cause changes.
 add_task(function* () {
+  yield PlacesUtils.history.clear();
+
   let tab = gBrowser.addTab(URL);
 
+  is(yield prerenderedVisited(), false, "Should not have been visited");
+
   yield new Promise(resolve => {
     tab.linkedBrowser.messageManager.addMessageListener("Prerender:Request", function f() {
       tab.linkedBrowser.messageManager.removeMessageListener("Prerender:Request", f);
       info("Successfully received the prerender request");
       resolve();
     });
   });
   yield BrowserTestUtils.switchTab(gBrowser, tab);
 
+  is(yield prerenderedVisited(), false, "Should not have been visited");
+
   // Check that visibilityState is set correctly in the prerendered tab. We
   // check all of the tabs because we have no easy way to tell which one is
   // which.
-  let result;
+  let foundTab;
   for (let i = 0; i < gBrowser.tabs.length; ++i) {
-    result = yield ContentTask.spawn(gBrowser.tabs[i].linkedBrowser, null, function* () {
-      let interesting = content.document.location.toString() == "data:text/html,b";
-      if (interesting) {
-        is(content.document.visibilityState, "prerender");
-      }
-      return interesting;
-    });
-    if (result) {
+    foundTab = yield ContentTask.spawn(gBrowser.tabs[i].linkedBrowser, null,
+                                       () => content.document.visibilityState == "prerender");
+    if (foundTab) {
       break;
     }
   }
-  ok(result, "The prerender tab was found!");
+  ok(foundTab, "The prerender tab was found!");
 
   let dialogShown = awaitAndCloseBeforeUnloadDialog();
   ContentTask.spawn(tab.linkedBrowser, null, function*() {
     let anchor = content.document.querySelector("a");
     anchor.click();
   });
   yield dialogShown;
 
   yield awaitProcessChange(tab.linkedBrowser);
 
-  yield ContentTask.spawn(tab.linkedBrowser, null, function*() {
-    is(content.document.location.toString(), "data:text/html,b");
-    is(content.document.visibilityState, "visible",
-       "VisibilityState of formerly prerendered window must be visible");
+  yield ContentTask.spawn(tab.linkedBrowser, PRERENDERED_URL, function*(PRERENDERED_URL) {
+    is(content.document.location.toString(), PRERENDERED_URL);
+    isnot(content.document.visibilityState, "prerender",
+          "VisibilityState of formerly prerendered window must not be prerender");
   });
 
+  is(yield prerenderedVisited(), true, "Should have been visited");
+
   let groupedSHistory = tab.linkedBrowser.frameLoader.groupedSHistory;
   is(groupedSHistory.count, 2, "Check total length of grouped shistory.");
   is(gBrowser.tabs.length, 3, "Check number of opened tabs.");
 
   // We don't touch the about:blank tab opened when browser mochitest runs.
   // The tabs under test are the other 2 tabs, so we're expecting 2 TabClose.
   let closed = new Promise(resolve => {
     let seen = 0;
@@ -96,24 +113,30 @@ add_task(function* () {
         resolve();
       }
     });
   });
 
   yield BrowserTestUtils.removeTab(tab);
   yield closed;
 
+  is(yield prerenderedVisited(), true, "Should have been visited");
+
   is(gBrowser.tabs.length, 1);
 });
 
 // Test 2: Creating a prerendered browser, and navigating to a different url,
 // succeeds, and closes the prerendered browser.
 add_task(function* () {
+  yield PlacesUtils.history.clear();
+
   let tab = gBrowser.addTab(URL);
 
+  is(yield prerenderedVisited(), false, "Should not have been visited");
+
   yield Promise.all([
     BrowserTestUtils.browserLoaded(tab.linkedBrowser),
     new Promise(resolve => {
       tab.linkedBrowser.messageManager.addMessageListener("Prerender:Request", function f() {
         tab.linkedBrowser.messageManager.removeMessageListener("Prerender:Request", f);
         info("Successfully received the prerender request");
         resolve();
       });
@@ -124,16 +147,18 @@ add_task(function* () {
   let dialogShown = awaitAndCloseBeforeUnloadDialog();
   ContentTask.spawn(tab.linkedBrowser, null, function*() {
     let anchor = content.document.querySelector("a");
     anchor.setAttribute("href", "data:text/html,something_else");
     anchor.click();
   });
   yield dialogShown;
 
+  is(yield prerenderedVisited(), false, "Should not have been visited");
+
   yield Promise.all([
     BrowserTestUtils.browserLoaded(tab.linkedBrowser),
     new Promise(resolve => {
       let seen = false;
       gBrowser.tabContainer.addEventListener("TabClose", function f() {
         gBrowser.tabContainer.removeEventListener("TabClose", f);
         if (!seen) {
           seen = true;
@@ -143,10 +168,12 @@ add_task(function* () {
       });
     }),
   ]);
 
   yield ContentTask.spawn(tab.linkedBrowser, null, function*() {
     is(content.document.location.toString(), "data:text/html,something_else");
   });
 
+  is(yield prerenderedVisited(), false, "Should not have been visited");
+
   yield BrowserTestUtils.removeTab(tab);
 });
--- a/dom/tests/browser/prerender.html
+++ b/dom/tests/browser/prerender.html
@@ -1,7 +1,7 @@
 <html>
 <head><title>Prerender Test</title></head>
 <body onbeforeunload="return 'stay with me';">
-<link rel="prerender" href="data:text/html,b">
-<a href="data:text/html,b">clicky here</a>
+<link rel="prerender" href="https://example.com/browser/dom/tests/browser/prerender_target.html">
+<a href="https://example.com/browser/dom/tests/browser/prerender_target.html">clicky here</a>
 </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/dom/tests/browser/prerender_target.html
@@ -0,0 +1,4 @@
+<!doctype html>
+<body>
+    <p>This is just a random HTML document which will be loaded as a target for prerendering.</p>
+</body>