Bug 655273 - SHEntries created by history.pushState should have their titles set. r=sicking
authorJustin Lebar <justin.lebar@gmail.com>
Mon, 09 May 2011 14:54:36 -0400
changeset 69729 aad0fbc6ae777080cb6d928056f601fdb85ec710
parent 69728 99436764a9261c60e758f28be50408b85a26b83a
child 69730 1a9a234a6fc7295c5206666f0a22ca18e98a1dda
child 70055 5a00a3c94e63e0de2f35a6037c3a84ad3afa3212
push id20084
push userjlebar@mozilla.com
push dateThu, 19 May 2011 20:45:26 +0000
treeherdermozilla-central@aad0fbc6ae77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs655273
milestone6.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 655273 - SHEntries created by history.pushState should have their titles set. r=sicking
docshell/base/nsDocShell.cpp
docshell/test/browser/Makefile.in
docshell/test/browser/browser_bug655273.js
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -9655,16 +9655,21 @@ nsDocShell::AddState(nsIVariant *aData, 
 
         // Set the new SHEntry's document identifier, if we can.
         PRUint64 ourDocIdent;
         NS_ENSURE_SUCCESS(oldOSHE->GetDocIdentifier(&ourDocIdent),
                           NS_ERROR_FAILURE);
         NS_ENSURE_SUCCESS(newSHEntry->SetDocIdentifier(ourDocIdent),
                           NS_ERROR_FAILURE);
 
+        // Set the new SHEntry's title (bug 655273).
+        nsString title;
+        mOSHE->GetTitle(getter_Copies(title));
+        newSHEntry->SetTitle(title);
+
         // AddToSessionHistory may not modify mOSHE.  In case it doesn't,
         // we'll just set mOSHE here.
         mOSHE = newSHEntry;
 
     } else {
         newSHEntry = mOSHE;
         newSHEntry->SetURI(newURI);
     }
--- a/docshell/test/browser/Makefile.in
+++ b/docshell/test/browser/Makefile.in
@@ -50,12 +50,13 @@ include $(topsrcdir)/config/rules.mk
 		browser_bug349769.js \
 		browser_bug388121-1.js \
 		browser_bug388121-2.js \
 		browser_bug441169.js \
 		browser_bug503832.js \
 		browser_loadDisallowInherit.js \
 		file_bug503832.html \
 		browser_bug554155.js \
+		browser_bug655273.js \
 		$(NULL)
 
 libs:: $(_BROWSER_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/docshell/test/browser/browser_bug655273.js
@@ -0,0 +1,68 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ *   Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ * 
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Justin Lebar <justin.lebar@gmail.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ * 
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Test for Bug 655273.  Make sure that after changing the URI via
+ * history.pushState, the resulting SHEntry has the same title as our old
+ * SHEntry.
+ **/
+
+function test() {
+  waitForExplicitFinish();
+
+  let tab = gBrowser.addTab('http://example.com');
+  let tabBrowser = tab.linkedBrowser;
+
+  tabBrowser.addEventListener('load', function(aEvent) {
+    tabBrowser.removeEventListener('load', arguments.callee, true);
+
+    let cw = tabBrowser.contentWindow;
+    let oldTitle = cw.document.title;
+    ok(oldTitle, 'Content window should initially have a title.');
+    cw.history.pushState('', '', 'new_page');
+
+    let shistory = cw.QueryInterface(Ci.nsIInterfaceRequestor)
+                     .getInterface(Ci.nsIWebNavigation)
+                     .sessionHistory;
+
+    is(shistory.getEntryAtIndex(shistory.index, false).title,
+       oldTitle, 'SHEntry title after pushstate.');
+
+    gBrowser.removeTab(tab);
+    finish();
+  }, true);
+}