Bug 860941 - Tests. r=jst
authorBobby Holley <bobbyholley@gmail.com>
Fri, 17 May 2013 10:43:20 -0700
changeset 132271 017883faccbb8b6497ea585fd83ff21620de6931
parent 132270 6bd149e8edfc61f64b7a66d6aafa799ee85038f5
child 132272 341f9653ff921293c2dc3a38741c4f4fcd1f13b4
push id24691
push userryanvm@gmail.com
push dateSat, 18 May 2013 01:41:18 +0000
treeherdermozilla-central@6e2789a70f6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst
bugs860941
milestone24.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 860941 - Tests. r=jst We augment the existing showModalDialog tests with test coverage for dialogArguments and returnValue.
dom/tests/mochitest/bugs/file_bug504862.html
dom/tests/mochitest/general/file_showModalDialog.html
dom/tests/mochitest/general/test_showModalDialog.html
--- a/dom/tests/mochitest/bugs/file_bug504862.html
+++ b/dom/tests/mochitest/bugs/file_bug504862.html
@@ -3,18 +3,18 @@
 <script>
 window.returnValue = 3;
 
 if (location.toString().match(/^http:\/\/mochi.test:8888/)) {
   // Test that we got the right arguments.
   opener.is(window.dialogArguments, "my args",
             "dialog did not get the right arguments.");
 
-  // Load a different url, and test that it doesn't see the arguments.
-  window.location="data:text/html,<html><body onload=\"opener.is(window.dialogArguments, null, 'subsequent dialog document did not get the right arguments.'); close();\">';";
+  // Load a different url, and test that it sees the arguments (since it's same origin).
+  window.location="data:text/html,<html><body onload=\"opener.is(window.dialogArguments, 'my args', 'subsequent dialog document did not get the right arguments.'); close();\">';";
 } else {
   // Post a message containing our arguments to the opener to test
   // that this cross origing dialog does *not* see the passed in
   // arguments.
   opener.postMessage("args: " + window.dialogArguments,
                      "http://mochi.test:8888");
 
   close();
--- a/dom/tests/mochitest/general/file_showModalDialog.html
+++ b/dom/tests/mochitest/general/file_showModalDialog.html
@@ -1,19 +1,35 @@
 <!DOCTYPE html>
 <html>
 <head>
 <script>
-  ok = window.opener.ok;
-  is = window.opener.is;
-  SpecialPowers = window.opener.SpecialPowers;
   function go() {
+    is(SpecialPowers.wrap(window).location.toString(), location.toString(), "sanity");
     is(SpecialPowers.Cu.getClassName(window, /* aUnwrap = */ true), "ModalContentWindow", "We are modal");
     var iwin = document.getElementById('ifr').contentWindow;
     is(SpecialPowers.Cu.getClassName(iwin, /* aUnwrap = */ true), "Window", "Descendant frames should not be modal");
-    window.close();
+
+    if (location.origin != "http://mochi.test:8888") {
+      is(window.dialogArguments, undefined,
+        "dialogArguments should be undefined cross-origin: " + location.origin);
+    }
+
+    window.returnValue = "rv: " + window.dialogArguments;
+
+    // Allow for testing navigations in series.
+    if (location.search == "") {
+      window.close();
+    } else {
+      var origins = location.search.split('?')[1].split(',');
+      var newsearch = '?' + origins.splice(1).join(',');
+      var newurl = location.toString().replace(location.origin, origins[0])
+                                      .replace(location.search, newsearch);
+      location = newurl;
+    }
+
   }
 </script>
 </head>
-<body onload="go();">
+<body onload="opener.postMessage('dosetup', '*');">
 <iframe id="ifr"></iframe>
 </body>
 </html>
--- a/dom/tests/mochitest/general/test_showModalDialog.html
+++ b/dom/tests/mochitest/general/test_showModalDialog.html
@@ -5,23 +5,50 @@ https://bugzilla.mozilla.org/show_bug.cg
 -->
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 862918</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript">
 
-  // This will be fixed in bug 860941.
-  SimpleTest.expectAssertions(0, 1);
+  /** Test for window.showModalDialog. **/
+
+  // The modal window needs to touch Cu, which means that it needs
+  // SpecialPowers. But given the semantics of modal windows, we have to
+  // do some funny stuff with postMessage to set this up.
+  window.onmessage = function(evt) {
+    is(evt.data, 'dosetup', "message from modal window is correct");
+    var win = SpecialPowers.wrap(evt.source);
+    win.wrappedJSObject.SpecialPowers = SpecialPowers;
+    win.wrappedJSObject.is = is;
+    win.wrappedJSObject.ok = ok;
+    win.wrappedJSObject.go();
+  };
 
-  /** Test for window.showModalDialog. **/
-  window.showModalDialog('file_showModalDialog.html');
+  var someObj = { foo: 42, bar: "hi"};
+  var xurl = location.toString()
+                     .replace('mochi.test:8888', 'example.org')
+                     .replace('test_showModal', 'file_showModal');
+  if (xurl.indexOf('?') != -1)
+    xurl = xurl.substring(0, xurl.indexOf('?'));
+  is(showModalDialog('file_showModalDialog.html'), "rv: undefined");
+  is(showModalDialog(xurl), undefined);
+  is(showModalDialog('file_showModalDialog.html', 3), "rv: 3");
+  is(showModalDialog(xurl, 3), undefined);
+  is(showModalDialog('file_showModalDialog.html', someObj), "rv: " + someObj);
+  is(showModalDialog(xurl, someObj), undefined);
 
-  // Blame mArguments assertion on this test.
+  // Test sequential navigations.
+  is(showModalDialog('file_showModalDialog.html?http://mochi.test:8888', 4),
+                     'rv: 4');
+  is(showModalDialog('file_showModalDialog.html?http://example.com', 4), undefined);
+  is(showModalDialog('file_showModalDialog.html?http://example.com,http://mochi.test:8888', 4), 'rv: 4');
+
+  // This test used to assert after gc. Make sure it doesn't.
   SpecialPowers.gc();
 
   </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=862918">Mozilla Bug 862918</a>
 <p id="display"></p>
 <div id="content" style="display: none">