Bug 742944 - Part 5: Tests for window.open in <iframe mozbrowser>. r=bz
authorJustin Lebar <justin.lebar@gmail.com>
Tue, 12 Jun 2012 18:01:25 -0400
changeset 96533 bc7286e373c9ddea9fe819473e25e5b05e91cfd3
parent 96532 65a425a98e860afa7132473dbf6a2f6868374b92
child 96534 a41fd66f124530dc07856ea67da4067b843f268b
push id22911
push useremorley@mozilla.com
push dateWed, 13 Jun 2012 12:49:30 +0000
treeherdermozilla-central@efbb6480e98e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs742944
milestone16.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 742944 - Part 5: Tests for window.open in <iframe mozbrowser>. r=bz
dom/browser-element/mochitest/Makefile.in
dom/browser-element/mochitest/browserElement_OpenWindow.js
dom/browser-element/mochitest/browserElement_OpenWindowRejected.js
dom/browser-element/mochitest/browserElement_OpenWindowRejected2.js
dom/browser-element/mochitest/file_browserElement_Open1.html
dom/browser-element/mochitest/file_browserElement_Open2.html
dom/browser-element/mochitest/file_browserElement_OpenWindowRejected.html
dom/browser-element/mochitest/file_empty.html
dom/browser-element/mochitest/test_browserElement_inproc_OpenWindow.html
dom/browser-element/mochitest/test_browserElement_inproc_OpenWindowRejected.html
dom/browser-element/mochitest/test_browserElement_inproc_OpenWindowRejected2.html
dom/browser-element/mochitest/test_browserElement_oop_OpenWindow.html
dom/browser-element/mochitest/test_browserElement_oop_OpenWindowRejected.html
dom/browser-element/mochitest/test_browserElement_oop_OpenWindowRejected2.html
--- a/dom/browser-element/mochitest/Makefile.in
+++ b/dom/browser-element/mochitest/Makefile.in
@@ -54,12 +54,21 @@ include $(topsrcdir)/config/rules.mk
 		test_browserElement_oop_PromptCheck.html \
 		test_browserElement_inproc_PromptCheck.html \
 		browserElement_PromptConfirm.js \
 		test_browserElement_oop_PromptConfirm.html \
 		test_browserElement_inproc_PromptConfirm.html \
 		browserElement_Close.js \
 		test_browserElement_oop_Close.html \
 		test_browserElement_inproc_Close.html \
+		browserElement_OpenWindow.js \
+		test_browserElement_oop_OpenWindow.html \
+		test_browserElement_inproc_OpenWindow.html \
+		file_browserElement_Open1.html \
+		file_browserElement_Open2.html \
+		browserElement_OpenWindowRejected.js \
+		test_browserElement_oop_OpenWindowRejected.html \
+		test_browserElement_inproc_OpenWindowRejected.html \
+		file_browserElement_OpenWindowRejected.html \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/browserElement_OpenWindow.js
@@ -0,0 +1,59 @@
+/* Any copyright is dedicated to the public domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Bug 742944 - Test that window.open works with <iframe mozbrowser>.
+
+"use strict";
+SimpleTest.waitForExplicitFinish();
+
+function runTest() {
+  browserElementTestHelpers.setEnabledPref(true);
+  browserElementTestHelpers.addToWhitelist();
+
+  var iframe = document.createElement('iframe');
+  iframe.mozbrowser = true;
+
+  var gotPopup = false;
+  iframe.addEventListener('mozbrowseropenwindow', function(e) {
+    is(gotPopup, false, 'Should get just one popup.');
+    gotPopup = true;
+
+    document.body.appendChild(e.detail.frameElement);
+
+    ok(/file_browserElement_Open2\.html$/.test(e.detail.url),
+       "Popup's URL (got " + e.detail.url + ")");
+    is(e.detail.name, "name");
+    is(e.detail.features, "features");
+  });
+
+  iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
+    ok(gotPopup, 'Got mozbrowseropenwindow event before showmodalprompt event.');
+    if (e.detail.message.indexOf("success:") == 0) {
+      ok(true, e.detail.message);
+    }
+    else if (e.detail.message.indexOf("failure:") == 0) {
+      ok(false, e.detail.message);
+    }
+    else if (e.detail.message == "finish") {
+      SimpleTest.finish();
+    }
+    else {
+      ok(false, "Got invalid message: " + e.detail.message);
+    }
+  });
+
+  /**
+   * file_browserElementOpen1 does
+   *
+   *   window.open('file_browserElement_Open2.html', 'name', 'features')
+   *
+   * then adds an event listener to the opened window and waits for onload.
+   *
+   * Onload, we fire a few alerts saying "success:REASON" or "failure:REASON".
+   * Finally, we fire a "finish" alert, which ends the test.
+   */
+  iframe.src = 'file_browserElement_Open1.html';
+  document.body.appendChild(iframe);
+}
+
+runTest();
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/browserElement_OpenWindowRejected.js
@@ -0,0 +1,44 @@
+/* Any copyright is dedicated to the public domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Bug 742944 - Do window.open from inside <iframe mozbrowser>.  But then
+// reject the call.  This shouldn't cause problems (crashes, leaks).
+
+"use strict";
+SimpleTest.waitForExplicitFinish();
+
+function runTest() {
+  browserElementTestHelpers.setEnabledPref(true);
+  browserElementTestHelpers.addToWhitelist();
+
+  var iframe = document.createElement('iframe');
+  iframe.mozbrowser = true;
+
+  iframe.addEventListener('mozbrowseropenwindow', function(e) {
+    ok(e.detail.url.indexOf('does_not_exist.html') != -1,
+       'Opened URL; got ' + e.detail.url);
+    is(e.detail.name, '');
+    is(e.detail.features, '');
+
+    // Don't add e.detail.frameElement to the DOM, so the window.open is
+    // effectively blocked.
+  });
+
+  iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
+    var msg = e.detail.message;
+    if (msg.indexOf('success:') == 0) {
+      ok(true, msg);
+    }
+    else if (msg == 'finish') {
+      SimpleTest.finish();
+    }
+    else {
+      ok(false, msg);
+    }
+  });
+
+  iframe.src = 'file_browserElement_OpenWindowRejected.html';
+  document.body.appendChild(iframe);
+}
+
+runTest();
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/browserElement_OpenWindowRejected2.js
@@ -0,0 +1,48 @@
+/* Any copyright is dedicated to the public domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Bug 742944 - Do window.open from inside <iframe mozbrowser>.  But then
+// reject the call.  This shouldn't cause problems (crashes, leaks).
+//
+// This is the same as OpenWindowRejected, except we "reject" the popup by not
+// adding the iframe element to our DOM, instead of by not calling
+// preventDefault() on the event.
+
+"use strict";
+SimpleTest.waitForExplicitFinish();
+
+function runTest() {
+  browserElementTestHelpers.setEnabledPref(true);
+  browserElementTestHelpers.addToWhitelist();
+
+  var iframe = document.createElement('iframe');
+  iframe.mozbrowser = true;
+
+  iframe.addEventListener('mozbrowseropenwindow', function(e) {
+    ok(e.detail.url.indexOf('does_not_exist.html') != -1,
+       'Opened URL; got ' + e.detail.url);
+    is(e.detail.name, '');
+    is(e.detail.features, '');
+
+    // Call preventDefault, but don't add the iframe to the DOM.  This still
+    // amounts to rejecting the popup.
+    e.preventDefault();
+  });
+
+  iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
+    var msg = e.detail.message;
+    if (msg.indexOf('success:') == 0) {
+      ok(true, msg);
+    }
+    else if (msg == 'finish') {
+      SimpleTest.finish();
+    }
+    else {
+      ok(false, msg);
+    }
+  });
+
+  iframe.src = 'file_browserElement_OpenWindowRejected.html';
+}
+
+runTest();
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/file_browserElement_Open1.html
@@ -0,0 +1,33 @@
+<html>
+<body>
+<script>
+
+// Because this file is inside <iframe mozbrowser>, the alert() calls below
+// don't trigger actual dialogs.  Instead, the document which contans the
+// iframe receives mozbrowsershowmodalprompt events, which the document uses
+// to determine test success/failure.
+
+function is(x, y, reason) {
+  if (x === y)  {
+    alert("success: " + x + " === " + y + ", " + reason);
+  }
+  else {
+    alert("failure: " + x + " !== " + y + ", " + reason);
+  }
+}
+
+function ok(bool, reason) {
+  alert((bool ? "success: " : "failure: ") + reason);
+}
+
+var w = window.open("file_browserElement_Open2.html", "name", "features");
+w.addEventListener("load", function() {
+  ok(true, "got load");
+  is(w.opener, window, 'opener property');
+  is(w.location.href, location.href.replace('Open1', 'Open2'), 'correct location');
+  is(w.document.getElementById('testElem').innerHTML, 'test', 'elem innerHTML');
+  alert("finish");
+});
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/file_browserElement_Open2.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+<div id='testElem'>test</div>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/file_browserElement_OpenWindowRejected.html
@@ -0,0 +1,16 @@
+<html>
+<body>
+
+<script>
+var w = window.open('does_not_exist.html');
+if (!w) {
+  alert("success:w is null");
+}
+else {
+  alert("failure:w is not null -- " + w);
+}
+alert("finish");
+</script>
+
+</body>
+</html>
--- a/dom/browser-element/mochitest/file_empty.html
+++ b/dom/browser-element/mochitest/file_empty.html
@@ -1,10 +1,12 @@
 <html>
 <body>
 
+<!-- Tests rely on the fact that there's an element in here called 'url'. -->
 Aloha!  My URL is <span id='url'></span>.
+
 <script>
 document.getElementById('url').innerHTML = window.location;
 </script>
 
 </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/test_browserElement_inproc_OpenWindow.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test of browser element.</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="browserElementTestHelpers.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<script type="application/javascript;version=1.7" src="browserElement_OpenWindow.js">
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/test_browserElement_inproc_OpenWindowRejected.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test of browser element.</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="browserElementTestHelpers.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<script type="application/javascript;version=1.7" src="browserElement_OpenWindowRejected.js">
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/test_browserElement_inproc_OpenWindowRejected2.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test of browser element.</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="browserElementTestHelpers.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<script type="application/javascript;version=1.7" src="browserElement_OpenWindowRejected.js">
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/test_browserElement_oop_OpenWindow.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test of browser element.</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="browserElementTestHelpers.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<script type="application/javascript;version=1.7" src="browserElement_OpenWindow.js">
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/test_browserElement_oop_OpenWindowRejected.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test of browser element.</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="browserElementTestHelpers.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<script type="application/javascript;version=1.7" src="browserElement_OpenWindowRejected.js">
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/test_browserElement_oop_OpenWindowRejected2.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test of browser element.</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="browserElementTestHelpers.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<script type="application/javascript;version=1.7" src="browserElement_OpenWindowRejected.js">
+</script>
+</body>
+</html>