Bug 1255066 - [e10s] convert test_bug_461710_perwindowpb.html to mochitest-browser. r=mak
authorNihanth Subramanya <nhnt11@gmail.com>
Fri, 25 Mar 2016 11:38:33 -0400
changeset 290429 0d8ca812e2faade05f149e82db86b849d1d7e7a5
parent 290428 31249c60481310fe11d2d753eba7c4d79154169b
child 290430 51c718100df0fdd8d921eb62bcc180cfa765d9c0
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1255066
milestone48.0a1
Bug 1255066 - [e10s] convert test_bug_461710_perwindowpb.html to mochitest-browser. r=mak MozReview-Commit-ID: 4BafGjlLAe9
toolkit/components/places/tests/browser/461710_iframe.html
toolkit/components/places/tests/browser/461710_link_page-2.html
toolkit/components/places/tests/browser/461710_link_page-3.html
toolkit/components/places/tests/browser/461710_link_page.html
toolkit/components/places/tests/browser/461710_visited_page.html
toolkit/components/places/tests/browser/browser.ini
toolkit/components/places/tests/browser/browser_bug461710.js
toolkit/components/places/tests/chrome.ini
toolkit/components/places/tests/mochitest/bug_461710/.eslintrc
toolkit/components/places/tests/mochitest/bug_461710/iframe.html
toolkit/components/places/tests/mochitest/bug_461710/link_page-2.html
toolkit/components/places/tests/mochitest/bug_461710/link_page-3.html
toolkit/components/places/tests/mochitest/bug_461710/link_page.html
toolkit/components/places/tests/mochitest/bug_461710/visited_page.html
toolkit/components/places/tests/moz.build
toolkit/components/places/tests/test_bug_461710_perwindowpb.html
rename from toolkit/components/places/tests/mochitest/bug_461710/iframe.html
rename to toolkit/components/places/tests/browser/461710_iframe.html
rename from toolkit/components/places/tests/mochitest/bug_461710/link_page-2.html
rename to toolkit/components/places/tests/browser/461710_link_page-2.html
--- a/toolkit/components/places/tests/mochitest/bug_461710/link_page-2.html
+++ b/toolkit/components/places/tests/browser/461710_link_page-2.html
@@ -3,11 +3,11 @@
   <head>
     <title>Link page 2</title>
     <style type="text/css">
       a:link { color: #0000ff; }
       a:visited { color: #ff0000; }
     </style>
   </head>
   <body>
-    <p><a href="visited_page.html" id="link">Link to the second visited page</a></p>
+    <p><a href="461710_visited_page.html" id="link">Link to the second visited page</a></p>
   </body>
 </html>
\ No newline at end of file
rename from toolkit/components/places/tests/mochitest/bug_461710/link_page-3.html
rename to toolkit/components/places/tests/browser/461710_link_page-3.html
--- a/toolkit/components/places/tests/mochitest/bug_461710/link_page-3.html
+++ b/toolkit/components/places/tests/browser/461710_link_page-3.html
@@ -3,11 +3,11 @@
   <head>
     <title>Link page 3</title>
     <style type="text/css">
       a:link { color: #0000ff; }
       a:visited { color: #ff0000; }
     </style>
   </head>
   <body>
-    <p><a href="visited_page.html" id="link">Link to the third visited page</a></p>
+    <p><a href="461710_visited_page.html" id="link">Link to the third visited page</a></p>
   </body>
 </html>
\ No newline at end of file
rename from toolkit/components/places/tests/mochitest/bug_461710/link_page.html
rename to toolkit/components/places/tests/browser/461710_link_page.html
--- a/toolkit/components/places/tests/mochitest/bug_461710/link_page.html
+++ b/toolkit/components/places/tests/browser/461710_link_page.html
@@ -3,11 +3,11 @@
   <head>
     <title>Link page</title>
     <style type="text/css">
       a:link { color: #0000ff; }
       a:visited { color: #ff0000; }
     </style>
   </head>
   <body>
-    <p><a href="visited_page.html" id="link">Link to the visited page</a></p>
+    <p><a href="461710_visited_page.html" id="link">Link to the visited page</a></p>
   </body>
 </html>
\ No newline at end of file
rename from toolkit/components/places/tests/mochitest/bug_461710/visited_page.html
rename to toolkit/components/places/tests/browser/461710_visited_page.html
--- a/toolkit/components/places/tests/browser/browser.ini
+++ b/toolkit/components/places/tests/browser/browser.ini
@@ -3,23 +3,24 @@ support-files =
   colorAnalyzer/category-discover.png
   colorAnalyzer/dictionaryGeneric-16.png
   colorAnalyzer/extensionGeneric-16.png
   colorAnalyzer/localeGeneric.png
   head.js
 
 [browser_bug248970.js]
 [browser_bug399606.js]
+[browser_bug461710.js]
 [browser_bug646422.js]
 [browser_bug680727.js]
 skip-if = buildapp == 'mulet' # Bug ?????? - test times out on try on all platforms, but works locally for markh!
 [browser_colorAnalyzer.js]
 [browser_double_redirect.js]
 [browser_favicon_privatebrowsing_perwindowpb.js]
 [browser_favicon_setAndFetchFaviconForPage.js]
 [browser_favicon_setAndFetchFaviconForPage_failures.js]
 [browser_notfound.js]
 [browser_redirect.js]
 [browser_settitle.js]
 [browser_visited_notfound.js]
 [browser_visituri.js]
 [browser_visituri_nohistory.js]
-[browser_visituri_privatebrowsing_perwindowpb.js]
+[browser_visituri_privatebrowsing_perwindowpb.js]
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/toolkit/components/places/tests/browser/browser_bug461710.js
@@ -0,0 +1,82 @@
+const kRed = "rgb(255, 0, 0)";
+const kBlue = "rgb(0, 0, 255)";
+
+const prefix = "http://example.com/tests/toolkit/components/places/tests/browser/461710_";
+
+add_task(function* () {
+  let contentPage = prefix + "iframe.html";
+  let normalWindow = yield BrowserTestUtils.openNewBrowserWindow();
+
+  let browser = normalWindow.gBrowser.selectedBrowser;
+  BrowserTestUtils.loadURI(browser, contentPage);
+  yield BrowserTestUtils.browserLoaded(browser, contentPage);
+
+  let privateWindow = yield BrowserTestUtils.openNewBrowserWindow({private: true});
+
+  browser = privateWindow.gBrowser.selectedBrowser;
+  BrowserTestUtils.loadURI(browser, contentPage);
+  yield BrowserTestUtils.browserLoaded(browser, contentPage);
+
+  let tests = [{
+    win: normalWindow,
+    topic: "uri-visit-saved",
+    subtest: "visited_page.html"
+  }, {
+    win: normalWindow,
+    topic: "visited-status-resolution",
+    subtest: "link_page.html",
+    color: kRed,
+    message: "Visited link coloring should work outside of private mode"
+  }, {
+    win: privateWindow,
+    topic: "visited-status-resolution",
+    subtest: "link_page-2.html",
+    color: kBlue,
+    message: "Visited link coloring should not work inside of private mode"
+  }, {
+    win: normalWindow,
+    topic: "visited-status-resolution",
+    subtest: "link_page-3.html",
+    color: kRed,
+    message: "Visited link coloring should work outside of private mode"
+  }];
+
+  let visited_page_url = prefix + tests[0].subtest;
+  for (let test of tests) {
+    let promise = new Promise(resolve => {
+      let uri = NetUtil.newURI(visited_page_url);
+      Services.obs.addObserver(function observe(aSubject) {
+        if (uri.equals(aSubject.QueryInterface(Ci.nsIURI))) {
+          Services.obs.removeObserver(observe, test.topic);
+          resolve();
+        }
+      }, test.topic, false);
+    });
+    ContentTask.spawn(test.win.gBrowser.selectedBrowser, prefix + test.subtest, function* (aSrc) {
+      content.document.getElementById("iframe").src = aSrc;
+    });
+    yield promise;
+
+    if (test.color) {
+      // In e10s waiting for visited-status-resolution is not enough to ensure links
+      // have been updated, because it only tells us that messages to update links
+      // have been dispatched. We must still wait for the actual links to update.
+      yield BrowserTestUtils.waitForCondition(function* () {
+        let color = yield ContentTask.spawn(test.win.gBrowser.selectedBrowser, null, function* () {
+          let iframe = content.document.getElementById("iframe");
+          let elem = iframe.contentDocument.getElementById("link");
+          return content.QueryInterface(Ci.nsIInterfaceRequestor)
+                        .getInterface(Ci.nsIDOMWindowUtils)
+                        .getVisitedDependentComputedStyle(elem, "", "color");
+        });
+        return (color == test.color);
+      }, test.message);
+      // The harness will consider the test as failed overall if there were no
+      // passes or failures, so record it as a pass.
+      ok(true, test.message);
+    }
+  }
+
+  yield BrowserTestUtils.closeWindow(normalWindow);
+  yield BrowserTestUtils.closeWindow(privateWindow);
+});
\ No newline at end of file
--- a/toolkit/components/places/tests/chrome.ini
+++ b/toolkit/components/places/tests/chrome.ini
@@ -1,2 +1,1 @@
 [test_bug_94514.html]
-[test_bug_461710_perwindowpb.html]
deleted file mode 100644
--- a/toolkit/components/places/tests/mochitest/bug_461710/.eslintrc
+++ /dev/null
@@ -1,5 +0,0 @@
-{
-  "extends": [
-    "../../../../../../testing/mochitest/mochitest.eslintrc"
-  ]
-}
--- a/toolkit/components/places/tests/moz.build
+++ b/toolkit/components/places/tests/moz.build
@@ -36,16 +36,21 @@ TEST_HARNESS_FILES.xpcshell.toolkit.comp
 
 TEST_HARNESS_FILES.testing.mochitest.tests.toolkit.components.places.tests.browser += [
     'browser/399606-history.go-0.html',
     'browser/399606-httprefresh.html',
     'browser/399606-location.reload.html',
     'browser/399606-location.replace.html',
     'browser/399606-window.location.href.html',
     'browser/399606-window.location.html',
+    'browser/461710_iframe.html',
+    'browser/461710_link_page-2.html',
+    'browser/461710_link_page-3.html',
+    'browser/461710_link_page.html',
+    'browser/461710_visited_page.html',
     'browser/begin.html',
     'browser/favicon-normal16.png',
     'browser/favicon-normal32.png',
     'browser/favicon.html',
     'browser/final.html',
     'browser/redirect-target.html',
     'browser/redirect.sjs',
     'browser/redirect_once.sjs',
@@ -62,16 +67,8 @@ TEST_HARNESS_FILES.testing.mochitest.tes
     'chrome/rss_as_html.rss^headers^',
     'chrome/sample_feed.atom',
 ]
 
 TEST_HARNESS_FILES.testing.mochitest.tests.toolkit.components.places.tests += [
     'bug94514-postpage.html',
 ]
 
-TEST_HARNESS_FILES.testing.mochitest.tests.toolkit.components.places.tests.mochitest.bug_461710 += [
-    'mochitest/bug_461710/iframe.html',
-    'mochitest/bug_461710/link_page-2.html',
-    'mochitest/bug_461710/link_page-3.html',
-    'mochitest/bug_461710/link_page.html',
-    'mochitest/bug_461710/visited_page.html',
-]
-
deleted file mode 100644
--- a/toolkit/components/places/tests/test_bug_461710_perwindowpb.html
+++ /dev/null
@@ -1,237 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=461710
--->
-<head>
-  <title>Test for Bug 461710</title>
-  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
-</head>
-<body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=461710">Mozilla Bug 461710</a>
-<p id="display"></p>
-<pre id="test">
-<script class="testbody" type="text/javascript">
-
-/** Test for Bug 461710 **/
-
-SimpleTest.waitForExplicitFinish();
-
-const Ci = SpecialPowers.Ci;
-const Cc = SpecialPowers.Cc;
-const Cr = SpecialPowers.Cr;
-
-SpecialPowers.Cu.import("resource://gre/modules/NetUtil.jsm", window);
-var Services = SpecialPowers.Services;
-
-var gIframe;
-
-/**
- * Helper function which waits until another function returns true, and
- * then notifies a callback.
- *
- * Original function stolen from docshell/test/chrome/docshell_helpers.js.
- *
- * Parameters:
- *
- *    fn: a function which is evaluated repeatedly, and when it turns true,
- *        the onWaitComplete callback is notified.
- *
- *    onWaitComplete:  a callback which will be notified when fn() returns
- *        true.
- */
-function waitForTrue(fn, onWaitComplete) {
-  var start = new Date().valueOf();
-
-  // Loop until the test function returns true, or until a timeout occurs,
-  // if a timeout is defined.
-  var intervalid =
-    setInterval(
-      function() {
-        if (fn.call()) {
-          // Stop calling the test function and notify the callback.
-          clearInterval(intervalid);
-          onWaitComplete.call();
-        }
-      }, 20);
-}
-
-const kRed = "rgb(255, 0, 0)";
-const kBlue = "rgb(0, 0, 255)";
-
-var testpath = "/tests/toolkit/components/places/tests/mochitest/bug_461710/";
-var prefix = "http://mochi.test:8888" + testpath;
-var subtests = [
-                   "visited_page.html",   // 1
-                   "link_page.html",      // 2
-                   "link_page-2.html",    // 3
-                   "link_page-3.html"     // 4
-               ];
-
-var testNum = 0;
-function loadNextTest() {
-  // run the initialization code for each test
-  switch (++testNum) {
-    case 1:
-      gIframe = normalWindowIframe;
-      break;
-
-    case 2:
-      break;
-
-    case 3:
-      gIframe = privateWindowIframe;
-      break;
-
-    case 4:
-      gIframe = normalWindowIframe;
-      break;
-
-    default:
-      ok(false, "Unexpected call to loadNextTest for test #" + testNum);
-  }
-
-  if (testNum == 1)
-    observer.expectURL(prefix + subtests[0], "uri-visit-saved");
-  else
-    observer.expectURL(prefix + subtests[0]);
-
-  waitForTrue(() => observer.resolved, function() {
-    // And the nodes get notified after the "link-visited" topic, so
-    // we need to execute soon...
-    SimpleTest.executeSoon(handleLoad);
-  });
-
-  gIframe.src = prefix + subtests[testNum-1];
-}
-
-function getColor(doc, win, id) {
-  var elem = doc.getElementById(id);
-  var utils = SpecialPowers.getDOMWindowUtils(win);
-  return utils.getVisitedDependentComputedStyle(elem, "", "color");
-}
-
-function checkTest() {
-  switch (testNum) {
-    case 1:
-      // nothing to do here, we just want to mark the page as visited
-      break;
-
-    case 2:
-      // run outside of private mode, link should appear as visited
-      var doc = gIframe.contentDocument;
-      var win = doc.defaultView;
-      is(getColor(doc, win, "link"), kRed, "Visited link coloring should work outside of private mode");
-      break;
-
-    case 3:
-      // run inside of private mode, link should appear as not visited
-      doc = gIframe.contentDocument;
-      win = doc.defaultView;
-      is(getColor(doc, win, "link"), kBlue, "Visited link coloring should not work inside of private mode");
-      break;
-
-    case 4:
-      // run outside of private mode, link should appear as visited
-      doc = gIframe.contentDocument;
-      win = doc.defaultView;
-      is(getColor(doc, win, "link"), kRed, "Visited link coloring should work outside of private mode");
-      break;
-
-    default:
-      ok(false, "Unexpected call to checkTest for test #" + testNum);
-  }
-}
-
-function handleLoad() {
-  checkTest();
-
-  if (testNum < subtests.length) {
-    loadNextTest();
-  } else {
-    normalWindow.close();
-    privateWindow.close();
-
-    SimpleTest.finish();
-  }
-}
-
-var contentPage = "http://mochi.test:8888/tests/toolkit/components/places/tests/mochitest/bug_461710/iframe.html";
-
-function whenDelayedStartupFinished(aWindow, aCallback) {
-  Services.obs.addObserver(function observer(aSubject, aTopic) {
-    if (aWindow == aSubject) {
-      Services.obs.removeObserver(observer, aTopic);
-    }
-
-    if (aWindow.content == null || aWindow.content.location.href != contentPage) {
-      aWindow.addEventListener("DOMContentLoaded", function onInnerLoad() {
-        aWindow.removeEventListener("DOMContentLoaded", onInnerLoad, true);
-        SimpleTest.executeSoon(function() { aCallback(aWindow); });
-      }, true);
-
-      aWindow.gBrowser.loadURI(contentPage);
-    }
-  }, "browser-delayed-startup-finished", false);
-}
-
-function testOnWindow(aIsPrivate, callback) {
-  var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
-                         .getInterface(Ci.nsIWebNavigation)
-                         .QueryInterface(Ci.nsIDocShellTreeItem)
-                         .rootTreeItem
-                         .QueryInterface(Ci.nsIInterfaceRequestor)
-                         .getInterface(Ci.nsIDOMWindow);
-  var win = mainWindow.OpenBrowserWindow({private: aIsPrivate});
-  whenDelayedStartupFinished(win, function() { callback(win); });
-}
-
-const URI_VISITED_RESOLUTION_TOPIC = "visited-status-resolution";
-var observer = {
-  uri: null,
-  resolved: true,
-  observe: function (aSubject, aTopic, aData) {
-
-    if (this.uri.equals(SpecialPowers.wrap(aSubject).QueryInterface(Ci.nsIURI))) {
-      this.resolved = true;
-
-      Services.obs.removeObserver(this, aTopic);
-    }
-  },
-  expectURL: function (url, aOverrideTopic) {
-    ok(this.resolved, "Can't set the expected URL when another is yet to be resolved");
-    this.resolved = false;
-
-    this.uri = SpecialPowers.wrap(NetUtil).newURI(url);
-    var topic = aOverrideTopic || URI_VISITED_RESOLUTION_TOPIC;
-    Services.obs.addObserver(this, topic, false);
-  }
-};
-
-var normalWindow;
-var privateWindow;
-
-var normalWindowIframe;
-var privateWindowIframe;
-
-testOnWindow(false, function(aWin) {
-  var selectedBrowser = aWin.gBrowser.selectedBrowser;
-
-   normalWindow = aWin;
-   normalWindowIframe = selectedBrowser.contentDocument.getElementById("iframe");
-
-  testOnWindow(true, function(aPrivateWin) {
-    selectedBrowser = aPrivateWin.gBrowser.selectedBrowser;
-
-    privateWindow = aPrivateWin;
-    privateWindowIframe = selectedBrowser.contentDocument.getElementById("iframe");
-
-    loadNextTest();
-  });
-});
-
-</script>
-</pre>
-</body>
-</html>