browser/fuel/test/browser_Bookmarks.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 var gLastFolderAction = "";
michael@0 2 var gLastBookmarkAction = "";
michael@0 3 var gLastRootAction = "";
michael@0 4
michael@0 5 function url(spec) {
michael@0 6 return Services.io.newURI(spec, null, null);
michael@0 7 }
michael@0 8
michael@0 9 function test() {
michael@0 10 // Some very basic tests on the tags root
michael@0 11 var tags = Application.bookmarks.tags;
michael@0 12 ok(tags, "Check access to bookmark tags root");
michael@0 13 ok(!tags.parent, "Check tags parent (should be null)");
michael@0 14
michael@0 15 //----------------------------------------------
michael@0 16
michael@0 17 // Some very basic tests on the unfiled root
michael@0 18 var unfiled = Application.bookmarks.unfiled;
michael@0 19 ok(unfiled, "Check access to bookmark unfiled root");
michael@0 20 ok(!unfiled.parent, "Check unfiled parent (should be null)");
michael@0 21
michael@0 22 //----------------------------------------------
michael@0 23
michael@0 24 // Some basic tests on the toolbar root
michael@0 25 var toolbar = Application.bookmarks.toolbar;
michael@0 26 ok(toolbar, "Check access to bookmark toolbar root");
michael@0 27 ok(!toolbar.parent, "Check toolbar parent (should be null)");
michael@0 28
michael@0 29 var toolbarKidCount = toolbar.children.length;
michael@0 30
michael@0 31 // test adding folders
michael@0 32 var testFolderToolbar = toolbar.addFolder("FUEL in Toolbar");
michael@0 33 ok(testFolderToolbar, "Check folder creation");
michael@0 34 is(testFolderToolbar.type, "folder", "Check 'folder.type' after creation");
michael@0 35 ok(testFolderToolbar.parent, "Check parent after folder creation");
michael@0 36
michael@0 37 toolbarKidCount++;
michael@0 38 is(toolbar.children.length, toolbarKidCount, "Check toolbar folder child count after adding a child folder");
michael@0 39
michael@0 40 //----------------------------------------------
michael@0 41
michael@0 42 // Main testing is done on the bookmarks menu root
michael@0 43 var root = Application.bookmarks.menu;
michael@0 44 ok(root, "Check access to bookmark root");
michael@0 45 ok(!root.parent, "Check root parent (should be null)");
michael@0 46
michael@0 47 var rootKidCount = root.children.length;
michael@0 48
michael@0 49 // test adding folders
michael@0 50 var testFolder = root.addFolder("FUEL");
michael@0 51 ok(testFolder, "Check folder creation");
michael@0 52 is(testFolder.type, "folder", "Check 'folder.type' after creation");
michael@0 53 ok(testFolder.parent, "Check parent after folder creation");
michael@0 54
michael@0 55 rootKidCount++;
michael@0 56 is(root.children.length, rootKidCount, "Check root folder child count after adding a child folder");
michael@0 57
michael@0 58 // test modifying a folder
michael@0 59 testFolder.events.addListener("change", onFolderChange);
michael@0 60 testFolder.description = "FUEL folder";
michael@0 61 is(testFolder.description, "FUEL folder", "Check setting 'folder.description'");
michael@0 62 is(gLastFolderAction, "bookmarkProperties/description", "Check event handler for setting 'folder.description'");
michael@0 63
michael@0 64 testFolder.title = "fuel-is-cool";
michael@0 65 is(testFolder.title, "fuel-is-cool", "Check setting 'folder.title'");
michael@0 66 is(gLastFolderAction, "title", "Check event handler for setting 'folder.title'");
michael@0 67
michael@0 68 testFolder.annotations.set("testing/folder", "annotate-this", 0);
michael@0 69 ok(testFolder.annotations.has("testing/folder"), "Checking existence of added annotation");
michael@0 70 is(gLastFolderAction, "testing/folder", "Check event handler for setting annotation");
michael@0 71 gLastFolderAction = "";
michael@0 72 is(testFolder.annotations.get("testing/folder"), "annotate-this", "Checking existence of added annotation");
michael@0 73 testFolder.annotations.remove("testing/folder");
michael@0 74 ok(!testFolder.annotations.has("testing/folder"), "Checking existence of removed annotation");
michael@0 75 is(gLastFolderAction, "testing/folder", "Check event handler for removing annotation");
michael@0 76
michael@0 77 testFolder.events.addListener("addchild", onFolderAddChild);
michael@0 78 testFolder.events.addListener("removechild", onFolderRemoveChild);
michael@0 79
michael@0 80 // test adding a bookmark
michael@0 81 var testBookmark = testFolder.addBookmark("Mozilla", url("https://www.mozilla.org/"));
michael@0 82 ok(testBookmark, "Check bookmark creation");
michael@0 83 ok(testBookmark.parent, "Check parent after bookmark creation");
michael@0 84 is(gLastFolderAction, "addchild", "Check event handler for adding a child to a folder");
michael@0 85 is(testBookmark.type, "bookmark", "Check 'bookmark.type' after creation");
michael@0 86 is(testBookmark.title, "Mozilla", "Check 'bookmark.title' after creation");
michael@0 87 is(testBookmark.uri.spec, "https://www.mozilla.org/", "Check 'bookmark.uri' after creation");
michael@0 88
michael@0 89 is(testFolder.children.length, 1, "Check test folder child count after adding a child bookmark");
michael@0 90
michael@0 91 // test modifying a bookmark
michael@0 92 testBookmark.events.addListener("change", onBookmarkChange);
michael@0 93 testBookmark.description = "mozcorp";
michael@0 94 is(testBookmark.description, "mozcorp", "Check setting 'bookmark.description'");
michael@0 95 is(gLastBookmarkAction, "bookmarkProperties/description", "Check event handler for setting 'bookmark.description'");
michael@0 96
michael@0 97 testBookmark.keyword = "moz"
michael@0 98 is(testBookmark.keyword, "moz", "Check setting 'bookmark.keyword'");
michael@0 99 is(gLastBookmarkAction, "keyword", "Check event handler for setting 'bookmark.keyword'");
michael@0 100
michael@0 101 testBookmark.title = "MozCorp"
michael@0 102 is(testBookmark.title, "MozCorp", "Check setting 'bookmark.title'");
michael@0 103 is(gLastBookmarkAction, "title", "Check event handler for setting 'bookmark.title'");
michael@0 104
michael@0 105 testBookmark.uri = url("http://www.mozilla.org/");
michael@0 106 is(testBookmark.uri.spec, "http://www.mozilla.org/", "Check setting 'bookmark.uri'");
michael@0 107 is(gLastBookmarkAction, "uri", "Check event handler for setting 'bookmark.uri'");
michael@0 108
michael@0 109 // test adding and removing a bookmark annotation
michael@0 110 testBookmark.annotations.set("testing/bookmark", "annotate-this", 0);
michael@0 111 ok(testBookmark.annotations.has("testing/bookmark"), "Checking existence of added annotation");
michael@0 112 is(gLastBookmarkAction, "testing/bookmark", "Check event handler for setting annotation");
michael@0 113 gLastBookmarkAction = "";
michael@0 114 is(testBookmark.annotations.get("testing/bookmark"), "annotate-this", "Checking existence of added annotation");
michael@0 115 testBookmark.annotations.remove("testing/bookmark");
michael@0 116 ok(!testBookmark.annotations.has("testing/bookmark"), "Checking existence of removed annotation");
michael@0 117 is(gLastBookmarkAction, "testing/bookmark", "Check event handler for removing annotation");
michael@0 118 is(testBookmark.annotations.get("testing/bookmark"), null, "Check existence of a missing annotation");
michael@0 119
michael@0 120 // quick annotation type tests
michael@0 121 testBookmark.annotations.set("testing/bookmark/string", "annotate-this", 0);
michael@0 122 ok(testBookmark.annotations.has("testing/bookmark/string"), "Checking existence of added string annotation");
michael@0 123 is(testBookmark.annotations.get("testing/bookmark/string"), "annotate-this", "Checking value of added string annotation");
michael@0 124 is(gLastBookmarkAction, "testing/bookmark/string", "Check event handler for setting annotation");
michael@0 125 gLastBookmarkAction = "";
michael@0 126 testBookmark.annotations.set("testing/bookmark/int", 100, 0);
michael@0 127 ok(testBookmark.annotations.has("testing/bookmark/int"), "Checking existence of added integer annotation");
michael@0 128 is(testBookmark.annotations.get("testing/bookmark/int"), 100, "Checking value of added integer annotation");
michael@0 129 is(gLastBookmarkAction, "testing/bookmark/int", "Check event handler for setting annotation");
michael@0 130 gLastBookmarkAction = "";
michael@0 131 testBookmark.annotations.set("testing/bookmark/double", 3.333, 0);
michael@0 132 ok(testBookmark.annotations.has("testing/bookmark/double"), "Checking existence of added double annotation");
michael@0 133 is(testBookmark.annotations.get("testing/bookmark/double"), 3.333, "Checking value of added double annotation");
michael@0 134 is(gLastBookmarkAction, "testing/bookmark/double", "Check event handler for setting annotation");
michael@0 135 gLastBookmarkAction = "";
michael@0 136
michael@0 137 // test names array - NOTE: "bookmarkProperties/description" is an annotation too
michael@0 138 var names = testBookmark.annotations.names;
michael@0 139 ok(names.some(function (f) f == "bookmarkProperties/description"), "Checking for description annotation");
michael@0 140 ok(names.some(function (f) f == "testing/bookmark/string"), "Checking for string test annotation");
michael@0 141 ok(names.some(function (f) f == "testing/bookmark/int"), "Checking for int test annotation");
michael@0 142 ok(names.some(function (f) f == "testing/bookmark/double"), "Checking for double test annotation");
michael@0 143
michael@0 144 // test adding a separator
michael@0 145 var testSeparator = testFolder.addSeparator();
michael@0 146 ok(testSeparator, "Check bookmark creation");
michael@0 147 ok(testSeparator.parent, "Check parent after separator creation");
michael@0 148 is(gLastFolderAction, "addchild", "Check event handler for adding a child separator to a folder");
michael@0 149 is(testSeparator.type, "separator", "Check 'bookmark.type' after separator creation");
michael@0 150
michael@0 151 is(testFolder.children.length, 2, "Check test folder child count after adding a child separator");
michael@0 152
michael@0 153 // test removing separator
michael@0 154 testSeparator.events.addListener("remove", onBookmarkRemove);
michael@0 155 testSeparator.remove();
michael@0 156 is(gLastBookmarkAction, "remove", "Check event handler for removing separator");
michael@0 157 is(gLastFolderAction, "removechild", "Check event handler for removing a child separator from a folder");
michael@0 158 is(testFolder.children.length, 1, "Check test folder child count after removing a child separator");
michael@0 159
michael@0 160 // test removing bookmark
michael@0 161 testBookmark.events.addListener("remove", onBookmarkRemove);
michael@0 162 testBookmark.remove();
michael@0 163 is(gLastBookmarkAction, "remove", "Check event handler for removing bookmark");
michael@0 164 is(gLastFolderAction, "removechild", "Check event handler for removing a child from a folder");
michael@0 165 is(testFolder.children.length, 0, "Check test folder child count after removing a child bookmark");
michael@0 166
michael@0 167 // test removing a folder
michael@0 168 testFolder.events.addListener("remove", onFolderRemove);
michael@0 169 testFolder.remove();
michael@0 170 is(gLastFolderAction, "remove", "Check event handler for removing child folder");
michael@0 171 rootKidCount--;
michael@0 172 is(root.children.length, rootKidCount, "Check root folder child count after removing a child folder");
michael@0 173
michael@0 174 // test moving between folders
michael@0 175 var testFolderA = root.addFolder("folder-a");
michael@0 176 var testFolderB = root.addFolder("folder-b");
michael@0 177
michael@0 178 var testMove = testFolderA.addBookmark("Mozilla", url("https://www.mozilla.org/"));
michael@0 179 testMove.events.addListener("move", onBookmarkMove);
michael@0 180 is(testMove.parent.title, "folder-a", "Checking for new parent before moving bookmark");
michael@0 181
michael@0 182 testMove.parent = testFolderB;
michael@0 183 is(testMove.parent.title, "folder-b", "Checking for new parent after moving bookmark");
michael@0 184 is(gLastBookmarkAction, "move", "Checking for event handler after moving bookmark");
michael@0 185
michael@0 186 // test moving a folder
michael@0 187 testFolderA.events.addListener("move", onFolderMove);
michael@0 188 testFolderA.parent = testFolderB;
michael@0 189 is(testFolderA.parent.title, "folder-b", "Checking for new parent after moving folder");
michael@0 190 is(gLastFolderAction, "move", "Checking for event handler after moving folder");
michael@0 191
michael@0 192 // test events on the root
michael@0 193 root.events.addListener("add", onRootAdd);
michael@0 194 root.events.addListener("remove", onRootRemove);
michael@0 195 root.events.addListener("change", onRootChange);
michael@0 196 var testFolderC = root.addFolder("folder-c");
michael@0 197 is(gLastRootAction, "add");
michael@0 198
michael@0 199 root.events.removeListener("add", onRootAdd);
michael@0 200 gLastRootAction = "";
michael@0 201 var testFolderD = root.addFolder("folder-d");
michael@0 202 is(gLastRootAction, "");
michael@0 203
michael@0 204 testFolderC.remove();
michael@0 205 is(gLastRootAction, "remove");
michael@0 206
michael@0 207 testFolderD.description = "Foo";
michael@0 208 is(gLastRootAction, "bookmarkProperties/description");
michael@0 209 }
michael@0 210
michael@0 211 function onFolderChange(evt) {
michael@0 212 gLastFolderAction = evt.data;
michael@0 213 }
michael@0 214
michael@0 215 function onFolderRemove(evt) {
michael@0 216 gLastFolderAction = evt.type;
michael@0 217 }
michael@0 218
michael@0 219 function onFolderAddChild(evt) {
michael@0 220 gLastFolderAction = evt.type;
michael@0 221 }
michael@0 222
michael@0 223 function onFolderRemoveChild(evt) {
michael@0 224 gLastFolderAction = evt.type;
michael@0 225 }
michael@0 226
michael@0 227 function onFolderMove(evt) {
michael@0 228 gLastFolderAction = evt.type;
michael@0 229 }
michael@0 230
michael@0 231 function onBookmarkChange(evt) {
michael@0 232 gLastBookmarkAction = evt.data;
michael@0 233 }
michael@0 234
michael@0 235 function onBookmarkRemove(evt) {
michael@0 236 gLastBookmarkAction = evt.type;
michael@0 237 }
michael@0 238
michael@0 239 function onBookmarkMove(evt) {
michael@0 240 gLastBookmarkAction = evt.type;
michael@0 241 }
michael@0 242
michael@0 243 function onRootAdd(evt) {
michael@0 244 gLastRootAction = evt.type;
michael@0 245 }
michael@0 246
michael@0 247 function onRootRemove(evt) {
michael@0 248 gLastRootAction = evt.type;
michael@0 249 }
michael@0 250
michael@0 251 function onRootChange(evt) {
michael@0 252 gLastRootAction = evt.data;
michael@0 253 }

mercurial