|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 /** |
|
6 * Test for Bug 646224. Make sure that after changing the URI via |
|
7 * history.pushState, the history service has a title stored for the new URI. |
|
8 **/ |
|
9 |
|
10 function test() { |
|
11 waitForExplicitFinish(); |
|
12 |
|
13 let tab = gBrowser.addTab('http://example.com'); |
|
14 let tabBrowser = tab.linkedBrowser; |
|
15 |
|
16 tabBrowser.addEventListener('load', function(aEvent) { |
|
17 tabBrowser.removeEventListener('load', arguments.callee, true); |
|
18 |
|
19 // Control should now flow down to observer.onTitleChanged(). |
|
20 let cw = tabBrowser.contentWindow; |
|
21 ok(cw.document.title, 'Content window should initially have a title.'); |
|
22 cw.history.pushState('', '', 'new_page'); |
|
23 }, true); |
|
24 |
|
25 let observer = { |
|
26 onTitleChanged: function(uri, title) { |
|
27 // If the uri of the page whose title is changing ends with 'new_page', |
|
28 // then it's the result of our pushState. |
|
29 if (/new_page$/.test(uri.spec)) { |
|
30 is(title, tabBrowser.contentWindow.document.title, |
|
31 'Title after pushstate.'); |
|
32 PlacesUtils.history.removeObserver(this); |
|
33 gBrowser.removeTab(tab); |
|
34 finish(); |
|
35 } |
|
36 }, |
|
37 |
|
38 onBeginUpdateBatch: function() { }, |
|
39 onEndUpdateBatch: function() { }, |
|
40 onVisit: function() { }, |
|
41 onDeleteURI: function() { }, |
|
42 onClearHistory: function() { }, |
|
43 onPageChanged: function() { }, |
|
44 onDeleteVisits: function() { }, |
|
45 QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver]) |
|
46 }; |
|
47 |
|
48 PlacesUtils.history.addObserver(observer, false); |
|
49 } |