Bug 1263798 - rewrite broadcastchannel tests for e10s, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 12 Apr 2016 16:12:08 -0400
changeset 330776 246b4f8d75bdb8dbf7856392f7716f2a7f0484d8
parent 330775 6fc0294f96c5b74a19da133a260df51677d64c3f
child 330777 06616766e22e50155e23d99a5621911b8308b059
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1263798
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 1263798 - rewrite broadcastchannel tests for e10s, r=smaug
dom/broadcastchannel/moz.build
dom/broadcastchannel/tests/browser.ini
dom/broadcastchannel/tests/browser_private_browsing.js
dom/broadcastchannel/tests/chrome.ini
dom/broadcastchannel/tests/test_broadcastchannel_private_browsing.html
--- a/dom/broadcastchannel/moz.build
+++ b/dom/broadcastchannel/moz.build
@@ -19,16 +19,16 @@ IPDL_SOURCES += [
     'PBroadcastChannel.ipdl',
 ]
 
 LOCAL_INCLUDES += [
     '../workers',
 ]
 
 MOCHITEST_MANIFESTS += ['tests/mochitest.ini']
-MOCHITEST_CHROME_MANIFESTS += ['tests/chrome.ini']
+BROWSER_CHROME_MANIFESTS += ['tests/browser.ini']
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
 if CONFIG['GNU_CXX']:
     CXXFLAGS += ['-Wshadow']
new file mode 100644
--- /dev/null
+++ b/dom/broadcastchannel/tests/browser.ini
@@ -0,0 +1,6 @@
+[DEFAULT]
+skip-if = buildapp == 'b2g' || os == 'android'
+support-files =
+  blank.html
+
+[browser_private_browsing.js]
new file mode 100644
--- /dev/null
+++ b/dom/broadcastchannel/tests/browser_private_browsing.js
@@ -0,0 +1,74 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+const URL = "http://mochi.test:8888/browser/dom/broadcastchannel/tests/blank.html";
+
+add_task(function*() {
+  var win1 = OpenBrowserWindow({private: true});
+  var win1Promise = new win1.Promise(resolve => {
+    win1.addEventListener("load", function onLoad() {
+      win1.removeEventListener("load", onLoad, false);
+      resolve();
+    });
+  });
+  yield win1Promise;
+
+  var win2 = OpenBrowserWindow({private: false});
+  var win2Promise = new win2.Promise(resolve => {
+    win2.addEventListener("load", function onLoad() {
+      win2.removeEventListener("load", onLoad, false);
+      resolve();
+    });
+  });
+  yield win2Promise;
+
+  var tab1 = win1.gBrowser.addTab(URL);
+  yield BrowserTestUtils.browserLoaded(win1.gBrowser.getBrowserForTab(tab1));
+  var browser1 = gBrowser.getBrowserForTab(tab1);
+
+  var tab2 = win2.gBrowser.addTab(URL);
+  yield BrowserTestUtils.browserLoaded(win2.gBrowser.getBrowserForTab(tab2));
+  var browser2 = gBrowser.getBrowserForTab(tab2);
+
+  var p1 = ContentTask.spawn(browser1, null, function(opts) {
+    return new content.window.Promise(resolve => {
+      content.window.bc = new content.window.BroadcastChannel('foobar');
+      content.window.bc.onmessage = function(e) { resolve(e.data); }
+    });
+  });
+
+  var p2 = ContentTask.spawn(browser2, null, function(opts) {
+    return new content.window.Promise(resolve => {
+      content.window.bc = new content.window.BroadcastChannel('foobar');
+      content.window.bc.onmessage = function(e) { resolve(e.data); }
+    });
+  });
+
+  yield ContentTask.spawn(browser1, null, function(opts) {
+    return new content.window.Promise(resolve => {
+      var bc = new content.window.BroadcastChannel('foobar');
+      bc.postMessage('hello world from private browsing');
+      resolve();
+    });
+  });
+
+  yield ContentTask.spawn(browser2, null, function(opts) {
+    return new content.window.Promise(resolve => {
+      var bc = new content.window.BroadcastChannel('foobar');
+      bc.postMessage('hello world from non private browsing');
+      resolve();
+    });
+  });
+
+  var what1 = yield p1;
+  ok(what1, 'hello world from private browsing', 'No messages received from the other window.');
+
+  var what2 = yield p2;
+  ok(what1, 'hello world from non private browsing', 'No messages received from the other window.');
+
+  yield BrowserTestUtils.removeTab(tab1);
+  yield BrowserTestUtils.closeWindow(win1);
+
+  yield BrowserTestUtils.removeTab(tab2);
+  yield BrowserTestUtils.closeWindow(win2);
+});
deleted file mode 100644
--- a/dom/broadcastchannel/tests/chrome.ini
+++ /dev/null
@@ -1,6 +0,0 @@
-[DEFAULT]
-skip-if = e10s || buildapp == 'b2g' || os == 'android'
-support-files =
-  blank.html
-
-[test_broadcastchannel_private_browsing.html]
deleted file mode 100644
--- a/dom/broadcastchannel/tests/test_broadcastchannel_private_browsing.html
+++ /dev/null
@@ -1,118 +0,0 @@
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-  <title>Test for BroadcastChannel - Private Browsing</title>
-  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
-</head>
-<body>
-
-<script type="application/javascript">
-
-const Ci = Components.interfaces;
-var mainWindow;
-
-var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
-                           .getService(Components.interfaces.nsIPrefBranch);
-prefBranch.setIntPref("browser.startup.page", 0);
-prefBranch.setCharPref("browser.startup.homepage_override.mstone", "ignore");
-
-var contentPage = "http://mochi.test:8888/chrome/dom/broadcastchannel/tests/blank.html";
-
-function testOnWindow(aIsPrivate, aCallback) {
-  var win = mainWindow.OpenBrowserWindow({private: aIsPrivate});
-  win.addEventListener("load", function onLoad() {
-    win.removeEventListener("load", onLoad, false);
-    win.addEventListener("DOMContentLoaded", function onInnerLoad() {
-      if (win.content.location.href != contentPage) {
-        win.gBrowser.loadURI(contentPage);
-        return;
-      }
-
-      win.removeEventListener("DOMContentLoaded", onInnerLoad, true);
-      SimpleTest.executeSoon(function() { aCallback(win); });
-    }, true);
-
-    if (!aIsPrivate) {
-      win.gBrowser.loadURI(contentPage);
-    }
-  }, true);
-}
-
-function setupWindow() {
-  mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
-                     .getInterface(Ci.nsIWebNavigation)
-                     .QueryInterface(Ci.nsIDocShellTreeItem)
-                     .rootTreeItem
-                     .QueryInterface(Ci.nsIInterfaceRequestor)
-                     .getInterface(Ci.nsIDOMWindow);
-  runTest();
-}
-
-var gCounter = 0;
-
-function check(msg, private) {
-  is(msg, private ? "private" : "public", "Correct context!");
-  gCounter++;
-
-  if (gCounter > 1) {
-    runTest();
-  }
-}
-
-var wN;
-var wP;
-
-function doTests() {
-  testOnWindow(false, function(aWin) {
-    wN = aWin;
-
-    testOnWindow(true, function(aWin) {
-      wP = aWin;
-
-      var bcP = new wP.content.BroadcastChannel('foobar');
-      bcP.onmessage = function(e) { ok(false, "This should not be called!"); }
-
-      var bc = new wP.content.BroadcastChannel('foobar');
-      bc.onmessage = function(e) { check(e.data, true); }
-
-      var bcN = new wN.content.BroadcastChannel('foobar');
-      bcN.onmessage = function(e) { ok(false, "This should not be called!"); }
-
-      var bc = new wN.content.BroadcastChannel('foobar');
-      bc.onmessage = function(e) { check(e.data, false); }
-
-      bcP.postMessage('private');
-      bcN.postMessage('public');
-    });
-  });
-}
-
-var steps = [
-  setupWindow,
-  doTests
-];
-
-function runTest() {
-  if (!steps.length) {
-    wN.close();
-    wP.close();
-
-    prefBranch.clearUserPref("browser.startup.page")
-    prefBranch.clearUserPref("browser.startup.homepage_override.mstone");
-
-    SimpleTest.finish();
-    return;
-  }
-
-  var step = steps.shift();
-  step();
-}
-
-SimpleTest.waitForExplicitFinish();
-runTest();
-
-</script>
-</body>
-</html>
-
-