browser_526613.js
Go to the documentation of this file.
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is sessionstore test code.
15  *
16  * The Initial Developer of the Original Code is
17  * Mozilla Foundation.
18  * Portions created by the Initial Developer are Copyright (C) 2009
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Ehsan Akhgari <ehsan@mozilla.com>
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37 
38 function test() {
41  // test setup
42  let ss = Cc["@mozilla.org/browser/sessionstore;1"].
43  getService(Ci.nsISessionStore);
44  let os = Cc["@mozilla.org/observer-service;1"].
45  getService(Ci.nsIObserverService);
46  let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
47  getService(Ci.nsIWindowMediator);
49 
50  function browserWindowsCount() {
51  let count = 0;
52  let e = wm.getEnumerator("navigator:browser");
53  while (e.hasMoreElements()) {
54  if (!e.getNext().closed)
55  ++count;
56  }
57 
58  return count;
59  }
60 
61  is(browserWindowsCount(), 1, "Only one browser window should be open initially");
62 
63  // backup old state
64  let oldState = ss.getBrowserState();
65  // create a new state for testing
66  let testState = {
67  windows: [
68  { tabs: [{ entries: [{ url: "http://example.com/" }] }], selected: 1 },
69  { tabs: [{ entries: [{ url: "about:robots" }] }], selected: 1 },
70  ],
71  // make sure the first window is focused, otherwise when restoring the
72  // old state, the first window is closed and the test harness gets unloaded
73  selectedWindow: 1
74  };
75 
76  let observer = {
77  pass: 1,
78  observe: function(aSubject, aTopic, aData) {
79  is(aTopic, "sessionstore-browser-state-restored",
80  "The sessionstore-browser-state-restored notification was observed");
81 
82  if (this.pass++ == 1) {
83  is(browserWindowsCount(), 2, "Two windows should exist at this point");
84 
85  // let the first window be focused (see above)
86  function pollMostRecentWindow() {
87  if (wm.getMostRecentWindow("navigator:browser") == window) {
88  ss.setBrowserState(oldState);
89  } else {
90  info("waiting for the current window to become active");
91  setTimeout(pollMostRecentWindow, 0);
92  }
93  }
94  window.focus(); //XXX Why is this needed?
95  pollMostRecentWindow();
96  }
97  else {
98  is(browserWindowsCount(), 1, "Only one window should exist after cleanup");
99  ok(!window.closed, "Restoring the old state should have left this window open");
100  os.removeObserver(this, "sessionstore-browser-state-restored");
101  finish();
102  }
103  }
104  };
105  os.addObserver(observer, "sessionstore-browser-state-restored", false);
106 
107  // set browser to test state
108  ss.setBrowserState(JSON.stringify(testState));
109 }
const Cc
var windows
getService(Ci.sbIFaceplateManager)
let window
var count
Definition: test_bug7406.js:32
var tabs
waitForExplicitFinish()
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
var os
function url(spec)
function test()
const Ci
var JSON
let observer
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe