|
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 let stateBackup = ss.getBrowserState(); |
|
6 |
|
7 function cleanup() { |
|
8 // Reset the pref |
|
9 try { |
|
10 Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand"); |
|
11 } catch (e) {} |
|
12 ss.setBrowserState(stateBackup); |
|
13 executeSoon(finish); |
|
14 } |
|
15 |
|
16 function test() { |
|
17 /** Bug 599909 - to-be-reloaded tabs don't show up in switch-to-tab **/ |
|
18 waitForExplicitFinish(); |
|
19 |
|
20 // Set the pref to true so we know exactly how many tabs should be restoring at |
|
21 // any given time. This guarantees that a finishing load won't start another. |
|
22 Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true); |
|
23 |
|
24 let state = { windows: [{ tabs: [ |
|
25 { entries: [{ url: "http://example.org/#1" }] }, |
|
26 { entries: [{ url: "http://example.org/#2" }] }, |
|
27 { entries: [{ url: "http://example.org/#3" }] }, |
|
28 { entries: [{ url: "http://example.org/#4" }] } |
|
29 ], selected: 1 }] }; |
|
30 |
|
31 let tabsForEnsure = {}; |
|
32 state.windows[0].tabs.forEach(function(tab) { |
|
33 tabsForEnsure[tab.entries[0].url] = 1; |
|
34 }); |
|
35 |
|
36 let tabsRestoring = 0; |
|
37 let tabsRestored = 0; |
|
38 |
|
39 function handleEvent(aEvent) { |
|
40 if (aEvent.type == "SSTabRestoring") |
|
41 tabsRestoring++; |
|
42 else |
|
43 tabsRestored++; |
|
44 |
|
45 if (tabsRestoring < state.windows[0].tabs.length || |
|
46 tabsRestored < 1) |
|
47 return; |
|
48 |
|
49 gBrowser.tabContainer.removeEventListener("SSTabRestoring", handleEvent, true); |
|
50 gBrowser.tabContainer.removeEventListener("SSTabRestored", handleEvent, true); |
|
51 executeSoon(function() { |
|
52 checkAutocompleteResults(tabsForEnsure, cleanup); |
|
53 }); |
|
54 } |
|
55 |
|
56 // currentURI is set before SSTabRestoring is fired, so we can sucessfully check |
|
57 // after that has fired for all tabs. Since 1 tab will be restored though, we |
|
58 // also need to wait for 1 SSTabRestored since currentURI will be set, unset, then set. |
|
59 gBrowser.tabContainer.addEventListener("SSTabRestoring", handleEvent, true); |
|
60 gBrowser.tabContainer.addEventListener("SSTabRestored", handleEvent, true); |
|
61 ss.setBrowserState(JSON.stringify(state)); |
|
62 } |
|
63 |
|
64 // The following was taken from browser/base/content/test/general/browser_tabMatchesInAwesomebar.js |
|
65 // so that we could do the same sort of checking. |
|
66 var gController = Cc["@mozilla.org/autocomplete/controller;1"]. |
|
67 getService(Ci.nsIAutoCompleteController); |
|
68 |
|
69 function checkAutocompleteResults(aExpected, aCallback) { |
|
70 gController.input = { |
|
71 timeout: 10, |
|
72 textValue: "", |
|
73 searches: ["history"], |
|
74 searchParam: "enable-actions", |
|
75 popupOpen: false, |
|
76 minResultsForPopup: 0, |
|
77 invalidate: function() {}, |
|
78 disableAutoComplete: false, |
|
79 completeDefaultIndex: false, |
|
80 get popup() { return this; }, |
|
81 onSearchBegin: function() {}, |
|
82 onSearchComplete: function () |
|
83 { |
|
84 info("Found " + gController.matchCount + " matches."); |
|
85 // Check to see the expected uris and titles match up (in any order) |
|
86 for (let i = 0; i < gController.matchCount; i++) { |
|
87 let uri = gController.getValueAt(i).replace(/^moz-action:[^,]+,/i, ""); |
|
88 |
|
89 info("Search for '" + uri + "' in open tabs."); |
|
90 ok(uri in aExpected, "Registered open page found in autocomplete."); |
|
91 // Remove the found entry from expected results. |
|
92 delete aExpected[uri]; |
|
93 } |
|
94 |
|
95 // Make sure there is no reported open page that is not open. |
|
96 for (let entry in aExpected) { |
|
97 ok(false, "'" + entry + "' not found in autocomplete."); |
|
98 } |
|
99 |
|
100 executeSoon(aCallback); |
|
101 }, |
|
102 setSelectedIndex: function() {}, |
|
103 get searchCount() { return this.searches.length; }, |
|
104 getSearchAt: function(aIndex) this.searches[aIndex], |
|
105 QueryInterface: XPCOMUtils.generateQI([ |
|
106 Ci.nsIAutoCompleteInput, |
|
107 Ci.nsIAutoCompletePopup, |
|
108 ]) |
|
109 }; |
|
110 |
|
111 info("Searching open pages."); |
|
112 gController.startSearch(Services.prefs.getCharPref("browser.urlbar.restrict.openpage")); |
|
113 } |