browser_privatebrowsing_placestitle.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) 2009
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 // This test makes sure that the title of existing history entries does not
39 // change inside the private browsing mode.
40 
41 function test() {
42  // initialization
43  let pb = Cc["@mozilla.org/privatebrowsing;1"].
44  getService(Ci.nsIPrivateBrowsingService);
45  let bhist = Cc["@mozilla.org/browser/global-history;2"].
46  getService(Ci.nsIBrowserHistory);
47  let histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
48  getService(Ci.nsINavHistoryService).
49  QueryInterface(Ci.nsPIPlacesDatabase);
50  let cm = Cc["@mozilla.org/cookiemanager;1"].
51  getService(Ci.nsICookieManager);
53 
54  const TEST_URL = "http://localhost:8888/browser/browser/components/privatebrowsing/test/browser/title.sjs";
55 
56  function cleanup() {
57  // delete all history items
58  bhist.removeAllPages();
59  // delete all cookies
60  cm.removeAll();
61  }
62  cleanup();
63 
64  let observer = {
65  pass: 1,
66  onBeginUpdateBatch: function() {
67  },
68  onEndUpdateBatch: function() {
69  },
70  onVisit: function(aURI, aVisitID, aTime, aSessionId, aReferringId,
71  aTransitionType, _added) {
72  },
73  onTitleChanged: function(aURI, aPageTitle) {
74  if (aURI.spec != TEST_URL)
75  return;
76  switch (this.pass++) {
77  case 1: // the first time that the page is loaded
78  is(aPageTitle, "No Cookie", "The page should be loaded without any cookie for the first time");
79  gBrowser.selectedTab = gBrowser.addTab(TEST_URL);
80  break;
81  case 2: // the second time that the page is loaded
82  is(aPageTitle, "Cookie", "The page should be loaded with a cookie for the second time");
83  cleanup();
84  gBrowser.selectedTab = gBrowser.addTab(TEST_URL);
85  break;
86  case 3: // before entering the private browsing mode
87  is(aPageTitle, "No Cookie", "The page should be loaded without any cookie again");
88  // enter private browsing mode
89  pb.privateBrowsingEnabled = true;
90  gBrowser.selectedTab = gBrowser.addTab(TEST_URL);
91  executeSoon(function() {
92  histsvc.removeObserver(observer);
93  pb.privateBrowsingEnabled = false;
94  while (gBrowser.browsers.length > 1)
95  gBrowser.removeCurrentTab();
96  cleanup();
97  finish();
98  });
99  break;
100  default:
101  ok(false, "Unexpected pass: " + (this.pass - 1));
102  }
103  },
104  onBeforeDeleteURI: function(aURI) {
105  },
106  onDeleteURI: function(aURI) {
107  },
108  onClearHistory: function() {
109  },
110  onPageChanged: function(aURI, aWhat, aValue) {
111  },
112  onPageExpired: function(aURI, aVisitTime, aWholeEntry) {
113  },
114  QueryInterface: function(iid) {
115  if (iid.equals(Ci.nsINavHistoryObserver) ||
116  iid.equals(Ci.nsISupports)) {
117  return this;
118  }
119  throw Cr.NS_ERROR_NO_INTERFACE;
120  }
121  };
122  histsvc.addObserver(observer, false);
123 
124  gBrowser.selectedTab = gBrowser.addTab(TEST_URL);
125 }
const Cc
onPageChanged onVisit
Definition: FeedWriter.js:1395
onPageChanged aValue
Definition: FeedWriter.js:1395
onPageChanged onEndUpdateBatch
Definition: FeedWriter.js:1395
onPageChanged onBeforeDeleteURI
Definition: FeedWriter.js:1395
sbOSDControlService prototype QueryInterface
const histsvc
getService(Ci.sbIFaceplateManager)
onPageChanged onPageExpired
Definition: FeedWriter.js:1395
waitForExplicitFinish()
onPageChanged aWhat
Definition: FeedWriter.js:1392
onPageChanged onBeginUpdateBatch
Definition: FeedWriter.js:1395
function cleanup()
onPageChanged onTitleChanged
Definition: FeedWriter.js:1395
const Cr
const Ci
onPageChanged onDeleteURI
Definition: FeedWriter.js:1395
onPageChanged onClearHistory
Definition: FeedWriter.js:1395
let observer
var cm