Bug 1253233 - Refactor bug331215_window.xul to run the test on remote browsers as well. r=felipe
☠☠ backed out by 7a3f8d12197f ☠ ☠
authorMike de Boer <mdeboer@mozilla.com>
Fri, 11 Mar 2016 19:27:25 +0100
changeset 289928 a498165cef0c84eab1741d398b884a9bbce2a7bb
parent 289927 0b9ba3cfe5cef263aa552d32f678387eeeeaabd6
child 289929 2aad094c7cf871adac1f83e17169e9cb338e32b4
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)
reviewersfelipe
bugs1253233
milestone48.0a1
Bug 1253233 - Refactor bug331215_window.xul to run the test on remote browsers as well. r=felipe
toolkit/content/tests/chrome/bug331215_window.xul
--- a/toolkit/content/tests/chrome/bug331215_window.xul
+++ b/toolkit/content/tests/chrome/bug331215_window.xul
@@ -1,73 +1,104 @@
 <?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="331215test"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         width="600"
         height="600"
         onload="SimpleTest.executeSoon(startTest);"
         title="331215 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/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) {
+      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/plain,latest");
+      yield promise;
+      yield onDocumentLoaded();
     }
 
-    function onPageShow() {
+    function* onDocumentLoaded() {
       document.getElementById("cmd_find").doCommand();
-      enterStringIntoFindField("test");
+      yield enterStringIntoFindField("test");
       document.commandDispatcher
               .getControllerForCommand("cmd_moveTop")
               .doCommand("cmd_moveTop");
-      enterStringIntoFindField("l");
+      yield enterStringIntoFindField("l");
       ok(gFindBar._findField.getAttribute("status") == "notfound",
          "Findfield status attribute should have been 'notfound'" +
          " after entering ltest");              
-      enterStringIntoFindField("a");
+      yield enterStringIntoFindField("a");
       ok(gFindBar._findField.getAttribute("status") != "notfound",
          "Findfield status attribute should not have been 'notfound'" +
          " after entering latest");
-      finish();
     }
 
-    function enterStringIntoFindField(aString) {
-      for (var i=0; i < aString.length; i++) {
-        var event = document.createEvent("KeyEvents");
+    function* enterStringIntoFindField(aString) {
+      for (let i = 0; i < aString.length; i++) {      
+        let event = document.createEvent("KeyEvents");
+        let promise = new Promise(resolve => {
+          let listener = {
+            onFindResult: function() {
+              gFindBar.browser.finder.removeResultListener(listener);
+              resolve();
+            }
+          };
+          gFindBar.browser.finder.addResultListener(listener);
+        });
         event.initKeyEvent("keypress", true, true, null, false, false,
                            false, false, 0, aString.charCodeAt(i));
         gFindBar._findField.inputField.dispatchEvent(event);
+        yield promise;
       }
     }
   ]]></script>
 
   <commandset>
     <command id="cmd_find" oncommand="document.getElementById('FindToolbar').onFindCommand();"/>
   </commandset>
   <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>