Bug 1093566 - Migrate BrowserUITestUtils into BrowserTestUtils; r=Unfocused r=paolo
authorSteven MacLeod <smacleod@mozilla.com>
Mon, 23 Feb 2015 12:48:54 -0500
changeset 231328 be473722fb842a5de1e66fdcd376736df4aff7c9
parent 231327 ec936c510299f0c50b3bd33f18461827ece4b43d
child 231329 fad92c7e2f57587aa0d04790f515741b3279d11f
push id28349
push userkwierso@gmail.com
push dateMon, 02 Mar 2015 20:41:54 +0000
treeherdermozilla-central@eaaa45f32e9a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersUnfocused, paolo
bugs1093566
milestone39.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 1093566 - Migrate BrowserUITestUtils into BrowserTestUtils; r=Unfocused r=paolo
browser/base/content/test/BrowserUITestUtils.jsm
browser/base/moz.build
browser/components/readinglist/test/browser/browser_sidebar_mouse_nav.js
browser/components/readinglist/test/browser/head.js
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
deleted file mode 100644
--- a/browser/base/content/test/BrowserUITestUtils.jsm
+++ /dev/null
@@ -1,70 +0,0 @@
-"use strict";
-
-this.EXPORTED_SYMBOLS = [
-  "BrowserUITestUtils",
-];
-
-const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
-
-Cu.import("resource://gre/modules/Timer.jsm");
-
-
-/**
- * Default wait period in millseconds, when waiting for the expected event to occur.
- * @type {number}
- */
-const DEFAULT_WAIT = 2000;
-
-
-/**
- * Test utility functions for dealing with the browser UI DOM.
- */
-this.BrowserUITestUtils = {
-
-  /**
-   * Waits a specified number of miliseconds for a specified event to be
-   * fired on a specified element.
-   *
-   * Usage:
-   *    let receivedEvent = BrowserUITestUtils.waitForEvent(element, "eventName");
-   *    // Do some processing here that will cause the event to be fired
-   *    // ...
-   *    // Now yield until the Promise is fulfilled
-   *    yield receivedEvent;
-   *    if (receivedEvent && !(receivedEvent instanceof Error)) {
-   *      receivedEvent.msg == "eventName";
-   *      // ...
-   *    }
-   *
-   * @param {Element} subject - The element that should receive the event.
-   * @param {string} eventName - The event to wait for.
-   * @param {number} timeoutMs - The number of miliseconds to wait before giving up.
-   * @param {Element} target - Expected target of the event.
-   * @returns {Promise} A Promise that resolves to the received event, or
-   *                    rejects with an Error.
-   */
-  waitForEvent(subject, eventName, timeoutMs, target) {
-    return new Promise((resolve, reject) => {
-      function listener(event) {
-        if (target && target !== event.target) {
-          return;
-        }
-
-        subject.removeEventListener(eventName, listener);
-        clearTimeout(timerID);
-        resolve(event);
-      }
-
-      timeoutMs = timeoutMs || DEFAULT_WAIT;
-      let stack = new Error().stack;
-
-      let timerID = setTimeout(() => {
-        subject.removeEventListener(eventName, listener);
-        reject(new Error(`${eventName} event timeout at ${stack}`));
-      }, timeoutMs);
-
-
-      subject.addEventListener(eventName, listener);
-    });
-  },
-};
--- a/browser/base/moz.build
+++ b/browser/base/moz.build
@@ -1,20 +1,16 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
 SPHINX_TREES['sslerrorreport'] = 'content/docs/sslerrorreport'
 
-TESTING_JS_MODULES += [
-    'content/test/BrowserUITestUtils.jsm',
-]
-
 MOCHITEST_MANIFESTS += [
     'content/test/general/mochitest.ini',
 ]
 
 MOCHITEST_CHROME_MANIFESTS += [
     'content/test/chrome/chrome.ini',
 ]
 
--- a/browser/components/readinglist/test/browser/browser_sidebar_mouse_nav.js
+++ b/browser/components/readinglist/test/browser/browser_sidebar_mouse_nav.js
@@ -1,15 +1,15 @@
 /**
  * Test mouse navigation for selecting items in the sidebar.
  */
 
 
 function mouseInteraction(mouseEvent, responseEvent, itemNode) {
-  let eventPromise = BrowserUITestUtils.waitForEvent(RLSidebarUtils.list, responseEvent);
+  let eventPromise = BrowserTestUtils.waitForEvent(RLSidebarUtils.list, responseEvent);
   let details = {};
   if (mouseEvent != "click") {
     details.type = mouseEvent;
   }
 
   EventUtils.synthesizeMouseAtCenter(itemNode, details, itemNode.ownerDocument.defaultView);
   return eventPromise;
 }
--- a/browser/components/readinglist/test/browser/head.js
+++ b/browser/components/readinglist/test/browser/head.js
@@ -1,14 +1,12 @@
 XPCOMUtils.defineLazyModuleGetter(this, "ReadingList",
                                   "resource:///modules/readinglist/ReadingList.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "ReadingListTestUtils",
                                   "resource://testing-common/ReadingListTestUtils.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "BrowserUITestUtils",
-                                  "resource://testing-common/BrowserUITestUtils.jsm");
 
 
 XPCOMUtils.defineLazyGetter(this, "RLUtils", () => {
   return ReadingListTestUtils;
 });
 
 XPCOMUtils.defineLazyGetter(this, "RLSidebarUtils", () => {
   return new RLUtils.SidebarUtils(window, Assert);
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -14,24 +14,33 @@
 this.EXPORTED_SYMBOLS = [
   "BrowserTestUtils",
 ];
 
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/Timer.jsm");
 Cu.import("resource://testing-common/TestUtils.jsm");
 
 Cc["@mozilla.org/globalmessagemanager;1"]
   .getService(Ci.nsIMessageListenerManager)
   .loadFrameScript(
     "chrome://mochikit/content/tests/BrowserTestUtils/content-utils.js", true);
 
 
+/**
+ * Default wait period in millseconds, when waiting for the expected
+ * event to occur.
+ * @type {number}
+ */
+const DEFAULT_WAIT = 2000;
+
+
 this.BrowserTestUtils = {
   /**
    * @param {xul:browser} browser
    *        A xul:browser.
    * @param {Boolean} includeSubFrames
    *        A boolean indicating if loads from subframes should be included.
    * @return {Promise}
    *         A Promise which resolves when a load event is triggered
@@ -76,9 +85,56 @@ this.BrowserTestUtils = {
 
       // Wait for browser-delayed-startup-finished notification, it indicates
       // that the window has loaded completely and is ready to be used for
       // testing.
       TestUtils.topicObserved("browser-delayed-startup-finished", win).then(
         () => resolve(win));
     });
   },
+
+  /**
+   * Waits a specified number of miliseconds for a specified event to be
+   * fired on a specified element.
+   *
+   * Usage:
+   *    let receivedEvent = BrowserTestUtil.waitForEvent(element, "eventName");
+   *    // Do some processing here that will cause the event to be fired
+   *    // ...
+   *    // Now yield until the Promise is fulfilled
+   *    yield receivedEvent;
+   *    if (receivedEvent && !(receivedEvent instanceof Error)) {
+   *      receivedEvent.msg == "eventName";
+   *      // ...
+   *    }
+   *
+   * @param {Element} subject - The element that should receive the event.
+   * @param {string} eventName - The event to wait for.
+   * @param {number} timeoutMs - The number of miliseconds to wait before giving up.
+   * @param {Element} target - Expected target of the event.
+   * @returns {Promise} A Promise that resolves to the received event, or
+   *                    rejects with an Error.
+   */
+  waitForEvent(subject, eventName, timeoutMs, target) {
+    return new Promise((resolve, reject) => {
+      function listener(event) {
+        if (target && target !== event.target) {
+          return;
+        }
+
+        subject.removeEventListener(eventName, listener);
+        clearTimeout(timerID);
+        resolve(event);
+      }
+
+      timeoutMs = timeoutMs || DEFAULT_WAIT;
+      let stack = new Error().stack;
+
+      let timerID = setTimeout(() => {
+        subject.removeEventListener(eventName, listener);
+        reject(new Error(`${eventName} event timeout at ${stack}`));
+      }, timeoutMs);
+
+
+      subject.addEventListener(eventName, listener);
+    });
+  },
 };