docshell/test/browser/browser_bug670318.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:19524be4436a
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * Test for Bug 670318
6 *
7 * When LoadEntry() is called on a browser that has multiple duplicate history
8 * entries, history.index can end up out of range (>= history.count).
9 */
10
11 const URL = "http://mochi.test:8888/browser/docshell/test/browser/file_bug670318.html";
12
13 function test() {
14 waitForExplicitFinish();
15
16 let count = 0, historyListenerRemoved = false;
17
18 let listener = {
19 OnHistoryNewEntry: function (aNewURI) {
20 if (aNewURI.spec == URL && 5 == ++count) {
21 browser.addEventListener("load", function onLoad() {
22 browser.removeEventListener("load", onLoad, true);
23
24 ok(history.index < history.count, "history.index is valid");
25 finish();
26 }, true);
27
28 history.removeSHistoryListener(listener);
29 historyListenerRemoved = true;
30
31 executeSoon(function () BrowserReload());
32 }
33
34 return true;
35 },
36
37 OnHistoryReload: function () true,
38 OnHistoryGoBack: function () true,
39 OnHistoryGoForward: function () true,
40 OnHistoryGotoIndex: function () true,
41 OnHistoryPurge: function () true,
42 OnHistoryReplaceEntry: function () true,
43
44 QueryInterface: XPCOMUtils.generateQI([Ci.nsISHistoryListener,
45 Ci.nsISupportsWeakReference])
46 };
47
48 let tab = gBrowser.loadOneTab(URL, {inBackground: false});
49 let browser = tab.linkedBrowser;
50 let history = browser.sessionHistory;
51
52 history.addSHistoryListener(listener);
53
54 registerCleanupFunction(function () {
55 gBrowser.removeTab(tab);
56
57 if (!historyListenerRemoved)
58 history.removeSHistoryListener(listener);
59 });
60 }

mercurial