1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/unit/test_broken_folderShortcut_result.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +function run_test() 1.8 +{ 1.9 + run_next_test(); 1.10 +} 1.11 + 1.12 +add_task(function test_execute() 1.13 +{ 1.14 + PlacesUtils.bookmarks.insertBookmark( 1.15 + PlacesUtils.unfiledBookmarksFolderId, NetUtil.newURI("http://1.moz.org/"), 1.16 + PlacesUtils.bookmarks.DEFAULT_INDEX, "Bookmark 1" 1.17 + ); 1.18 + let id1 = PlacesUtils.bookmarks.insertBookmark( 1.19 + PlacesUtils.unfiledBookmarksFolderId, NetUtil.newURI("place:folder=1234"), 1.20 + PlacesUtils.bookmarks.DEFAULT_INDEX, "Shortcut 1" 1.21 + ); 1.22 + let id2 = PlacesUtils.bookmarks.insertBookmark( 1.23 + PlacesUtils.unfiledBookmarksFolderId, NetUtil.newURI("place:folder=-1"), 1.24 + PlacesUtils.bookmarks.DEFAULT_INDEX, "Shortcut 2" 1.25 + ); 1.26 + PlacesUtils.bookmarks.insertBookmark( 1.27 + PlacesUtils.unfiledBookmarksFolderId, NetUtil.newURI("http://2.moz.org/"), 1.28 + PlacesUtils.bookmarks.DEFAULT_INDEX, "Bookmark 2" 1.29 + ); 1.30 + 1.31 + // Add also a simple visit. 1.32 + yield promiseAddVisits(uri(("http://3.moz.org/"))); 1.33 + 1.34 + // Query containing a broken folder shortcuts among results. 1.35 + let query = PlacesUtils.history.getNewQuery(); 1.36 + query.setFolders([PlacesUtils.unfiledBookmarksFolderId], 1); 1.37 + let options = PlacesUtils.history.getNewQueryOptions(); 1.38 + let root = PlacesUtils.history.executeQuery(query, options).root; 1.39 + root.containerOpen = true; 1.40 + 1.41 + do_check_eq(root.childCount, 4); 1.42 + 1.43 + let shortcut = root.getChild(1); 1.44 + do_check_eq(shortcut.uri, "place:folder=1234"); 1.45 + PlacesUtils.asContainer(shortcut); 1.46 + shortcut.containerOpen = true; 1.47 + do_check_eq(shortcut.childCount, 0); 1.48 + shortcut.containerOpen = false; 1.49 + // Remove the broken shortcut while the containing result is open. 1.50 + PlacesUtils.bookmarks.removeItem(id1); 1.51 + do_check_eq(root.childCount, 3); 1.52 + 1.53 + shortcut = root.getChild(1); 1.54 + do_check_eq(shortcut.uri, "place:folder=-1"); 1.55 + PlacesUtils.asContainer(shortcut); 1.56 + shortcut.containerOpen = true; 1.57 + do_check_eq(shortcut.childCount, 0); 1.58 + shortcut.containerOpen = false; 1.59 + // Remove the broken shortcut while the containing result is open. 1.60 + PlacesUtils.bookmarks.removeItem(id2); 1.61 + do_check_eq(root.childCount, 2); 1.62 + 1.63 + root.containerOpen = false; 1.64 + 1.65 + // Broken folder shortcut as root node. 1.66 + let query = PlacesUtils.history.getNewQuery(); 1.67 + query.setFolders([1234], 1); 1.68 + let options = PlacesUtils.history.getNewQueryOptions(); 1.69 + let root = PlacesUtils.history.executeQuery(query, options).root; 1.70 + root.containerOpen = true; 1.71 + do_check_eq(root.childCount, 0); 1.72 + root.containerOpen = false; 1.73 + 1.74 + // Broken folder shortcut as root node with folder=-1. 1.75 + query = PlacesUtils.history.getNewQuery(); 1.76 + query.setFolders([-1], 1); 1.77 + options = PlacesUtils.history.getNewQueryOptions(); 1.78 + root = PlacesUtils.history.executeQuery(query, options).root; 1.79 + root.containerOpen = true; 1.80 + do_check_eq(root.childCount, 0); 1.81 + root.containerOpen = false; 1.82 +});