Bug 949471 - history.state should be null, not undefined, when there is no state. r=smaug, a=lsblakk
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 12 Dec 2013 16:11:56 -0500
changeset 175318 40e9753ec0eebc5537751910f9dff582b08ed5e9
parent 175317 e8523e7bddac8c5e9df0e136bbd40c323243f1b4
child 175319 c89197c22c25fbe8fa3212e67bb2e1c1bd2c2c78
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, lsblakk
bugs949471
milestone28.0a2
Bug 949471 - history.state should be null, not undefined, when there is no state. r=smaug, a=lsblakk
dom/base/nsHistory.cpp
dom/base/test/mochitest.ini
dom/base/test/test_history_state_null.html
dom/tests/mochitest/whatwg/test_bug500328.html
--- a/dom/base/nsHistory.cpp
+++ b/dom/base/nsHistory.cpp
@@ -134,17 +134,17 @@ nsHistory::GetState(JSContext* aCx, Erro
     if (!JS_WrapValue(aCx, &jsData)) {
       aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
       return JS::UndefinedValue();
     }
 
     return jsData;
   }
 
-  return JS::UndefinedValue();
+  return JS::NullValue();
 }
 
 void
 nsHistory::Go(int32_t aDelta, ErrorResult& aRv)
 {
   nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mInnerWindow));
   if (!win || !win->HasActiveDocument()) {
     aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
--- a/dom/base/test/mochitest.ini
+++ b/dom/base/test/mochitest.ini
@@ -14,16 +14,17 @@ support-files =
 [test_domcursor.html]
 [test_domrequest.html]
 [test_e4x_for_each.html]
 [test_error.html]
 [test_gsp-qualified.html]
 [test_gsp-quirks.html]
 [test_gsp-standards.html]
 [test_history_document_open.html]
+[test_history_state_null.html]
 [test_innersize_scrollport.html]
 [test_messageChannel.html]
 [test_messageChannel_cloning.html]
 [test_messageChannel_pingpong.html]
 [test_messageChannel_post.html]
 [test_messageChannel_pref.html]
 [test_messageChannel_start.html]
 [test_messageChannel_transferable.html]
new file mode 100644
--- /dev/null
+++ b/dom/base/test/test_history_state_null.html
@@ -0,0 +1,25 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=949471
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 949471</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">
+  /** Test for Bug 949471 **/
+    ise(history.state, null, "history.state should be null by default");
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=949471">Mozilla Bug 949471</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>
--- a/dom/tests/mochitest/whatwg/test_bug500328.html
+++ b/dom/tests/mochitest/whatwg/test_bug500328.html
@@ -273,39 +273,39 @@ function runTest() {
      "Wrong state object popped after going back to page 1.");
   ok(gLastPopStateEvent.state === iframeCw.history.state,
      "Wrong state object in document after going back to page 1.");
   ok(iframeCw.location.toString().match(/file_bug500328_1.html$/),
       "Going back to page 1 hould take us to original page.");
 
   iframeCw.history.back();
   popstateExpected("Going back to page 0 should trigger a popstate.");
-  is(gLastPopStateEvent.state, null,
+  ise(gLastPopStateEvent.state, null,
       "Going back to page 0 should pop a null state.");
-  is(iframeCw.history.state, null,
+  ise(iframeCw.history.state, null,
       "Going back to page 0 should pop a null state.");
-  is(iframeCw.location.search, "",
+  ise(iframeCw.location.search, "",
       "Going back to page 0 should clear the querystring.");
 
   iframeCw.history.forward();
   popstateExpected("Going forward to page 1 should trigger a popstate.");
   is(JSON.stringify(gLastPopStateEvent.state), JSON.stringify(testObj1),
       "Wrong state object popped after going forward to page 1.");
-  ok(gLastPopStateEvent.state === iframeCw.history.state,
+  ise(gLastPopStateEvent.state, iframeCw.history.state,
       "Wrong state object in document after going forward to page 1.");
   ok(iframeCw.location.toString().match(/file_bug500328_1.html$/),
       "Going forward to page 1 should leave us at original page.");
 
   statusMsg("About to go forward to page 2.");
   iframeCw.history.forward();
   statusMsg("Awake after going forward to page 2.");
   popstateExpected("Going forward to page 2 should trigger a popstate.");
   is(JSON.stringify(gLastPopStateEvent.state), JSON.stringify(testObj2),
      "Wrong state object popped after going forward to page 2.");
-  ok(iframeCw.history.state === gLastPopStateEvent.state,
+  ise(iframeCw.history.state, gLastPopStateEvent.state,
      "Wrong state object in document after going forward to page 2.");
   ok(iframeCw.location.toString().match(/file_bug500328_1.html\?test1#foo$/),
      "Going forward to page 2 took us to " + iframeCw.location.toString());
 
   statusMsg("About to reload page 2.");
   iframeCw.location.reload();
   enableChildLoadCallback();
   yield undefined;
@@ -324,17 +324,17 @@ function runTest() {
   enableChildPopStateCallback();
   sendMouseEvent({type:'click'}, 'link-anchor1', iframeCw);
   yield undefined;
   popstateExpected("Clicking on link-anchor1 should trigger a popstate.");
   is(iframeCw.location.search, "?test1",
       "search should be ?test1 after clicking link.");
   is(iframeCw.location.hash, "#1",
       "hash should be #1 after clicking link.");
-  ok(iframeCw.history.state === null,
+  ise(iframeCw.history.state, null,
      "Wrong state object in document after clicking link to hash '#1'.");
 
   /*
    * Reload file_bug500328_1.html; we're now going to test that link hrefs
    * and colors are updated correctly on push/popstates.
    */
 
   iframe.onload = onChildLoad;