Bug 754029 - Tests. r=smaug
authorOonishi Atsushi <torisugari@gmail.com>
Fri, 27 Jul 2012 17:51:53 -0400
changeset 100775 ae0b0dd6dfa260ff447909b10f42110f2e81638b
parent 100774 551b6acdafb9f3a0474de38a8dde22042446ed16
child 100776 2fd48f64273e576acd1d4488f964784e132aa740
push id12655
push userryanvm@gmail.com
push dateFri, 27 Jul 2012 21:51:47 +0000
treeherdermozilla-inbound@74c9c20b284a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs754029
milestone17.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 754029 - Tests. r=smaug
docshell/test/chrome/Makefile.in
docshell/test/chrome/bug754029_window.xul
docshell/test/chrome/test_bug754029.xul
docshell/test/navigation/Makefile.in
docshell/test/navigation/file_bug754029.html
--- a/docshell/test/chrome/Makefile.in
+++ b/docshell/test/chrome/Makefile.in
@@ -89,16 +89,18 @@ MOCHITEST_CHROME_FILES =	\
 		662200c.html \
 		test_bug690056.xul \
 		bug690056_window.xul \
 		test_bug311007.xul \
 		bug311007_window.xul \
 		test_principalInherit.xul \
 		test_mozFrameType.xul \
 		mozFrameType_window.xul \
+		test_bug754029.xul \
+		bug754029_window.xul \
 		$(NULL)
 
 MOCHITEST_CHROME_FILES += \
     docshell_helpers.js \
     generic.html \
     $(NULL)
 
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/docshell/test/chrome/bug754029_window.xul
@@ -0,0 +1,307 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+
+<window id="754029Test"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        width="600"
+        height="600"
+        onload="startup();"
+        title="bug 754029 test">
+
+  <script type="application/javascript" src="docshell_helpers.js"></script>
+  <script type="application/javascript"><![CDATA[
+
+const _kDocshellTestNavURI =
+  "http://test1.example.org:80/tests/docshell/test/navigation/";
+
+const kBlankURI = _kDocshellTestNavURI + "blank.html";
+const kRedirectURI = _kDocshellTestNavURI + "file_bug754029.html";
+
+function startup() {
+  var browser = document.getElementById("content");
+  browser.addEventListener("load", contentOnLoad, true);
+  content.location.href = kBlankURI + "?start";
+}
+
+function contentOnLoad(aEvent) {
+  is(aEvent.originalTarget.nodeName, "#document", "Loading a document.");
+  var browser = document.getElementById("content");
+  var sessionHistory = browser.sessionHistory;
+
+  var _contentLoadURI = function (aHref) {content.location.href = aHref;}
+
+  function contentLoadURI(aHref) {
+    setTimeout(_contentLoadURI, 0, aHref);
+  }
+
+  function indexToSearch(aSessionHistory, aIndex) {
+    return "?" + aSessionHistory.getEntryAtIndex(aIndex, false)
+                                .URI
+                                .QueryInterface(Components.interfaces.nsIURL)
+                                .query;
+  }
+
+  switch(content.location.search) {
+  case "?start":
+    // Expected SH entries are:
+    // 1  * <blank.html          ?start>
+    is(content.history.length, 1, "Initial <about:blank> is replaced.");
+
+    // Requesting <file_bug754029.html?test1>
+    contentLoadURI(kRedirectURI + "?test1");
+    break;
+
+  /*****************************************************************************
+   * Test 1: Load a JS redirecting page; |location.href = ...| is directly in
+   *         <script></script> tag.
+   *
+   * Expected Result: The redirected page should replace the redirecting page's
+   *                  session history.
+   ****************************************************************************/
+  case "?test1":
+    // We can't catch this onload, because redirection is earlier than
+    // firing load event. That is OK.
+
+    // Expected SH entries are:
+    // 0    <?start>
+    // 1  * <?test1>
+    break;
+
+  case "?result1":
+    // Expected SH entries are:
+    // 0    <?start>
+    // x    <?test1>    // replaced.
+    // 1  * <?result1>
+
+    is(sessionHistory.count, 2, "<?result1>: SH's length");
+    is(sessionHistory.index, 1, "<?result1>: Current entry's index");
+
+    is(indexToSearch(sessionHistory, sessionHistory.index),
+       "?result1",
+       "Check if the current SH entry is <?result1>");
+
+    is(indexToSearch(sessionHistory, sessionHistory.index - 1),
+       "?start",
+       "Check if the previous SH entry is not <?test1> but <?start>");
+
+    // Requesting <file_bug754029.html?test2>
+    contentLoadURI(kRedirectURI + "?test2");
+    break;
+
+  /*****************************************************************************
+   * Test 2: Load a JS redirecting page; |location.href = ...| is in
+   *         "load" event handler.
+   *
+   * Expected Result: Replace
+   ****************************************************************************/
+  case "?test2":
+    // Expected SH entries are:
+    // 0    <?start>
+    // x    <?test1>    // replaced.
+    // 1    <?result1>
+    // 2  * <?test2>
+
+    is(sessionHistory.count, 3, "<?test2>: SH's length");
+    is(sessionHistory.index, 2, "<?test2>: Current entry's index");
+
+    is(indexToSearch(sessionHistory, sessionHistory.index),
+       "?test2",
+       "Check if the current SH entry is <?test2>");
+
+    is(indexToSearch(sessionHistory, sessionHistory.index - 1),
+       "?result1",
+       "Check if the previous SH entry is <?result1>");
+    break;
+
+  case "?result2":
+    // Expected SH entries are:
+    // 0    <?start>
+    // x    <?test1>    // replaced.
+    // 1    <?result1>
+    // x    <?test2>    // replaced.
+    // 2  * <?result2>
+
+    is(sessionHistory.count, 3, "<?result2>: SH's length");
+    is(sessionHistory.index, 2, "<?result2>: Current entry's index");
+
+    is(indexToSearch(sessionHistory, sessionHistory.index),
+       "?result2",
+       "Check if the current SH entry is <?result2>");
+
+    is(indexToSearch(sessionHistory, sessionHistory.index - 1),
+       "?result1",
+       "Check if the previous SH entry is not <?test2> but <?resutl1>");
+
+    contentLoadURI(kRedirectURI + "?test3");
+    break;
+
+  /*****************************************************************************
+   * Test 3: Load a JS redirecting page; |location.href = ...| is in
+   *         setTimeout(...)'s call back.
+   *
+   * Expected Result: Not replace
+   ****************************************************************************/
+  case "?test3":
+    // Expected SH entries are:
+    // 0    <?start>
+    // x    <?test1>    // replaced.
+    // 1    <?result1>
+    // x    <?test2>    // replaced.
+    // 2    <?result2>
+    // 3  * <?test3>
+
+    is(sessionHistory.count, 4, "<?test3>: SH's length");
+    is(sessionHistory.index, 3, "<?test3>: Current entry's index");
+
+    is(indexToSearch(sessionHistory, sessionHistory.index),
+       "?test3",
+       "Check if the current SH entry is <?test3>");
+
+    is(indexToSearch(sessionHistory, sessionHistory.index - 1),
+       "?result2",
+       "Check if the previous SH entry is <?result2>");
+    break;
+
+  case "?result3":
+    // Expected SH entries are:
+    // 0    <?start>
+    // x    <?test1>    // replaced.
+    // 1    <?result1>
+    // x    <?test2>    // replaced.
+    // 2    <?result2>
+    // 3    <?test3>    // not replaced.
+    // 4  * <?result3>
+
+    is(sessionHistory.count, 5, "<?result3>: SH's length");
+    is(sessionHistory.index, 4, "<?result3>: Current entry's index");
+
+    is(indexToSearch(sessionHistory, sessionHistory.index),
+       "?result3",
+       "Check if the current SH entry is <?result3>");
+
+    is(indexToSearch(sessionHistory, sessionHistory.index - 1),
+       "?test3",
+       "Check if <?test3> exists.");
+
+    contentLoadURI(kRedirectURI + "?test4");
+    break;
+
+  /*****************************************************************************
+   * Test 4: Load a JS redirecting page; setTimeout(...)'s callback
+   *         is inserting a new script element into the document. And the
+   *         inserted script contains |location.href = ...|.
+   *
+   *         See also:
+   *         https://bugzilla.mozilla.org/attachment.cgi?id=622899
+   *
+   * Expected Result: Not replace
+   ****************************************************************************/
+  case "?test4":
+    // Expected SH entries are:
+    // 0    <?start>
+    // x    <?test1>    // replaced.
+    // 1    <?result1>
+    // x    <?test2>    // replaced.
+    // 2    <?result2>
+    // 3    <?test3>    // not replaced
+    // 4    <?result3>
+    // 5  * <?test4>
+
+    is(sessionHistory.count, 6, "<?test4>: SH's length");
+    is(sessionHistory.index, 5, "<?test4>: Current entry's index");
+
+    is(indexToSearch(sessionHistory, sessionHistory.index),
+       "?test4",
+       "Check if the current SH entry is <?test4>");
+
+    is(indexToSearch(sessionHistory, sessionHistory.index - 1),
+       "?result3",
+       "Check if the previous SH entry is <?result3>");
+
+    break;
+
+  case "?result4":
+    // Expected SH entries are:
+    // 0    <?start>
+    // x    <?test1>    // replaced.
+    // 1    <?result1>
+    // x    <?test2>    // replaced.
+    // 2    <?result2>
+    // 3    <?test3>    // not replaced.
+    // 4    <?result3>
+    // 5    <?test4>    // not replaced.
+    // 6  * <?result4>
+
+    is(sessionHistory.count, 7, "<?test4>: SH's length");
+    is(sessionHistory.index, 6, "<?test4>: Current entry's index");
+
+    is(indexToSearch(sessionHistory, sessionHistory.index),
+       "?result4",
+       "Check if the current SH entry is <?test4>");
+
+    is(indexToSearch(sessionHistory, sessionHistory.index - 1),
+       "?test4",
+       "Check if <?test4> exists.");
+
+    contentLoadURI(kRedirectURI + "?testDOMContentLoaded");
+    break;
+
+  /*****************************************************************************
+   * Test 5: Setting location.href in onDOMContentLoaded() should REPLACE.
+   ****************************************************************************/
+  case "?testDOMContentLoaded":
+    break;
+  case "?resultDOMContentLoaded":
+    is(indexToSearch(sessionHistory, sessionHistory.index),
+       "?resultDOMContentLoaded",
+       "Check if the current SH entry is <?resultDOMContentLoaded>");
+
+    is(indexToSearch(sessionHistory, sessionHistory.index - 1),
+       "?result4",
+       "Check if the perevious entry is not <?testDOMContentLoaded> but " +
+       "<?result4>.");
+
+    contentLoadURI(kRedirectURI + "?testPageshow");
+    break;
+
+  /*****************************************************************************
+   * Test 6: Setting location.href in onpageshow() should REPLACE.
+   ****************************************************************************/
+  case "?testPageshow":
+    break;
+  case "?resultPageshow":
+    is(indexToSearch(sessionHistory, sessionHistory.index),
+       "?resultPageshow",
+       "Check if the current SH entry is <?resultPageshow>");
+
+    is(indexToSearch(sessionHistory, sessionHistory.index - 1),
+       "?resultDOMContentLoaded",
+       "Check if the perevious entry is not <?testPageshow> but " +
+       "<?resultDOMContentLoaded>.");
+
+    contentLoadURI(kRedirectURI + "?testReadystatechange");
+    break;
+
+  /*****************************************************************************
+   * Test 7: Setting location.href in onreadystatechange() should REPLACE.
+   ****************************************************************************/
+  case "?testReadystatechange":
+    break;
+  case "?resultReadystatechange":
+    is(indexToSearch(sessionHistory, sessionHistory.index),
+       "?resultReadystatechange",
+       "Check if the current SH entry is <?resultReadystatechange>");
+
+    is(indexToSearch(sessionHistory, sessionHistory.index - 1),
+       "?resultPageshow",
+       "Check if the perevious entry is not <?testReadystatechange> but " +
+       "<?resultPageshow>.");
+
+    finish();
+    break;
+  }
+}
+  ]]></script>
+
+  <browser type="content-primary" flex="1" id="content" src="about:blank"/>
+</window>
new file mode 100644
--- /dev/null
+++ b/docshell/test/chrome/test_bug754029.xul
@@ -0,0 +1,43 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+<?xml-stylesheet
+  href="chrome://mochikit/content/tests/SimpleTest/test.css"
+  type="text/css"?>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=754029.xul
+-->
+<window title="Mozilla Bug 754029"
+  xmlns:html="http://www.w3.org/1999/xhtml"
+  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+  <title>Test for Bug 754029</title>
+  <script type="application/javascript"
+    src="chrome://mochikit/content/MochiKit/packed.js"></script>
+  <script type="application/javascript"
+    src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+
+<body  xmlns="http://www.w3.org/1999/xhtml">
+<a target="_blank"
+   href="https://bugzilla.mozilla.org/show_bug.cgi?id=754029">
+   Mozilla Bug 754029</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+
+<script class="testbody" type="application/javascript">
+<![CDATA[
+
+/** Test for Bug 754029 **/
+
+SimpleTest.waitForExplicitFinish();
+window.open("bug754029_window.xul", "bug754029",
+            "chrome,width=600,height=600");
+
+]]>
+</script>
+
+</window>
--- a/docshell/test/navigation/Makefile.in
+++ b/docshell/test/navigation/Makefile.in
@@ -42,16 +42,17 @@ MOCHITEST_FILES = \
 		file_document_write_1.html \
 		file_static_and_dynamic_1.html \
 		frame0.html \
 		frame1.html \
 		frame2.html \
 		frame3.html \
 		goback.html \
 		file_bug534178.html \
+		file_bug754029.html \
 		$(NULL)
 
 ifneq (mobile,$(MOZ_BUILD_APP))
 MOCHITEST_BROWSER_FILES = \
 		browser_bug343515.js \
 		bug343515_pg1.html \
 		bug343515_pg2.html \
 		bug343515_pg3.html \
new file mode 100644
--- /dev/null
+++ b/docshell/test/navigation/file_bug754029.html
@@ -0,0 +1,84 @@
+<html>
+<head>
+<meta http-equiv="content-type" Content="text/html; charset=utf-8">
+</head>
+<body>
+<script>
+
+// inline <script> tag redirection.
+function test1() {
+  location.href = "blank.html?result1";
+}
+
+// onload() handler redirection.
+function test2() {
+  addEventListener("load", 
+                   function(aEvent) {
+                     location.href = "blank.html?result2";
+                   },
+                   false);
+}
+
+// setTimeout() 100 milisec redirection.
+function test3() {
+  setTimeout(function() {
+               location.href = "blank.html?result3";
+             },
+             100);
+}
+
+// setTimeout() 100 milisec + inline <script> tag redirection.
+function test4() {
+  setTimeout(function() {
+               var ns = document.createElement("script");
+               var nt = document.createTextNode(
+                          "location = 'blank.html?result4'"
+                        );
+               ns.appendChild(nt);
+               document.documentElement.appendChild(ns);
+             },
+             100);
+}
+
+// DOMContentLoaded
+function testDOMContentLoaded() {
+  addEventListener("DOMContentLoaded", 
+                   function(aEvent) {
+                     location.href = "blank.html?resultDOMContentLoaded";
+                   },
+                   false);
+}
+
+// pageshow
+function testPageshow() {
+  addEventListener("pageshow", 
+                   function(aEvent) {
+                     location.href = "blank.html?resultPageshow";
+                   },
+                   false);
+}
+
+// readystatechange for "complete"
+function testReadystatechange() {
+  document.onreadystatechange =
+    function() {
+      if ("complete" == document.readyState) {
+        location.href = "blank.html?resultReadystatechange";
+      }
+    };
+}
+
+switch(location.search) {
+case "?test1": test1(); break;
+case "?test2": test2(); break;
+case "?test3": test3(); break;
+case "?test4": test4(); break;
+case "?testDOMContentLoaded": testDOMContentLoaded(); break;
+case "?testPageshow"        : testPageshow();         break;
+case "?testReadystatechange": testReadystatechange(); break;
+default: throw "Unexpected!";
+}
+
+</script>
+</body>
+</html>