Bug 1259531 - [e10s] Fix test_bug451286.xul to run in e10s by converting to a mochitest-browser test. r=mikedeboer
authorJared Wein <jwein@mozilla.com>
Thu, 31 Mar 2016 20:41:00 -0400
changeset 291467 82a40128b81b1ec85c55933a0baa9e7f0b8e148b
parent 291466 7e4c0bee56f35104a4809121e8672f1e659258f5
child 291468 41d126344f3d794d7f81ea9f6d9ce50cabc4a3fa
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)
reviewersmikedeboer
bugs1259531, 451286
milestone48.0a1
Bug 1259531 - [e10s] Fix test_bug451286.xul to run in e10s by converting to a mochitest-browser test. r=mikedeboer MozReview-Commit-ID: 6Rt0dM6md06
testing/mochitest/tests/SimpleTest/WindowSnapshot.js
toolkit/content/tests/browser/browser.ini
toolkit/content/tests/browser/browser_bug451286.js
toolkit/content/tests/chrome/bug451286_window.xul
toolkit/content/tests/chrome/chrome.ini
toolkit/content/tests/chrome/test_bug451286.xul
toolkit/modules/RemoteFinder.jsm
--- a/testing/mochitest/tests/SimpleTest/WindowSnapshot.js
+++ b/testing/mochitest/tests/SimpleTest/WindowSnapshot.js
@@ -7,16 +7,20 @@ try {
 } catch (e) {
   gWindowUtils = null;
 }
 
 function snapshotWindow(win, withCaret) {
   return SpecialPowers.snapshotWindow(win, withCaret);
 }
 
+function snapshotRect(win, rect) {
+  return SpecialPowers.snapshotRect(win, rect);
+}
+
 // If the two snapshots don't compare as expected (true for equal, false for
 // unequal), returns their serializations as data URIs.  In all cases, returns
 // whether the comparison was as expected.
 function compareSnapshots(s1, s2, expectEqual, fuzz) {
   if (s1.width != s2.width || s1.height != s2.height) {
     ok(false, "Snapshot canvases are not the same size - comparing them makes no sense");
     return [false];
   }
--- a/toolkit/content/tests/browser/browser.ini
+++ b/toolkit/content/tests/browser/browser.ini
@@ -1,15 +1,16 @@
 [DEFAULT]
 support-files =
   head.js
   file_contentTitle.html
   audio.ogg
 [browser_autoscroll_disabled.js]
 [browser_bug295977_autoscroll_overflow.js]
+[browser_bug451286.js]
 [browser_bug594509.js]
 [browser_bug982298.js]
 [browser_bug1198465.js]
 [browser_contentTitle.js]
 [browser_default_image_filename.js]
 [browser_f7_caret_browsing.js]
 skip-if = e10s
 [browser_findbar.js]
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/browser/browser_bug451286.js
@@ -0,0 +1,136 @@
+Services.scriptloader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js", this);
+
+add_task(function*() {
+  const SEARCH_TEXT = "text";
+  const DATAURI = "data:text/html," + SEARCH_TEXT;
+
+  // Bug 451286. An iframe that should be highlighted
+  let visible = "<iframe id='visible' src='" + DATAURI + "'></iframe>";
+
+  // Bug 493658. An invisible iframe that shouldn't interfere with
+  // highlighting matches lying after it in the document
+  let invisible = "<iframe id='invisible' style='display: none;' " +
+                  "src='" + DATAURI + "'></iframe>";
+
+  let uri = DATAURI + invisible + SEARCH_TEXT + visible + SEARCH_TEXT;
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, uri);
+  let contentRect = tab.linkedBrowser.getBoundingClientRect();
+  let noHighlightSnapshot = snapshotRect(window, contentRect);
+  ok(noHighlightSnapshot, "Got noHighlightSnapshot");
+
+  yield openFindBarAndWait();
+  gFindBar._findField.value = SEARCH_TEXT;
+  var matchCase = gFindBar.getElement("find-case-sensitive");
+  if (matchCase.checked)
+    matchCase.doCommand();
+
+  // Turn on highlighting
+  yield toggleHighlightAndWait(true);
+  yield closeFindBarAndWait();
+
+  // Take snapshot of highlighting
+  let findSnapshot = snapshotRect(window, contentRect);
+  ok(findSnapshot, "Got findSnapshot");
+
+  // Now, remove the highlighting, and take a snapshot to compare
+  // to our original state
+  yield openFindBarAndWait();
+  yield toggleHighlightAndWait(false);
+  yield closeFindBarAndWait();
+
+  let unhighlightSnapshot = snapshotRect(window, contentRect);
+  ok(unhighlightSnapshot, "Got unhighlightSnapshot");
+
+  // Select the matches that should have been highlighted manually
+  yield ContentTask.spawn(tab.linkedBrowser, null, function*() {
+    let doc = content.document;
+    let win = doc.defaultView;
+
+    // Create a manual highlight in the visible iframe to test bug 451286
+    let iframe = doc.getElementById("visible");
+    let ifBody = iframe.contentDocument.body;
+    let range = iframe.contentDocument.createRange();
+    range.selectNodeContents(ifBody.childNodes[0]);
+    let ifWindow = iframe.contentWindow;
+    let ifDocShell = ifWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+                             .getInterface(Ci.nsIWebNavigation)
+                             .QueryInterface(Ci.nsIDocShell);
+
+    let ifController = ifDocShell.QueryInterface(Ci.nsIInterfaceRequestor)
+                                 .getInterface(Ci.nsISelectionDisplay)
+                                 .QueryInterface(Ci.nsISelectionController);
+
+    let frameFindSelection =
+      ifController.getSelection(ifController.SELECTION_FIND);
+    frameFindSelection.addRange(range);
+
+    // Create manual highlights in the main document (the matches that lie
+    // before/after the iframes
+    let docShell = win.QueryInterface(Ci.nsIInterfaceRequestor)
+                      .getInterface(Ci.nsIWebNavigation)
+                      .QueryInterface(Ci.nsIDocShell);
+
+    let controller = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+                             .getInterface(Ci.nsISelectionDisplay)
+                             .QueryInterface(Ci.nsISelectionController);
+
+    let docFindSelection =
+      controller.getSelection(ifController.SELECTION_FIND);
+
+    range = doc.createRange();
+    range.selectNodeContents(doc.body.childNodes[0]);
+    docFindSelection.addRange(range);
+    range = doc.createRange();
+    range.selectNodeContents(doc.body.childNodes[2]);
+    docFindSelection.addRange(range);
+    range = doc.createRange();
+    range.selectNodeContents(doc.body.childNodes[4]);
+    docFindSelection.addRange(range);
+  });
+
+  // Take snapshot of manual highlighting
+  let manualSnapshot = snapshotRect(window, contentRect);
+  ok(manualSnapshot, "Got manualSnapshot");
+
+  // Test 1: Were the matches in iframe correctly highlighted?
+  let res = compareSnapshots(findSnapshot, manualSnapshot, true);
+  ok(res[0], "Matches found in iframe correctly highlighted");
+
+  // Test 2: Were the matches in iframe correctly unhighlighted?
+  res = compareSnapshots(noHighlightSnapshot, unhighlightSnapshot, true);
+  ok(res[0], "Highlighting in iframe correctly removed");
+
+  yield BrowserTestUtils.removeTab(tab);
+});
+
+function toggleHighlightAndWait(shouldHighlight) {
+  return new Promise((resolve) => {
+    let listener = {
+      onFindResult() {},
+      onHighlightFinished() {
+        gFindBar.browser.finder.removeResultListener(listener);
+        resolve();
+      },
+      onMatchesCountResult() {}
+    };
+    gFindBar.browser.finder.addResultListener(listener);
+    gFindBar.toggleHighlight(shouldHighlight);
+  });
+}
+
+function* openFindBarAndWait() {
+  let awaitTransitionEnd = BrowserTestUtils.waitForEvent(gFindBar, "transitionend");
+  gFindBar.open();
+  yield awaitTransitionEnd;
+}
+
+// This test is comparing snapshots. It is necessary to wait for the gFindBar
+// to close before taking the snapshot so the gFindBar does not take up space
+// on the new snapshot.
+function* closeFindBarAndWait() {
+  let awaitTransitionEnd = BrowserTestUtils.waitForEvent(gFindBar, "transitionend", false, event => {
+    return event.propertyName == "visibility";
+  });
+  gFindBar.close();
+  yield awaitTransitionEnd;
+}
deleted file mode 100644
--- a/toolkit/content/tests/chrome/bug451286_window.xul
+++ /dev/null
@@ -1,193 +0,0 @@
-<?xml version="1.0"?>
-
-<!-- This Source Code Form is subject to the terms of the Mozilla Public
-   - License, v. 2.0. If a copy of the MPL was not distributed with this
-   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
-
-<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
-
-<window id="451286test"
-        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-        width="600"
-        height="600"
-        onload="SimpleTest.executeSoon(startTest);"
-        title="451286 test (also tests bug 493658)">
-
-  <script type="application/javascript"><![CDATA[
-    const Ci = Components.interfaces;
-    const Cc = Components.classes;
-    const Cr = Components.results;
-    const SEARCH_TEXT = "text";
-    const DATAURI = "data:text/html," + SEARCH_TEXT;
-
-    let {Task} = Components.utils.import("resource://gre/modules/Task.jsm", {});
-
-    var gFindBar = null;
-    var gBrowser;
-    var gWin;
-
-    var noHighlightSnapshot;
-    var findSnapshot;
-
-    var imports = ["SimpleTest", "ok", "snapshotWindow", "compareSnapshots",
-                   "parentFinish"];
-    for (var name of imports) {
-      window[name] = window.opener.wrappedJSObject[name];
-    }
-
-    function finish() {
-      window.close();
-      parentFinish();
-    }
-
-    function startTest() {
-      gFindBar = document.getElementById("FindToolbar");
-      gBrowser = document.getElementById("content");
-      gBrowser.addEventListener("pageshow", onPageShow, false);
-
-      // Bug 451286. An iframe that should be highlighted
-      var visible = "<iframe id='visible' src='" + DATAURI + "'></iframe>";
-
-      // Bug 493658. An invisible iframe that shouldn't interfere with
-      // highlighting matches lying after it in the document
-      var invisible = "<iframe id='invisible' style='display: none;' " +
-                      "src='" + DATAURI + "'></iframe>";
-
-      var uri = DATAURI + invisible + SEARCH_TEXT + visible + SEARCH_TEXT;
-      gBrowser.loadURI(uri);
-    }
-
-    // This test is comparing snapshots. It is necessary to wait for the findbar
-    // to close before taking the snapshot so the findbar does not take up space
-    // on the new snapshot.
-    function closeFindbarAndWait() {
-      return new Promise((resolve) => {
-        gFindBar.addEventListener("transitionend", function cont(aEvent) {
-          if (aEvent.propertyName != "visibility") {
-            return;
-          }
-          gFindBar.removeEventListener("transitionend", cont);
-          resolve();
-        });
-        gFindBar.close();
-      });
-    }
-
-    function toggleHighlightAndWait(aHighlight) {
-      return new Promise((resolve) => {
-        let listener = {
-          onHighlightFinished: function() {
-            gFindBar.browser.finder.removeResultListener(listener);
-            resolve();
-          }
-        };
-        gFindBar.browser.finder.addResultListener(listener);
-        gFindBar.toggleHighlight(aHighlight);
-      });
-    }
-
-    let onPageShow = Task.async(function* (aEvent) {
-      // Don't respond to pageshow events coming from the <iframes>
-      if (aEvent.target != gBrowser.contentDocument)
-        return;
-
-      gBrowser.removeEventListener("pageshow", onPageShow, false);
-
-      // First, take a snapshot of the window without highlighting
-      // to be used later to test the unhighlighting case
-      gWin = gBrowser.contentWindow;
-      noHighlightSnapshot = snapshotWindow(gWin);
-
-      yield part1();
-      yield part2();
-      yield part3();
-
-      finish();
-    });
-
-    let part1 = Task.async(function* () {
-      gFindBar.open();
-      gFindBar._findField.value = SEARCH_TEXT;
-      var matchCase = gFindBar.getElement("find-case-sensitive");
-      if (matchCase.checked)
-        matchCase.doCommand();
-
-      // Turn on highlighting
-      yield toggleHighlightAndWait(true);
-      yield closeFindbarAndWait();
-    });
-
-    let part2 = Task.async(function* () {
-      // Take snapshot of highlighting
-      findSnapshot = snapshotWindow(gWin);
-
-      // Now, remove the highlighting, and take a snapshot to compare
-      // to our original state
-      gFindBar.open();
-      yield toggleHighlightAndWait(false);
-      yield closeFindbarAndWait();
-    });
-
-    let part3 = Task.async(function* () {
-      var unhighlightSnapshot = snapshotWindow(gWin);
-
-      // Select the matches that should have been highlighted manually
-      var doc = gBrowser.contentDocument;
-
-      // Create a manual highlight in the visible iframe to test bug 451286
-      var iframe = doc.getElementById("visible");
-      var ifBody = iframe.contentDocument.body;
-      var range = iframe.contentDocument.createRange();
-      range.selectNodeContents(ifBody.childNodes[0]);
-      var ifWindow = iframe.contentWindow;
-      var ifDocShell = ifWindow.QueryInterface(Ci.nsIInterfaceRequestor)
-                               .getInterface(Ci.nsIWebNavigation)
-                               .QueryInterface(Ci.nsIDocShell);
-
-      var ifController = ifDocShell.QueryInterface(Ci.nsIInterfaceRequestor)
-                                   .getInterface(Ci.nsISelectionDisplay)
-                                   .QueryInterface(Ci.nsISelectionController);
-
-      var frameFindSelection =
-        ifController.getSelection(ifController.SELECTION_FIND);
-      frameFindSelection.addRange(range);
-
-      // Create manual highlights in the main document (the matches that lie
-      // before/after the iframes
-      var docShell = gWin.QueryInterface(Ci.nsIInterfaceRequestor)
-                         .getInterface(Ci.nsIWebNavigation)
-                          .QueryInterface(Ci.nsIDocShell);
-
-      var controller = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
-                               .getInterface(Ci.nsISelectionDisplay)
-                               .QueryInterface(Ci.nsISelectionController);
-
-      var docFindSelection =
-        controller.getSelection(ifController.SELECTION_FIND);
-
-      range = doc.createRange();
-      range.selectNodeContents(doc.body.childNodes[0]);
-      docFindSelection.addRange(range);
-      range = doc.createRange();
-      range.selectNodeContents(doc.body.childNodes[2]);
-      docFindSelection.addRange(range);
-      range = doc.createRange();
-      range.selectNodeContents(doc.body.childNodes[4]);
-      docFindSelection.addRange(range);
-
-      // Take snapshot of manual highlighting
-      var manualSnapshot = snapshotWindow(gBrowser.contentWindow);
-
-      // Test 1: Were the matches in iframe correctly highlighted?
-      var res = compareSnapshots(findSnapshot, manualSnapshot, true);
-      ok(res[0], "Matches found in iframe correctly highlighted");
-
-      // Test 2: Were the matches in iframe correctly unhighlighted?
-      res = compareSnapshots(noHighlightSnapshot, unhighlightSnapshot, true);
-      ok(res[0], "Highlighting in iframe correctly removed");
-    });
-  ]]></script>
-
-  <browser type="content-primary" flex="1" id="content" src="about:blank"/>
-  <findbar id="FindToolbar" browserid="content"/>
-</window>
--- a/toolkit/content/tests/chrome/chrome.ini
+++ b/toolkit/content/tests/chrome/chrome.ini
@@ -6,17 +6,16 @@ support-files =
   RegisterUnregisterChrome.js
   bug263683_window.xul
   bug304188_window.xul
   bug331215_window.xul
   bug360437_window.xul
   bug366992_window.xul
   bug409624_window.xul
   bug429723_window.xul
-  bug451286_window.xul
   bug624329_window.xul
   dialog_dialogfocus.xul
   file_about_networking_wsh.py
   file_autocomplete_with_composition.js
   findbar_events_window.xul
   findbar_window.xul
   frame_popup_anchor.xul
   frame_popupremoving_frame.xul
@@ -71,17 +70,16 @@ skip-if = buildapp == 'mulet'
 [test_bug360437.xul]
 [test_bug365773.xul]
 [test_bug366992.xul]
 [test_bug382990.xul]
 [test_bug409624.xul]
 [test_bug418874.xul]
 [test_bug429723.xul]
 [test_bug437844.xul]
-[test_bug451286.xul]
 [test_bug457632.xul]
 [test_bug460942.xul]
 [test_bug471776.xul]
 [test_bug509732.xul]
 [test_bug554279.xul]
 [test_bug557987.xul]
 [test_bug562554.xul]
 [test_bug570192.xul]
deleted file mode 100644
--- a/toolkit/content/tests/chrome/test_bug451286.xul
+++ /dev/null
@@ -1,56 +0,0 @@
-<?xml version="1.0"?>
-<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
-<?xml-stylesheet 
-  href="chrome://mochikit/content/tests/SimpleTest/test.css"
-  type="text/css"?>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=451286
--->
-<window title="Mozilla Bug 451286"
-  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
-
-  <script type="application/javascript" 
-          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="application/javascript" 
-          src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script>
-
-  <body  xmlns="http://www.w3.org/1999/xhtml">
-    <a target="_blank" 
-       href="https://bugzilla.mozilla.org/show_bug.cgi?id=451286">
-      Mozilla Bug 451286
-    </a>
-
-    <p id="display"></p>
-    <div id="content" style="display: none">
-    </div>
-    <pre id="test">
-    </pre>
-  </body>
-
-  <script class="testbody" type="application/javascript">
-    <![CDATA[
-
-      // To be called by the window we open.
-      function parentFinish() {
-        // This is called with JS code from the window we open on the
-        // stack.  We need to GC everything in that window, so do that
-        // from a timeout and then call SimpleTest.finish().
-        setTimeout(doFinish, 0);
-      }
-
-      function doFinish() {
-        // Garbage collect objects created in this test can cause
-        // assertions, so GC now to blame those assertions to this test.
-        SpecialPowers.gc();
-        SimpleTest.finish();
-      }
-
-      /** Test for Bug 451286 **/
-      SimpleTest.waitForExplicitFinish();
-      window.open("bug451286_window.xul", "451286test", 
-                  "chrome,width=600,height=600");
-
-    ]]>
-  </script>
-
-</window>
--- a/toolkit/modules/RemoteFinder.jsm
+++ b/toolkit/modules/RemoteFinder.jsm
@@ -84,18 +84,20 @@ RemoteFinder.prototype = {
         params = [ aMessage.data ];
         break;
     }
 
     for (let l of this._listeners) {
       // Don't let one callback throwing stop us calling the rest
       try {
         l[callback].apply(l, params);
-      }
-      catch (e) {
+      } catch (e) {
+        if (!l[callback]) {
+          Cu.reportError(`Missing ${callback} callback on RemoteFinderListener`);
+        }
         Cu.reportError(e);
       }
     }
   },
 
   get searchString() {
     return this._searchString;
   },