Bug 1253233: refactor bug263683_window.xul to run the test on remote browsers as well. r=felipe
authorMike de Boer <mdeboer@mozilla.com>
Fri, 25 Mar 2016 15:26:14 +0100
changeset 290365 fe2112d79fc1178e0b34f7674e61309f7de082ab
parent 290364 d823452bea13282527bce173c1133f2f12990d7f
child 290366 912ee4b6a03385ac8e5bd80f06cbb57cc9b594c1
push id30119
push userryanvm@gmail.com
push dateSat, 26 Mar 2016 02:03:32 +0000
treeherdermozilla-central@d4ccb3062261 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe
bugs1253233
milestone48.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 1253233: refactor bug263683_window.xul to run the test on remote browsers as well. r=felipe
toolkit/content/tests/chrome/bug263683_window.xul
toolkit/modules/RemoteFinder.jsm
--- a/toolkit/content/tests/chrome/bug263683_window.xul
+++ b/toolkit/content/tests/chrome/bug263683_window.xul
@@ -1,83 +1,149 @@
 <?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"?>
+<?xml-stylesheet
+  href="chrome://mochikit/content/tests/SimpleTest/test.css"
+  type="text/css"?>
 
 <window id="263683test"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         width="600"
         height="600"
         onload="SimpleTest.executeSoon(startTest);"
         title="263683 test">
 
   <script type="application/javascript"><![CDATA[
-    const Ci = Components.interfaces;
-    const Cc = Components.classes;
-    const Cr = Components.results;
+    const {interfaces: Ci, classes: Cc, results: Cr, utils: Cu} = Components;
+    Cu.import("resource://gre/modules/AppConstants.jsm");
+    Cu.import("resource://gre/modules/Task.jsm");
+    Cu.import("resource://testing-common/ContentTask.jsm");
+    ContentTask.setTestScope(window.opener.wrappedJSObject);
 
     var gFindBar = null;
     var gBrowser;
 
-    var imports = ["SimpleTest", "ok"];
+    var imports = ["SimpleTest", "ok", "info"];
     for (var name of imports) {
       window[name] = window.opener.wrappedJSObject[name];
     }
 
-    function finish() {
-      window.close();
-      SimpleTest.finish();
+    function startTest() {
+      Task.spawn(function* () {
+        gFindBar = document.getElementById("FindToolbar");
+        for (let browserId of ["content", "content-remote"]) {
+          yield startTestWithBrowser(browserId);
+        }
+      }).then(() => {
+        window.close();
+        SimpleTest.finish();
+      });
     }
 
-    function startTest() {
-      gFindBar = document.getElementById("FindToolbar");
-      gBrowser = document.getElementById("content");
-      gBrowser.addEventListener("pageshow", onPageShow, false);
+    function* startTestWithBrowser(browserId) {
+      // We're bailing out when testing a remote browser on OSX 10.6, because it
+      // fails permanently.
+      if (browserId.endsWith("remote") && AppConstants.isPlatformAndVersionAtMost("macosx", 11)) {
+        return;
+      }
+
+      info("Starting test with browser '" + browserId + "'");
+      gBrowser = document.getElementById(browserId);
+      gFindBar.browser = gBrowser;
+      let promise = ContentTask.spawn(gBrowser, null, function* () {
+        return new Promise(resolve => {
+          addEventListener("DOMContentLoaded", function listener() {
+            removeEventListener("DOMContentLoaded", listener);
+            resolve();
+          });
+        });
+      });
       gBrowser.loadURI('data:text/html,<h2>Text mozilla</h2><input id="inp" type="text" />');
+      yield promise;
+      yield onDocumentLoaded();
     }
 
-    function onPageShow() {
+    function toggleHighlightAndWait(highlight) {
+      return new Promise(resolve => {
+        let listener = {
+          onHighlightFinished: function() {
+            gFindBar.browser.finder.removeResultListener(listener);
+            resolve();
+          }
+        };
+        gFindBar.browser.finder.addResultListener(listener);
+        gFindBar.toggleHighlight(highlight);
+      });
+    }
+
+    function* onDocumentLoaded() {
       gFindBar.open();
       var search = "mozilla";
       gFindBar._findField.value = search;
       var matchCase = gFindBar.getElement("find-case-sensitive");
       if (matchCase.checked)
         matchCase.doCommand();
 
       gFindBar._find();
-      var highlightButton = gFindBar.getElement("highlight");
-      if (!highlightButton.checked)
-        highlightButton.click();
+      yield toggleHighlightAndWait(true);
+
+      yield ContentTask.spawn(gBrowser, { search }, function* (args) {
+        let controller = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+                                 .getInterface(Ci.nsISelectionDisplay)
+                                 .QueryInterface(Ci.nsISelectionController);
+        Assert.ok("SELECTION_FIND" in controller, "Correctly detects new selection type");
+        let selection = controller.getSelection(controller.SELECTION_FIND);
+        
+        Assert.equal(selection.rangeCount, 1,
+          "Correctly added a match to the selection type");
+        Assert.equal(selection.getRangeAt(0).toString().toLowerCase(),
+          args.search, "Added the correct match");
+      });
+
+      yield toggleHighlightAndWait(false);
+
+      yield ContentTask.spawn(gBrowser, { search }, function* (args) {
+        let controller = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+                                 .getInterface(Ci.nsISelectionDisplay)
+                                 .QueryInterface(Ci.nsISelectionController);
+        let selection = controller.getSelection(controller.SELECTION_FIND);
+        Assert.equal(selection.rangeCount, 0, "Correctly removed the range");
 
-      var controller = gFindBar.browser.docShell.QueryInterface(Ci.nsIInterfaceRequestor)
-                                       .getInterface(Ci.nsISelectionDisplay)
-                                       .QueryInterface(Ci.nsISelectionController);
-      ok('SELECTION_FIND' in controller, "Correctly detects new selection type");
-      var selection = controller.getSelection(controller.SELECTION_FIND);
-      
-      ok(selection.rangeCount == 1, "Correctly added a match to the selection type");
-      ok(selection.getRangeAt(0).toString().toLowerCase() == search, "Added the correct match");
-      highlightButton.click();
-      ok(selection.rangeCount == 0, "Correctly removed the range");
+        let input = content.document.getElementById("inp");
+        input.value = args.search;
+      });
+ 
+      yield toggleHighlightAndWait(true);
+
+      yield ContentTask.spawn(gBrowser, { search }, function* (args) {
+        let input = content.document.getElementById("inp");
+        let inputController = input.editor.selectionController;
+        let inputSelection = inputController.getSelection(inputController.SELECTION_FIND);
 
-      var input = gBrowser.contentDocument.getElementById("inp");
-      input.value = search;
- 
-      highlightButton.click();
+        Assert.equal(inputSelection.rangeCount, 1,
+          "Correctly added a match from input to the selection type");
+        Assert.equal(inputSelection.getRangeAt(0).toString().toLowerCase(),
+          args.search, "Added the correct match");
+      });
+
+      yield toggleHighlightAndWait(false);
 
-      var inputController = input.editor.selectionController;
-      var inputSelection = inputController.getSelection(inputController.SELECTION_FIND);
+      yield ContentTask.spawn(gBrowser, null, function* () {
+        let input = content.document.getElementById("inp");
+        let inputController = input.editor.selectionController;
+        let inputSelection = inputController.getSelection(inputController.SELECTION_FIND);
 
-      ok(inputSelection.rangeCount == 1, "Correctly added a match from input to the selection type");
-      ok(inputSelection.getRangeAt(0).toString().toLowerCase() == search, "Added the correct match");
-      highlightButton.click();
-      ok(inputSelection.rangeCount == 0, "Correctly removed the range");
-      finish();
+        Assert.equal(inputSelection.rangeCount, 0, "Correctly removed the range");
+      });
+
+      gFindBar.close();
     }
   ]]></script>
 
   <browser type="content-primary" flex="1" id="content" src="about:blank"/>
+  <browser type="content-primary" flex="1" id="content-remote" remote="true" src="about:blank"/>
   <findbar id="FindToolbar" browserid="content"/>
 </window>
--- a/toolkit/modules/RemoteFinder.jsm
+++ b/toolkit/modules/RemoteFinder.jsm
@@ -24,26 +24,28 @@ function RemoteFinder(browser) {
 }
 
 RemoteFinder.prototype = {
   swapBrowser: function(aBrowser) {
     if (this._messageManager) {
       this._messageManager.removeMessageListener("Finder:Result", this);
       this._messageManager.removeMessageListener("Finder:MatchesResult", this);
       this._messageManager.removeMessageListener("Finder:CurrentSelectionResult",this);
+      this._messageManager.removeMessageListener("Finder:HighlightFinished",this);
     }
     else {
       aBrowser.messageManager.sendAsyncMessage("Finder:Initialize");
     }
 
     this._browser = aBrowser;
     this._messageManager = this._browser.messageManager;
     this._messageManager.addMessageListener("Finder:Result", this);
     this._messageManager.addMessageListener("Finder:MatchesResult", this);
     this._messageManager.addMessageListener("Finder:CurrentSelectionResult", this);
+    this._messageManager.addMessageListener("Finder:HighlightFinished", this);
 
     // Ideally listeners would have removed themselves but that doesn't happen
     // right now
     this._listeners.clear();
   },
 
   addResultListener: function (aListener) {
     this._listeners.add(aListener);
@@ -66,16 +68,20 @@ RemoteFinder.prototype = {
       case "Finder:MatchesResult":
         callback = "onMatchesCountResult";
         params = [ aMessage.data ];
         break;
       case "Finder:CurrentSelectionResult":
         callback = "onCurrentSelection";
         params = [ aMessage.data.selection, aMessage.data.initial ];
         break;
+      case "Finder:HighlightFinished":
+        callback = "onHighlightFinished";
+        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) {
@@ -197,16 +203,20 @@ RemoteFinderListener.prototype = {
   },
 
   // When the child receives messages with results of requestMatchesCount,
   // it passes them forward to the parent.
   onMatchesCountResult: function (aData) {
     this._global.sendAsyncMessage("Finder:MatchesResult", aData);
   },
 
+  onHighlightFinished: function(aData) {
+    this._global.sendAsyncMessage("Finder:HighlightFinished", aData);
+  },
+
   receiveMessage: function (aMessage) {
     let data = aMessage.data;
 
     switch (aMessage.name) {
       case "Finder:CaseSensitive":
         this._finder.caseSensitive = data.caseSensitive;
         break;