browser_privatebrowsing_forgetthissite.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 Forget This Site command is hidden in private
39 // browsing mode.
40 
41 function test() {
42  // initialization
43  let pb = Cc["@mozilla.org/privatebrowsing;1"].
44  getService(Ci.nsIPrivateBrowsingService);
45  let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
46  getService(Ci.nsIWindowWatcher);
48 
49  // Add a history entry.
50  const TEST_URI = "http://www.mozilla.org/privatebrowsing";
51  ok(PlacesUtils, "checking PlacesUtils, running in chrome context?");
52  let history = PlacesUtils.history;
53  let visitId = history.addVisit(PlacesUtils._uri(TEST_URI), Date.now() * 1000,
54  null, PlacesUtils.history.TRANSITION_TYPED, false, 0);
55  ok(visitId > 0, TEST_URI + " successfully marked visited");
56 
57  function testForgetThisSiteVisibility(expected, funcNext) {
58  let observer = {
59  observe: function(aSubject, aTopic, aData) {
60  if (aTopic === "domwindowopened") {
61  ww.unregisterNotification(this);
62  let organizer = aSubject.QueryInterface(Ci.nsIDOMWindow);
63  organizer.addEventListener("load", function onLoad(event) {
64  organizer.removeEventListener("load", onLoad, false);
65  executeSoon(function () {
66  // Select History in the left pane.
67  let PO = organizer.PlacesOrganizer;
68  PO.selectLeftPaneQuery('History');
69  let histContainer = PO._places.selectedNode.QueryInterface(Ci.nsINavHistoryContainerResultNode);
70  histContainer.containerOpen = true;
71  PO._places.selectNode(histContainer.getChild(0));
72  // Select the first history entry.
73  let doc = organizer.document;
74  let tree = PO._content;
75  let selection = tree.view.selection;
76  selection.clearSelection();
77  selection.rangedSelect(0, 0, true);
78  is(tree.selectedNode.uri, TEST_URI, "The correct history item has been selected");
79  // Open the context menu
80  let contextmenu = doc.getElementById("placesContext");
81  contextmenu.addEventListener("popupshown", function() {
82  contextmenu.removeEventListener("popupshown", arguments.callee, false);
83  let forgetThisSite = doc.getElementById("placesContext_deleteHost");
84  is(forgetThisSite.hidden, !expected,
85  "The Forget This Site menu item should " + (expected ? "not " : "") + "be hidden");
86  let forgetThisSiteCmd = doc.getElementById("placesCmd_deleteDataHost");
87  if (forgetThisSiteCmd.disabled, !expected,
88  "The Forget This Site command should " + (expected ? "not " : "") + "be disabled");
89  // Close the context menu
90  contextmenu.hidePopup();
91  // Close Library window.
92  organizer.close();
93  // Proceed
94  funcNext();
95  }, false);
96  let event = document.createEvent("MouseEvents");
97  event.initMouseEvent("contextmenu", true, true, organizer, 0,
98  0, 0, 0, 0, false, false, false, false,
99  0, null);
100  tree.dispatchEvent(event);
101  });
102  }, false);
103  }
104  }
105  };
106 
107  ww.registerNotification(observer);
108  ww.openWindow(null,
109  "chrome://browser/content/places/places.xul",
110  "",
111  "chrome,toolbar=yes,dialog=no,resizable",
112  null);
113  }
114 
115  testForgetThisSiteVisibility(true, function() {
116  // Enter private browsing mode
117  pb.privateBrowsingEnabled = true;
118  testForgetThisSiteVisibility(false, function() {
119  // Leave private browsing mode
120  pb.privateBrowsingEnabled = false;
121  testForgetThisSiteVisibility(true, function() {
122  // Cleanup
123  history.QueryInterface(Ci.nsIBrowserHistory)
124  .removeAllPages();
125  finish();
126  });
127  });
128  });
129 }
const Cc
var history
function doc() browser.contentDocument
var event
getService(Ci.sbIFaceplateManager)
Lastfm onLoad
Definition: mini.js:36
waitForExplicitFinish()
return null
Definition: FeedWriter.js:1143
var expected
return!aWindow arguments!aWindow arguments[0]
const Ci
let observer
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe