browser/components/places/tests/browser/browser_forgetthissite_single.js

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 // This test makes sure that the Forget This Site command is hidden for multiple
michael@0 6 // selections.
michael@0 7 function test() {
michael@0 8 // initialization
michael@0 9 waitForExplicitFinish();
michael@0 10
michael@0 11 // Add a history entry.
michael@0 12 let TEST_URIs = ["http://www.mozilla.org/test1", "http://www.mozilla.org/test2"];
michael@0 13 ok(PlacesUtils, "checking PlacesUtils, running in chrome context?");
michael@0 14 let places = [];
michael@0 15 TEST_URIs.forEach(function(TEST_URI) {
michael@0 16 places.push({uri: PlacesUtils._uri(TEST_URI),
michael@0 17 transition: PlacesUtils.history.TRANSITION_TYPED});
michael@0 18 });
michael@0 19 addVisits(places, window, function() {
michael@0 20 testForgetThisSiteVisibility(1, function() {
michael@0 21 testForgetThisSiteVisibility(2, function() {
michael@0 22 // Cleanup
michael@0 23 waitForClearHistory(finish);
michael@0 24 });
michael@0 25 });
michael@0 26 });
michael@0 27
michael@0 28 function testForgetThisSiteVisibility(selectionCount, funcNext) {
michael@0 29 openLibrary(function (organizer) {
michael@0 30 // Select History in the left pane.
michael@0 31 organizer.PlacesOrganizer.selectLeftPaneQuery('History');
michael@0 32 let PO = organizer.PlacesOrganizer;
michael@0 33 let histContainer = PO._places.selectedNode.QueryInterface(Ci.nsINavHistoryContainerResultNode);
michael@0 34 histContainer.containerOpen = true;
michael@0 35 PO._places.selectNode(histContainer.getChild(0));
michael@0 36 // Select the first history entry.
michael@0 37 let doc = organizer.document;
michael@0 38 let tree = PO._content;
michael@0 39 let selection = tree.view.selection;
michael@0 40 selection.clearSelection();
michael@0 41 selection.rangedSelect(0, selectionCount - 1, true);
michael@0 42 is(selection.count, selectionCount,
michael@0 43 "The selected range is as big as expected");
michael@0 44 // Open the context menu
michael@0 45 let contextmenu = doc.getElementById("placesContext");
michael@0 46 contextmenu.addEventListener("popupshown", function() {
michael@0 47 contextmenu.removeEventListener("popupshown", arguments.callee, true);
michael@0 48 let forgetThisSite = doc.getElementById("placesContext_deleteHost");
michael@0 49 let hideForgetThisSite = (selectionCount != 1);
michael@0 50 is(forgetThisSite.hidden, hideForgetThisSite,
michael@0 51 "The Forget this site menu item should " + (hideForgetThisSite ? "" : "not ") +
michael@0 52 "be hidden with " + selectionCount + " items selected");
michael@0 53 // Close the context menu
michael@0 54 contextmenu.hidePopup();
michael@0 55 // Wait for the Organizer window to actually be closed
michael@0 56 organizer.addEventListener("unload", function () {
michael@0 57 organizer.removeEventListener("unload", arguments.callee, false);
michael@0 58 // Proceed
michael@0 59 funcNext();
michael@0 60 }, false);
michael@0 61 // Close Library window.
michael@0 62 organizer.close();
michael@0 63 }, true);
michael@0 64 // Get cell coordinates
michael@0 65 var x = {}, y = {}, width = {}, height = {};
michael@0 66 tree.treeBoxObject.getCoordsForCellItem(0, tree.columns[0], "text",
michael@0 67 x, y, width, height);
michael@0 68 // Initiate a context menu for the selected cell
michael@0 69 EventUtils.synthesizeMouse(tree.body, x.value + width.value / 2, y.value + height.value / 2, {type: "contextmenu"}, organizer);
michael@0 70 });
michael@0 71 }
michael@0 72 }
michael@0 73

mercurial