browser/components/places/tests/browser/browser_library_batch_delete.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 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Tests that Library handles correctly batch deletes.
michael@0 6 */
michael@0 7
michael@0 8 const TEST_URL = "http://www.batch.delete.me/";
michael@0 9
michael@0 10 var gTests = [];
michael@0 11 var gLibrary;
michael@0 12
michael@0 13 //------------------------------------------------------------------------------
michael@0 14
michael@0 15 gTests.push({
michael@0 16 desc: "Create and batch remove bookmarks",
michael@0 17 run: function() {
michael@0 18 let testURI = makeURI(TEST_URL);
michael@0 19 PlacesUtils.history.runInBatchMode({
michael@0 20 runBatched: function (aUserData) {
michael@0 21 // Create a folder in unserted and populate it with bookmarks.
michael@0 22 let folder = PlacesUtils.bookmarks.createFolder(
michael@0 23 PlacesUtils.unfiledBookmarksFolderId, "deleteme",
michael@0 24 PlacesUtils.bookmarks.DEFAULT_INDEX
michael@0 25 );
michael@0 26 PlacesUtils.bookmarks.createFolder(
michael@0 27 PlacesUtils.unfiledBookmarksFolderId, "keepme",
michael@0 28 PlacesUtils.bookmarks.DEFAULT_INDEX
michael@0 29 );
michael@0 30 for (let i = 0; i < 10; i++) {
michael@0 31 PlacesUtils.bookmarks.insertBookmark(folder,
michael@0 32 testURI,
michael@0 33 PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 34 "bm" + i);
michael@0 35 }
michael@0 36 }
michael@0 37 }, null);
michael@0 38
michael@0 39 // Select and open the left pane "History" query.
michael@0 40 let PO = gLibrary.PlacesOrganizer;
michael@0 41 PO.selectLeftPaneQuery("UnfiledBookmarks");
michael@0 42 isnot(PO._places.selectedNode, null, "Selected unsorted bookmarks");
michael@0 43
michael@0 44 let unsortedNode = PlacesUtils.asContainer(PO._places.selectedNode);
michael@0 45 unsortedNode.containerOpen = true;
michael@0 46 is(unsortedNode.childCount, 2, "Unsorted node has 2 children");
michael@0 47 let folderNode = unsortedNode.getChild(0);
michael@0 48 is(folderNode.title, "deleteme", "Folder found in unsorted bookmarks");
michael@0 49 // Check delete command is available.
michael@0 50 PO._places.selectNode(folderNode);
michael@0 51 is(PO._places.selectedNode.title, "deleteme", "Folder node selected");
michael@0 52 ok(PO._places.controller.isCommandEnabled("cmd_delete"),
michael@0 53 "Delete command is enabled");
michael@0 54 // Execute the delete command and check bookmark has been removed.
michael@0 55 PO._places.controller.doCommand("cmd_delete");
michael@0 56 ok(!PlacesUtils.bookmarks.isBookmarked(testURI),
michael@0 57 "Bookmark has been correctly removed");
michael@0 58 // Test live update.
michael@0 59 is(unsortedNode.childCount, 1, "Unsorted node has 1 child");
michael@0 60 is(PO._places.selectedNode.title, "keepme", "Folder node selected");
michael@0 61 unsortedNode.containerOpen = false;
michael@0 62 nextTest();
michael@0 63 }
michael@0 64 });
michael@0 65
michael@0 66 //------------------------------------------------------------------------------
michael@0 67
michael@0 68 gTests.push({
michael@0 69 desc: "Ensure correct selection and functionality in Library",
michael@0 70 run: function() {
michael@0 71 let PO = gLibrary.PlacesOrganizer;
michael@0 72 let ContentTree = gLibrary.ContentTree;
michael@0 73 // Move selection forth and back.
michael@0 74 PO.selectLeftPaneQuery("History");
michael@0 75 PO.selectLeftPaneQuery("UnfiledBookmarks");
michael@0 76 // Now select the "keepme" folder in the right pane and delete it.
michael@0 77 ContentTree.view.selectNode(ContentTree.view.result.root.getChild(0));
michael@0 78 is(ContentTree.view.selectedNode.title, "keepme",
michael@0 79 "Found folder in content pane");
michael@0 80 // Test live update.
michael@0 81 PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
michael@0 82 makeURI(TEST_URL),
michael@0 83 PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 84 "bm");
michael@0 85 is(ContentTree.view.result.root.childCount, 2,
michael@0 86 "Right pane was correctly updated");
michael@0 87 nextTest();
michael@0 88 }
michael@0 89 });
michael@0 90
michael@0 91 //------------------------------------------------------------------------------
michael@0 92
michael@0 93 function test() {
michael@0 94 waitForExplicitFinish();
michael@0 95 registerCleanupFunction(function () {
michael@0 96 PlacesUtils.bookmarks
michael@0 97 .removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
michael@0 98 });
michael@0 99
michael@0 100 gLibrary = openLibrary(nextTest);
michael@0 101 }
michael@0 102
michael@0 103 function nextTest() {
michael@0 104 if (gTests.length) {
michael@0 105 var test = gTests.shift();
michael@0 106 info("Start of test: " + test.desc);
michael@0 107 test.run();
michael@0 108 }
michael@0 109 else {
michael@0 110 // Close Library window.
michael@0 111 gLibrary.close();
michael@0 112 finish();
michael@0 113 }
michael@0 114 }

mercurial