Bug 1267328: Re-enable the background script alert tests. r=trivial
authorKris Maglione <maglione.k@gmail.com>
Sat, 04 Jun 2016 21:21:09 -0700
changeset 339403 0ac19ca034d9097ded455362e46b56017f3a64a4
parent 339402 10e00a4afa507911c110ca779a0769922f9e9ea8
child 339404 f42a04d822baa22a4741c4fff1aab2054857e398
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstrivial
bugs1267328
milestone49.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 1267328: Re-enable the background script alert tests. r=trivial MozReview-Commit-ID: 4YScHAmRaMf
toolkit/components/extensions/test/mochitest/chrome.ini
toolkit/components/extensions/test/mochitest/test_chrome_ext_background_page.html
--- a/toolkit/components/extensions/test/mochitest/chrome.ini
+++ b/toolkit/components/extensions/test/mochitest/chrome.ini
@@ -3,17 +3,17 @@ support-files =
   file_download.html
   file_download.txt
   interruptible.sjs
   file_sample.html
 
 [test_chrome_ext_background_debug_global.html]
 skip-if = (os == 'android') # android doesn't have devtools
 [test_chrome_ext_background_page.html]
-skip-if = true # bug 1267328; was (toolkit == 'android') # android doesn't have devtools
+skip-if = (toolkit == 'android') # android doesn't have devtools
 [test_chrome_ext_downloads_download.html]
 [test_chrome_ext_downloads_misc.html]
 [test_chrome_ext_downloads_search.html]
 [test_chrome_ext_eventpage_warning.html]
 [test_chrome_ext_contentscript_unrecognizedprop_warning.html]
 skip-if = (os == 'android') # browser.tabs is undefined. Bug 1258975 on android.
 [test_chrome_ext_webnavigation_resolved_urls.html]
 skip-if = (os == 'android') # browser.tabs is undefined. Bug 1258975 on android.
--- a/toolkit/components/extensions/test/mochitest/test_chrome_ext_background_page.html
+++ b/toolkit/components/extensions/test/mochitest/test_chrome_ext_background_page.html
@@ -8,66 +8,74 @@
   <script type="text/javascript" src="head.js"></script>
   <link rel="stylesheet" href="chrome://mochikit/contents/tests/SimpleTest/test.css"/>
 </head>
 <body>
 
 <script type="text/javascript">
 "use strict";
 
-const {
-  classes: Cc,
-  interfaces: Ci,
-  utils: Cu,
-} = Components;
-const Services = SpecialPowers.Services;
+const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://testing-common/TestUtils.jsm");
+
+/* eslint-disable mozilla/balanced-listeners */
 
 add_task(function* testAlertNotShownInBackgroundWindow() {
   ok(!Services.wm.getEnumerator("alert:alert").hasMoreElements(),
      "Alerts should not be present at the start of the test.");
 
+  let consoleOpened = TestUtils.topicObserved("web-console-created");
+
+
   let extension = ExtensionTestUtils.loadExtension({
     background: "new " + function() {
       browser.test.log("background script executed");
 
       alert("I am an alert in the background.");
 
       browser.test.notifyPass("alertCalled");
     },
   });
 
   yield extension.startup();
 
   info("startup complete loaded");
 
   yield extension.awaitFinish("alertCalled");
 
+
   let alertWindows = Services.wm.getEnumerator("alert:alert");
   ok(!alertWindows.hasMoreElements(), "Should not show alert");
 
+
   // Make sure the message we output to the console is seen.
   // This message is in ext-backgroundPage.js
   let events = Cc["@mozilla.org/consoleAPI-storage;1"]
     .getService(Ci.nsIConsoleAPIStorage).getEvents();
+
   // This is the warning that is output after the first `alert()` call is made.
   let alertWarningEvent = events[events.length - 2];
   is(alertWarningEvent.arguments[0], "alert() is not supported in background windows; please use console.log instead.");
+
   // This is the actual alert text that should be present in the console
   // instead of as an `alert`.
   let alertEvent = events[events.length - 1];
   is(alertEvent.arguments[0], "I am an alert in the background.");
 
+
+  // Wait for the browser console window to open.
+  yield consoleOpened;
+
   let {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
   require("devtools/client/framework/devtools-browser");
   let hudservice = require("devtools/client/webconsole/hudservice");
 
-  while (!hudservice.getBrowserConsole()) {
-    // Setting this to 0 fails, but 200 seems to do the trick.
-    yield new Promise(resolve => setTimeout(resolve, 200));
-  }
+  // And then double check that we have an actual browser console.
   let haveConsole = !!hudservice.getBrowserConsole();
   ok(haveConsole, "Expected browser console to be open");
 
   if (haveConsole) {
     yield hudservice.toggleBrowserConsole();
   }
 
   yield extension.unload();