browser_forgetthissite_single.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 Places test code.
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 for multiple
39 // selections.
40 
41 function test() {
42  // initialization
43  let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
44  getService(Ci.nsIWindowWatcher);
46 
47  // Add a history entry.
48  let TEST_URIs = ["http://www.mozilla.org/test1", "http://www.mozilla.org/test2"];
49  ok(PlacesUtils, "checking PlacesUtils, running in chrome context?");
50  let history = PlacesUtils.history;
51  TEST_URIs.forEach(function(TEST_URI) {
52  let visitId = history.addVisit(PlacesUtils._uri(TEST_URI), Date.now() * 1000,
53  null, PlacesUtils.history.TRANSITION_TYPED, false, 0);
54  ok(visitId > 0, TEST_URI + " successfully marked visited");
55  });
56 
57  function testForgetThisSiteVisibility(selectionCount, 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  organizer.PlacesOrganizer.selectLeftPaneQuery('History');
68  let PO = organizer.PlacesOrganizer;
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, selectionCount - 1, true);
78  is(selection.count, selectionCount,
79  "The selected range is as big as expected");
80  // Open the context menu
81  let contextmenu = doc.getElementById("placesContext");
82  contextmenu.addEventListener("popupshown", function() {
83  contextmenu.removeEventListener("popupshown", arguments.callee, false);
84  let forgetThisSite = doc.getElementById("placesContext_deleteHost");
85  let hideForgetThisSite = (selectionCount != 1);
86  is(forgetThisSite.hidden, hideForgetThisSite,
87  "The Forget this site menu item should " + (hideForgetThisSite ? "" : "not ") +
88  "be hidden with " + selectionCount + " items selected");
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(1, function() {
116  testForgetThisSiteVisibility(2, function() {
117  // Cleanup
118  history.QueryInterface(Ci.nsIBrowserHistory)
119  .removeAllPages();
120  finish();
121  });
122  });
123 }
const Cc
var history
function doc() browser.contentDocument
var event
getService(Ci.sbIFaceplateManager)
function test()
Lastfm onLoad
Definition: mini.js:36
waitForExplicitFinish()
return null
Definition: FeedWriter.js:1143
return!aWindow arguments!aWindow arguments[0]
const Ci
let observer
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe