browser/components/places/tests/browser/browser_416459_cut.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

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/
     3  */
     5 const TEST_URL = "http://example.com/";
     7 let gLibrary;
     8 let gItemId;
     9 let PlacesOrganizer;
    10 let ContentTree;
    12 function test() {
    13   waitForExplicitFinish();
    14   gLibrary = openLibrary(onLibraryReady);
    15 }
    17 function onLibraryReady() {
    18   PlacesOrganizer = gLibrary.PlacesOrganizer;
    19   ContentTree = gLibrary.ContentTree;
    21   // Sanity checks.
    22   ok(PlacesUtils, "PlacesUtils in scope");
    23   ok(PlacesUIUtils, "PlacesUIUtils in scope");
    24   ok(PlacesOrganizer, "PlacesOrganizer in scope");
    25   ok(ContentTree, "ContentTree is in scope");
    27   gItemId = PlacesUtils.bookmarks.insertBookmark(
    28     PlacesUtils.toolbarFolderId, NetUtil.newURI(TEST_URL),
    29     PlacesUtils.bookmarks.DEFAULT_INDEX, "test"
    30   );
    32   selectBookmarkIn("BookmarksToolbar");
    34   waitForClipboard(function(aData) !!aData,
    35                    cutSelection,
    36                    onClipboardReady,
    37                    PlacesUtils.TYPE_X_MOZ_PLACE);
    38 }
    40 function selectBookmarkIn(aLeftPaneQuery) {
    41   info("Selecting " + aLeftPaneQuery + " in the left pane");
    42   PlacesOrganizer.selectLeftPaneQuery(aLeftPaneQuery);
    43   let rootId = PlacesUtils.getConcreteItemId(PlacesOrganizer._places.selectedNode);
    44   is(PlacesUtils.bookmarks.getFolderIdForItem(gItemId), rootId,
    45      "Bookmark has the right parent");
    46   info("Selecting the bookmark in the right pane");
    47   ContentTree.view.selectItems([gItemId]);
    48   let bookmarkNode = ContentTree.view.selectedNode;
    49   is(bookmarkNode.uri, TEST_URL, "Found the expected bookmark");
    50 }
    52 function cutSelection() {
    53   info("Cutting selection");
    54   ContentTree.view.controller.cut();
    55 }
    57 function pasteClipboard(aLeftPaneQuery) {
    58   info("Selecting " + aLeftPaneQuery + " in the left pane");
    59   PlacesOrganizer.selectLeftPaneQuery(aLeftPaneQuery);
    60   info("Pasting clipboard");
    61   ContentTree.view.controller.paste();
    62 }
    64 function onClipboardReady() {
    65   pasteClipboard("UnfiledBookmarks");
    66   selectBookmarkIn("UnfiledBookmarks");
    68   // Cleanup.
    69   gLibrary.close();
    70   PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
    71   finish();
    72 }

mercurial