head_privatebrowsing.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 Private Browsing Tests.
15  *
16  * The Initial Developer of the Original Code is
17  * Ehsan Akhgari.
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> (Original Author)
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either of the GNU General Public License Version 2 or later (the "GPL"),
26  * or 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 const Cc = Components.classes;
39 const Ci = Components.interfaces;
40 const Cr = Components.results;
41 const Cu = Components.utils;
42 
43 const kPrivateBrowsingNotification = "private-browsing";
44 const kPrivateBrowsingCancelVoteNotification = "private-browsing-cancel-vote";
45 const kPrivateBrowsingTransitionCompleteNotification = "private-browsing-transition-complete";
46 const kEnter = "enter";
47 const kExit = "exit";
48 
50 const NS_APP_HISTORY_50_FILE = "UHist";
51 
52 function LOG(aMsg) {
53  aMsg = ("*** PRIVATEBROWSING TESTS: " + aMsg);
54  Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).
55  logStringMessage(aMsg);
56  print(aMsg);
57 }
58 
59 function uri(spec) {
60  return Cc["@mozilla.org/network/io-service;1"].
61  getService(Ci.nsIIOService).
62  newURI(spec, null, null);
63 }
64 
65 // If there's no location registered for the profile direcotry, register one now.
66 var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
68 try {
69  profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
70 } catch (e) {}
71 if (!profileDir) {
72  // Register our own provider for the profile directory.
73  // It will simply return the current directory.
74  var provider = {
75  getFile: function(prop, persistent) {
76  persistent.value = true;
77  if (prop == NS_APP_USER_PROFILE_50_DIR) {
78  return dirSvc.get("CurProcD", Ci.nsIFile);
79  }
80  if (prop == NS_APP_HISTORY_50_FILE) {
81  var histFile = dirSvc.get("CurProcD", Ci.nsIFile);
82  histFile.append("history.dat");
83  return histFile;
84  }
85  throw Cr.NS_ERROR_FAILURE;
86  },
87  QueryInterface: function(iid) {
88  if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
89  iid.equals(Ci.nsISupports)) {
90  return this;
91  }
92  throw Cr.NS_ERROR_NO_INTERFACE;
93  }
94  };
95  dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
96 }
97 
98 // Do not attempt to restore any session since we don't have any windows
99 Cc["@mozilla.org/preferences-service;1"].
100  getService(Ci.nsIPrefBranch).
101  setBoolPref("browser.privatebrowsing.keep_current_session", true);
102 
106 function cleanUp()
107 {
108  let files = [
109  "downloads.sqlite",
110  "places.sqlite",
111  "cookies.sqlite",
112  "signons.sqlite",
113  "permissions.sqlite"
114  ];
115 
116  for (let i = 0; i < files.length; i++) {
117  let file = dirSvc.get("ProfD", Ci.nsIFile);
118  file.append(files[i]);
119  if (file.exists())
120  file.remove(false);
121  }
122 }
123 cleanUp();
124 
128 function shutdownPlaces() {
129  let os = Cc["@mozilla.org/observer-service;1"].
130  getService(Ci.nsIObserverService);
131  os.notifyObservers(null, "quit-application", null);
132 }
133 
136  var contractIDs = [
137  "@mozilla.org/privatebrowsing;1",
138  "@mozilla.org/privatebrowsing-wrapper;1"
139  ];
140  for (var i = 0; i < contractIDs.length; ++i) {
141  PRIVATEBROWSING_CONTRACT_ID = contractIDs[i];
143  cleanUp();
144  }
145 }
const Cu
const NS_APP_USER_PROFILE_50_DIR
function uri(spec)
const kPrivateBrowsingCancelVoteNotification
function shutdownPlaces()
const Ci
const NS_APP_HISTORY_50_FILE
const kPrivateBrowsingTransitionCompleteNotification
sbOSDControlService prototype QueryInterface
const Cr
const kExit
var dirSvc
function getFile(fileName)
gPrefs setBoolPref("extensions.logging.enabled", true)
const kEnter
Cc["@mozilla.org/preferences-service;1"] getService(Ci.nsIPrefBranch).setBoolPref("browser.privatebrowsing.keep_current_session"
const Cc
return null
Definition: FeedWriter.js:1143
function newURI(aURLString)
var os
const kPrivateBrowsingNotification
function cleanUp()
function run_test_on_all_services()
var PRIVATEBROWSING_CONTRACT_ID
var profileDir
_getSelectedPageStyle s i
function LOG(aMsg)
var file
function run_test_on_service()