43 let ss =
Cc[
"@mozilla.org/browser/sessionstore;1"].
46 function waitForBrowserState(
aState, aSetStateCallback) {
47 var locationChanges = 0;
48 gBrowser.addTabsProgressListener({
49 onLocationChange:
function (
aBrowser) {
50 if (++locationChanges ==
aState.windows[0].tabs.length) {
51 gBrowser.removeTabsProgressListener(
this);
52 executeSoon(aSetStateCallback);
55 onProgressChange:
function () {},
56 onSecurityChange:
function () {},
58 onStatusChange:
function () {}
66 function test_newTabFocused() {
70 { entries: [{
url:
"about:mozilla" }] },
71 { entries: [], userTypedValue:
"example.com", userTypedClear: 0 }
77 waitForBrowserState(state,
function() {
78 let
browser = gBrowser.selectedBrowser;
79 is(browser.currentURI.spec,
"about:blank",
80 "No history entries still sets currentURI to about:blank");
81 is(browser.userTypedValue,
"example.com",
82 "userTypedValue was correctly restored");
83 is(browser.userTypedClear, 0,
84 "userTypeClear restored as expected");
85 is(gURLBar.value,
"example.com",
86 "Address bar's value correctly restored");
88 gBrowser.selectedTab = gBrowser.tabContainer.getItemAtIndex(0);
89 is(gURLBar.value,
"about:mozilla",
90 "Address bar's value correctly updated");
98 function test_newTabNotFocused() {
102 { entries: [{
url:
"about:mozilla" }] },
103 { entries: [], userTypedValue:
"example.org", userTypedClear: 0 }
109 waitForBrowserState(state,
function() {
110 let
browser = gBrowser.getBrowserAtIndex(1);
111 is(browser.currentURI.spec,
"about:blank",
112 "No history entries still sets currentURI to about:blank");
113 is(browser.userTypedValue,
"example.org",
114 "userTypedValue was correctly restored");
115 is(browser.userTypedClear, 0,
116 "userTypeClear restored as expected");
117 is(gURLBar.value,
"about:mozilla",
118 "Address bar's value correctly restored");
120 gBrowser.selectedTab = gBrowser.tabContainer.getItemAtIndex(1);
121 is(gURLBar.value,
"example.org",
122 "Address bar's value correctly updated");
130 function test_existingSHEnd_noClear() {
134 entries: [{
url:
"about:mozilla" }, {
url:
"about:config" }],
136 userTypedValue:
"example.com",
142 waitForBrowserState(state,
function() {
143 let
browser = gBrowser.selectedBrowser;
144 is(browser.currentURI.spec,
"about:config",
145 "browser.currentURI set to current entry in SH");
146 is(browser.userTypedValue,
"example.com",
147 "userTypedValue was correctly restored");
148 is(browser.userTypedClear, 0,
149 "userTypeClear restored as expected");
150 is(gURLBar.value,
"example.com",
151 "Address bar's value correctly restored to userTypedValue");
159 function test_existingSHMiddle_noClear() {
163 entries: [{
url:
"about:mozilla" }, {
url:
"about:config" }],
165 userTypedValue:
"example.org",
171 waitForBrowserState(state,
function() {
172 let
browser = gBrowser.selectedBrowser;
173 is(browser.currentURI.spec,
"about:mozilla",
174 "browser.currentURI set to current entry in SH");
175 is(browser.userTypedValue,
"example.org",
176 "userTypedValue was correctly restored");
177 is(browser.userTypedClear, 0,
178 "userTypeClear restored as expected");
179 is(gURLBar.value,
"example.org",
180 "Address bar's value correctly restored to userTypedValue");
186 function test_getBrowserState_lotsOfTabsOpening() {
188 for (let
i = 0;
i < 25;
i++)
189 uris.push(
"http://example.com/" +
i);
195 gBrowser.addEventListener(
"load",
function(aEvent) {
196 if (gBrowser.currentURI.spec ==
"about:blank")
198 gBrowser.removeEventListener(
"load",
arguments.callee,
true);
200 let state =
JSON.parse(ss.getBrowserState());
202 let hasSH = state.windows[0].tabs.some(
function(
aTab) {
203 return !(
"userTypedValue" in
aTab) &&
aTab.entries[0].url;
205 let hasUTV = state.windows[0].tabs.some(
function(
aTab) {
206 return aTab.userTypedValue &&
aTab.userTypedClear && !
aTab.entries.length;
209 ok(hasSH,
"At least one tab has it's entry in SH");
210 ok(hasUTV,
"At least one tab has a userTypedValue with userTypedClear with no loaded URL");
215 gBrowser.loadTabs(uris);
220 function test_getBrowserState_userTypedValue() {
223 tabs: [{ entries: [] }]
227 waitForBrowserState(state,
function() {
228 let
browser = gBrowser.selectedBrowser;
230 is(browser.userTypedValue,
null,
"userTypedValue is empty to start");
231 is(browser.userTypedClear, 0,
"userTypedClear is 0 to start");
233 gURLBar.value =
"mozilla.org";
234 let
event = document.createEvent(
"Events");
235 event.initEvent(
"input",
true,
false);
236 gURLBar.dispatchEvent(
event);
238 is(browser.userTypedValue,
"mozilla.org",
239 "userTypedValue was set when changing gURLBar.value");
240 is(browser.userTypedClear, 0,
241 "userTypedClear was not changed when changing gURLBar.value");
244 let newState =
JSON.parse(ss.getBrowserState());
245 is(newState.windows[0].tabs[0].userTypedValue,
"mozilla.org",
246 "sessionstore got correct userTypedValue");
247 is(newState.windows[0].tabs[0].userTypedClear, 0,
248 "sessionstore got correct userTypedClear");
256 function test_userTypedClearLoadURI() {
260 { entries: [], userTypedValue:
"http://example.com", userTypedClear: 2 }
269 ss.setBrowserState(
JSON.stringify(state));
270 gBrowser.addEventListener(
"load",
function(aEvent) {
271 if (gBrowser.currentURI.spec ==
"about:blank")
273 gBrowser.removeEventListener(
"load",
arguments.callee,
true);
275 let
browser = gBrowser.selectedBrowser;
276 is(browser.currentURI.spec,
"http://example.com/",
277 "userTypedClear=2 caused userTypedValue to be loaded");
278 is(browser.userTypedValue,
null,
279 "userTypedValue was null after loading a URI");
280 is(browser.userTypedClear, 0,
281 "userTypeClear reset to 0");
282 is(gURLBar.value,
"http://example.com/",
283 "Address bar's value set after loading URI");
289 let
tests = [test_newTabFocused, test_newTabNotFocused,
290 test_existingSHEnd_noClear, test_existingSHMiddle_noClear,
291 test_getBrowserState_lotsOfTabsOpening,
292 test_getBrowserState_userTypedValue, test_userTypedClearLoadURI];
293 let originalState = ss.getBrowserState();
298 ss.setBrowserState(originalState);
getService(Ci.sbIFaceplateManager)
return!aWindow arguments!aWindow arguments[0]
_updateTextAndScrollDataForTab aBrowser
_replaceLoadingTitle aTab
ContinuingWebProgressListener prototype onStateChange
_getSelectedPageStyle s i