browser_248970_a.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  * Aaron Train <aaron.train@gmail.com>.
18  * Portions created by the Initial Developer are Copyright (C) 2008
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Ehsan Akhgari <ehsan.akhgari@gmail.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
43 
44  // private browsing service
45  let pb = Cc["@mozilla.org/privatebrowsing;1"].
46  getService(Ci.nsIPrivateBrowsingService);
47  gPrefService.setBoolPref("browser.privatebrowsing.keep_current_session", true);
48  let profilePath = Cc["@mozilla.org/file/directory_service;1"].
49  getService(Ci.nsIProperties).
50  get("ProfD", Ci.nsIFile);
51 
52  function getSessionstoreFile() {
53  let sessionStoreJS = profilePath.clone();
54  sessionStoreJS.append("sessionstore.js");
55  return sessionStoreJS;
56  }
57 
58  function getSessionstorejsModificationTime() {
59  let file = getSessionstoreFile();
60  if (file.exists())
61  return file.lastModifiedTime;
62  else
63  return -1;
64  }
65 
66  let os = Cc["@mozilla.org/observer-service;1"].
67  getService(Ci.nsIObserverService);
68  function waitForFileExistence(aMessage, aDoNext) {
69  const TOPIC = "sessionstore-state-write-complete";
70  let observer = {
71  observe: function(aSubject, aTopic, aData)
72  {
73  // Remove the observer so we do not leak.
74  os.removeObserver(this, TOPIC);
75 
76  // Check that the file exists.
77  ok(getSessionstoreFile().exists(), aMessage);
78 
79  // Run our next set of work.
80  aDoNext();
81  }
82  };
83  os.addObserver(observer, TOPIC, false);
84  }
85 
86  function actualTest() {
87 
89  // Test (A) : No data recording while in private browsing mode //
91 
92  // public session, add a new tab: (A)
93  const testURL_A = "http://example.org/";
94  let tab_A = gBrowser.addTab(testURL_A);
95 
96  tab_A.linkedBrowser.addEventListener("load", function (aEvent) {
97  this.removeEventListener("load", arguments.callee, true);
98 
99  // remove sessionstore.js to make sure it's created again when entering
100  // the private browsing mode.
101  let sessionStoreJS = getSessionstoreFile();
102  sessionStoreJS.remove(false);
103 
104  // enter private browsing mode
105  pb.privateBrowsingEnabled = true;
106  ok(pb.privateBrowsingEnabled, "private browsing enabled");
107 
108  // sessionstore.js should be re-created at this point
109  waitForFileExistence("file should be created after private browsing entered",
110  function() {
111  // record the time stamp of sessionstore.js in the private session
112  let startPBModeTimeStamp = getSessionstorejsModificationTime();
113 
114  // private browsing session, add new tab: (B)
115  const testURL_B = "http://test1.example.org/";
116  let tab_B = gBrowser.addTab(testURL_B);
117 
118  tab_B.linkedBrowser.addEventListener("load", function (aEvent) {
119  this.removeEventListener("load", arguments.callee, true);
120 
121  // private browsing session, add new tab: (C)
122  const testURL_C = "http://localhost:8888/";
123  let tab_C = gBrowser.addTab(testURL_C);
124 
125  tab_C.linkedBrowser.addEventListener("load", function (aEvent) {
126  this.removeEventListener("load", arguments.callee, true);
127 
128  // private browsing session, close tab: (C)
129  gBrowser.removeTab(tab_C);
130 
131  // private browsing session, close tab: (B)
132  gBrowser.removeTab(tab_B);
133 
134  // private browsing session, close tab: (A)
135  gBrowser.removeTab(tab_A);
136 
137  // record the timestamp of sessionstore.js at the end of the private session
138  if (gPrefService.prefHasUserValue("browser.sessionstore.interval"))
139  gPrefService.clearUserPref("browser.sessionstore.interval");
140  gPrefService.setIntPref("browser.sessionstore.interval", 0);
141  let endPBModeTimeStamp = getSessionstorejsModificationTime();
142 
143  // exit private browsing mode
144  pb.privateBrowsingEnabled = false;
145  ok(!pb.privateBrowsingEnabled, "private browsing disabled");
146 
147  // compare timestamps: pre and post private browsing session
148  is(startPBModeTimeStamp, endPBModeTimeStamp,
149  "outside private browsing - sessionStore.js timestamp has not changed");
150 
151  // cleanup
152  gPrefService.clearUserPref("browser.sessionstore.interval");
153  gPrefService.clearUserPref("browser.privatebrowsing.keep_current_session");
154  finish();
155  }, true);
156  }, true);
157  }); // End of anonymous waitForFileExistence function.
158  }, true);
159  }
160 
161  // sessionstore service
162  let ss = Cc["@mozilla.org/browser/sessionstore;1"].
163  getService(Ci.nsISessionStore);
164  // Remove the sessionstore.js file before setting the interval to 0
165  let sessionStoreJS = getSessionstoreFile();
166  if (sessionStoreJS.exists())
167  sessionStoreJS.remove(false);
168  // Make sure that sessionstore.js can be forced to be created by setting
169  // the interval pref to 0
170  gPrefService.setIntPref("browser.sessionstore.interval", 0);
171  // sessionstore.js should be re-created at this point
172  waitForFileExistence("file should be created after setting interval to 0",
173  actualTest);
174 }
const Cc
getService(Ci.sbIFaceplateManager)
waitForExplicitFinish()
return!aWindow arguments!aWindow arguments[0]
var gPrefService
Definition: overlay.js:34
var os
const Ci
this removeEventListener("load", this.__SS_restore, true)
function test()
let observer
_updateTextAndScrollDataForFrame aData
var file
sbDeviceFirmwareAutoCheckForUpdate prototype observe