Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | // Tests functionality of the mozIAsyncLivemarks interface. |
michael@0 | 5 | |
michael@0 | 6 | const FEED_URI = NetUtil.newURI("http://feed.rss/"); |
michael@0 | 7 | const SITE_URI = NetUtil.newURI("http://site.org/"); |
michael@0 | 8 | |
michael@0 | 9 | |
michael@0 | 10 | add_task(function test_addLivemark_noArguments_throws() |
michael@0 | 11 | { |
michael@0 | 12 | try { |
michael@0 | 13 | yield PlacesUtils.livemarks.addLivemark(); |
michael@0 | 14 | do_throw("Invoking addLivemark with no arguments should throw"); |
michael@0 | 15 | } catch (ex) { |
michael@0 | 16 | // The error is actually generated by XPConnect. |
michael@0 | 17 | do_check_eq(ex.result, Cr.NS_ERROR_XPC_NOT_ENOUGH_ARGS); |
michael@0 | 18 | } |
michael@0 | 19 | }); |
michael@0 | 20 | |
michael@0 | 21 | add_task(function test_addLivemark_emptyObject_throws() |
michael@0 | 22 | { |
michael@0 | 23 | try { |
michael@0 | 24 | yield PlacesUtils.livemarks.addLivemark({}); |
michael@0 | 25 | do_throw("Invoking addLivemark with empty object should throw"); |
michael@0 | 26 | } catch (ex) { |
michael@0 | 27 | do_check_eq(ex.result, Cr.NS_ERROR_INVALID_ARG); |
michael@0 | 28 | } |
michael@0 | 29 | }); |
michael@0 | 30 | |
michael@0 | 31 | add_task(function test_addLivemark_badParentId_throws() |
michael@0 | 32 | { |
michael@0 | 33 | try { |
michael@0 | 34 | yield PlacesUtils.livemarks.addLivemark({ parentId: "test" }); |
michael@0 | 35 | do_throw("Invoking addLivemark with a bad parent id should throw"); |
michael@0 | 36 | } catch (ex) { |
michael@0 | 37 | do_check_eq(ex.result, Cr.NS_ERROR_INVALID_ARG); |
michael@0 | 38 | } |
michael@0 | 39 | }); |
michael@0 | 40 | |
michael@0 | 41 | add_task(function test_addLivemark_invalidParentId_throws() |
michael@0 | 42 | { |
michael@0 | 43 | try { |
michael@0 | 44 | yield PlacesUtils.livemarks.addLivemark({ parentId: -2 }); |
michael@0 | 45 | do_throw("Invoking addLivemark with an invalid parent id should throw"); |
michael@0 | 46 | } catch (ex) { |
michael@0 | 47 | do_check_eq(ex.result, Cr.NS_ERROR_INVALID_ARG); |
michael@0 | 48 | } |
michael@0 | 49 | }); |
michael@0 | 50 | |
michael@0 | 51 | add_task(function test_addLivemark_noIndex_throws() |
michael@0 | 52 | { |
michael@0 | 53 | try { |
michael@0 | 54 | yield PlacesUtils.livemarks.addLivemark({ |
michael@0 | 55 | parentId: PlacesUtils.unfiledBookmarksFolderId }); |
michael@0 | 56 | do_throw("Invoking addLivemark with no index should throw"); |
michael@0 | 57 | } catch (ex) { |
michael@0 | 58 | do_check_eq(ex.result, Cr.NS_ERROR_INVALID_ARG); |
michael@0 | 59 | } |
michael@0 | 60 | }); |
michael@0 | 61 | |
michael@0 | 62 | add_task(function test_addLivemark_badIndex_throws() |
michael@0 | 63 | { |
michael@0 | 64 | try { |
michael@0 | 65 | yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 66 | { parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 67 | , index: "test" }); |
michael@0 | 68 | do_throw("Invoking addLivemark with a bad index should throw"); |
michael@0 | 69 | } catch (ex) { |
michael@0 | 70 | do_check_eq(ex.result, Cr.NS_ERROR_INVALID_ARG); |
michael@0 | 71 | } |
michael@0 | 72 | }); |
michael@0 | 73 | |
michael@0 | 74 | add_task(function test_addLivemark_invalidIndex_throws() |
michael@0 | 75 | { |
michael@0 | 76 | try { |
michael@0 | 77 | yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 78 | { parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 79 | , index: -2 |
michael@0 | 80 | }); |
michael@0 | 81 | do_throw("Invoking addLivemark with an invalid index should throw"); |
michael@0 | 82 | } catch (ex) { |
michael@0 | 83 | do_check_eq(ex.result, Cr.NS_ERROR_INVALID_ARG); |
michael@0 | 84 | } |
michael@0 | 85 | }); |
michael@0 | 86 | |
michael@0 | 87 | add_task(function test_addLivemark_noFeedURI_throws() |
michael@0 | 88 | { |
michael@0 | 89 | try { |
michael@0 | 90 | yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 91 | { parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 92 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX }); |
michael@0 | 93 | do_throw("Invoking addLivemark with no feedURI should throw"); |
michael@0 | 94 | } catch (ex) { |
michael@0 | 95 | do_check_eq(ex.result, Cr.NS_ERROR_INVALID_ARG); |
michael@0 | 96 | } |
michael@0 | 97 | }); |
michael@0 | 98 | |
michael@0 | 99 | add_task(function test_addLivemark_badFeedURI_throws() |
michael@0 | 100 | { |
michael@0 | 101 | try { |
michael@0 | 102 | yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 103 | { parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 104 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 105 | , feedURI: "test" }); |
michael@0 | 106 | do_throw("Invoking addLivemark with a bad feedURI should throw"); |
michael@0 | 107 | } catch (ex) { |
michael@0 | 108 | do_check_eq(ex.result, Cr.NS_ERROR_INVALID_ARG); |
michael@0 | 109 | } |
michael@0 | 110 | }); |
michael@0 | 111 | |
michael@0 | 112 | add_task(function test_addLivemark_badSiteURI_throws() |
michael@0 | 113 | { |
michael@0 | 114 | try { |
michael@0 | 115 | yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 116 | { parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 117 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 118 | , feedURI: FEED_URI |
michael@0 | 119 | , siteURI: "test" }); |
michael@0 | 120 | do_throw("Invoking addLivemark with a bad siteURI should throw"); |
michael@0 | 121 | } catch (ex) { |
michael@0 | 122 | do_check_eq(ex.result, Cr.NS_ERROR_INVALID_ARG); |
michael@0 | 123 | } |
michael@0 | 124 | }); |
michael@0 | 125 | |
michael@0 | 126 | add_task(function test_addLivemark_badGuid_throws() |
michael@0 | 127 | { |
michael@0 | 128 | try { |
michael@0 | 129 | yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 130 | { parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 131 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 132 | , feedURI: FEED_URI |
michael@0 | 133 | , guid: "123456" }); |
michael@0 | 134 | do_throw("Invoking addLivemark with a bad guid should throw"); |
michael@0 | 135 | } catch (ex) { |
michael@0 | 136 | do_check_eq(ex.result, Cr.NS_ERROR_INVALID_ARG); |
michael@0 | 137 | } |
michael@0 | 138 | }); |
michael@0 | 139 | |
michael@0 | 140 | add_task(function test_addLivemark_badCallback_throws() |
michael@0 | 141 | { |
michael@0 | 142 | try { |
michael@0 | 143 | yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 144 | { parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 145 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 146 | , feedURI: FEED_URI |
michael@0 | 147 | }, "test"); |
michael@0 | 148 | do_throw("Invoking addLivemark with a bad callback should throw"); |
michael@0 | 149 | } catch (ex) { |
michael@0 | 150 | // The error is actually generated by XPConnect. |
michael@0 | 151 | do_check_eq(ex.result, Cr.NS_ERROR_XPC_BAD_CONVERT_JS); |
michael@0 | 152 | } |
michael@0 | 153 | }); |
michael@0 | 154 | |
michael@0 | 155 | add_task(function test_addLivemark_noCallback_succeeds() |
michael@0 | 156 | { |
michael@0 | 157 | let onItemAddedCalled = false; |
michael@0 | 158 | PlacesUtils.bookmarks.addObserver({ |
michael@0 | 159 | __proto__: NavBookmarkObserver.prototype, |
michael@0 | 160 | onItemAdded: function onItemAdded(aItemId, aParentId, aIndex, aItemType, |
michael@0 | 161 | aURI, aTitle) |
michael@0 | 162 | { |
michael@0 | 163 | onItemAddedCalled = true; |
michael@0 | 164 | PlacesUtils.bookmarks.removeObserver(this); |
michael@0 | 165 | do_check_eq(aParentId, PlacesUtils.unfiledBookmarksFolderId); |
michael@0 | 166 | do_check_eq(aIndex, 0); |
michael@0 | 167 | do_check_eq(aItemType, Ci.nsINavBookmarksService.TYPE_FOLDER); |
michael@0 | 168 | do_check_eq(aTitle, "test"); |
michael@0 | 169 | } |
michael@0 | 170 | }, false); |
michael@0 | 171 | |
michael@0 | 172 | yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 173 | { title: "test" |
michael@0 | 174 | , parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 175 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 176 | , feedURI: FEED_URI }); |
michael@0 | 177 | do_check_true(onItemAddedCalled); |
michael@0 | 178 | }); |
michael@0 | 179 | |
michael@0 | 180 | |
michael@0 | 181 | add_task(function test_addLivemark_noSiteURI_succeeds() |
michael@0 | 182 | { |
michael@0 | 183 | let livemark = yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 184 | { title: "test" |
michael@0 | 185 | , parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 186 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 187 | , feedURI: FEED_URI |
michael@0 | 188 | }); |
michael@0 | 189 | do_check_true(livemark.id > 0); |
michael@0 | 190 | do_check_valid_places_guid(livemark.guid); |
michael@0 | 191 | do_check_eq(livemark.title, "test"); |
michael@0 | 192 | do_check_eq(livemark.parentId, PlacesUtils.unfiledBookmarksFolderId); |
michael@0 | 193 | do_check_eq(livemark.index, PlacesUtils.bookmarks.getItemIndex(livemark.id)); |
michael@0 | 194 | do_check_eq(livemark.lastModified, PlacesUtils.bookmarks.getItemLastModified(livemark.id)); |
michael@0 | 195 | do_check_true(livemark.feedURI.equals(FEED_URI)); |
michael@0 | 196 | do_check_eq(livemark.siteURI, null); |
michael@0 | 197 | }); |
michael@0 | 198 | |
michael@0 | 199 | add_task(function test_addLivemark_succeeds() |
michael@0 | 200 | { |
michael@0 | 201 | let livemark = yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 202 | { title: "test" |
michael@0 | 203 | , parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 204 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 205 | , feedURI: FEED_URI |
michael@0 | 206 | , siteURI: SITE_URI |
michael@0 | 207 | }); |
michael@0 | 208 | |
michael@0 | 209 | do_check_true(livemark.id > 0); |
michael@0 | 210 | do_check_valid_places_guid(livemark.guid); |
michael@0 | 211 | do_check_eq(livemark.title, "test"); |
michael@0 | 212 | do_check_eq(livemark.parentId, PlacesUtils.unfiledBookmarksFolderId); |
michael@0 | 213 | do_check_eq(livemark.index, PlacesUtils.bookmarks.getItemIndex(livemark.id)); |
michael@0 | 214 | do_check_eq(livemark.lastModified, PlacesUtils.bookmarks.getItemLastModified(livemark.id)); |
michael@0 | 215 | do_check_true(livemark.feedURI.equals(FEED_URI)); |
michael@0 | 216 | do_check_true(livemark.siteURI.equals(SITE_URI)); |
michael@0 | 217 | do_check_true(PlacesUtils.annotations |
michael@0 | 218 | .itemHasAnnotation(livemark.id, |
michael@0 | 219 | PlacesUtils.LMANNO_FEEDURI)); |
michael@0 | 220 | do_check_true(PlacesUtils.annotations |
michael@0 | 221 | .itemHasAnnotation(livemark.id, |
michael@0 | 222 | PlacesUtils.LMANNO_SITEURI)); |
michael@0 | 223 | }); |
michael@0 | 224 | |
michael@0 | 225 | add_task(function test_addLivemark_bogusid_succeeds() |
michael@0 | 226 | { |
michael@0 | 227 | let livemark = yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 228 | { id: 100 // Should be ignored. |
michael@0 | 229 | , title: "test" |
michael@0 | 230 | , parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 231 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 232 | , feedURI: FEED_URI |
michael@0 | 233 | , siteURI: SITE_URI |
michael@0 | 234 | }); |
michael@0 | 235 | do_check_true(livemark.id > 0); |
michael@0 | 236 | do_check_neq(livemark.id, 100); |
michael@0 | 237 | }); |
michael@0 | 238 | |
michael@0 | 239 | add_task(function test_addLivemark_bogusParent_fails() |
michael@0 | 240 | { |
michael@0 | 241 | try { |
michael@0 | 242 | yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 243 | { title: "test" |
michael@0 | 244 | , parentId: 187 |
michael@0 | 245 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 246 | , feedURI: FEED_URI |
michael@0 | 247 | }); |
michael@0 | 248 | do_throw("Adding a livemark with a bogus parent should fail"); |
michael@0 | 249 | } catch(ex) {} |
michael@0 | 250 | }); |
michael@0 | 251 | |
michael@0 | 252 | add_task(function test_addLivemark_intoLivemark_fails() |
michael@0 | 253 | { |
michael@0 | 254 | let livemark = yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 255 | { title: "test" |
michael@0 | 256 | , parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 257 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 258 | , feedURI: FEED_URI |
michael@0 | 259 | }); |
michael@0 | 260 | do_check_true(Boolean(livemark)); |
michael@0 | 261 | |
michael@0 | 262 | try { |
michael@0 | 263 | yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 264 | { title: "test" |
michael@0 | 265 | , parentId: livemark.id |
michael@0 | 266 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 267 | , feedURI: FEED_URI |
michael@0 | 268 | }); |
michael@0 | 269 | do_throw("Adding a livemark into a livemark should fail"); |
michael@0 | 270 | } catch(ex) {} |
michael@0 | 271 | }); |
michael@0 | 272 | |
michael@0 | 273 | add_task(function test_addLivemark_forceGuid_succeeds() |
michael@0 | 274 | { |
michael@0 | 275 | let checkLivemark = aLivemark => { |
michael@0 | 276 | do_check_eq(aLivemark.guid, "1234567890AB"); |
michael@0 | 277 | do_check_guid_for_bookmark(aLivemark.id, "1234567890AB"); |
michael@0 | 278 | }; |
michael@0 | 279 | |
michael@0 | 280 | let livemark = yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 281 | { title: "test" |
michael@0 | 282 | , parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 283 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 284 | , feedURI: FEED_URI |
michael@0 | 285 | , guid: "1234567890AB" |
michael@0 | 286 | }); |
michael@0 | 287 | checkLivemark(livemark); |
michael@0 | 288 | }); |
michael@0 | 289 | |
michael@0 | 290 | add_task(function test_addLivemark_lastModified_succeeds() |
michael@0 | 291 | { |
michael@0 | 292 | let now = Date.now() * 1000; |
michael@0 | 293 | let livemark = yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 294 | { title: "test" |
michael@0 | 295 | , parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 296 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 297 | , feedURI: FEED_URI |
michael@0 | 298 | , lastModified: now |
michael@0 | 299 | }); |
michael@0 | 300 | do_check_eq(livemark.lastModified, now); |
michael@0 | 301 | }); |
michael@0 | 302 | |
michael@0 | 303 | add_task(function test_removeLivemark_emptyObject_throws() |
michael@0 | 304 | { |
michael@0 | 305 | try { |
michael@0 | 306 | yield PlacesUtils.livemarks.removeLivemark({}); |
michael@0 | 307 | do_throw("Invoking removeLivemark with empty object should throw"); |
michael@0 | 308 | } catch (ex) { |
michael@0 | 309 | do_check_eq(ex.result, Cr.NS_ERROR_INVALID_ARG); |
michael@0 | 310 | } |
michael@0 | 311 | }); |
michael@0 | 312 | |
michael@0 | 313 | add_task(function test_removeLivemark_noValidId_throws() |
michael@0 | 314 | { |
michael@0 | 315 | try { |
michael@0 | 316 | yield PlacesUtils.livemarks.removeLivemark({ id: -10, guid: "test"}); |
michael@0 | 317 | do_throw("Invoking removeLivemark with no valid id should throw"); |
michael@0 | 318 | } catch (ex) { |
michael@0 | 319 | do_check_eq(ex.result, Cr.NS_ERROR_INVALID_ARG); |
michael@0 | 320 | } |
michael@0 | 321 | }); |
michael@0 | 322 | |
michael@0 | 323 | add_task(function test_removeLivemark_nonExistent_fails() |
michael@0 | 324 | { |
michael@0 | 325 | try { |
michael@0 | 326 | yield PlacesUtils.livemarks.removeLivemark({ id: 1337 }); |
michael@0 | 327 | do_throw("Removing a non-existent livemark should fail"); |
michael@0 | 328 | } |
michael@0 | 329 | catch(ex) { |
michael@0 | 330 | } |
michael@0 | 331 | }); |
michael@0 | 332 | |
michael@0 | 333 | add_task(function test_removeLivemark_guid_succeeds() |
michael@0 | 334 | { |
michael@0 | 335 | let livemark = yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 336 | { title: "test" |
michael@0 | 337 | , parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 338 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 339 | , feedURI: FEED_URI |
michael@0 | 340 | , guid: "234567890ABC" |
michael@0 | 341 | }); |
michael@0 | 342 | |
michael@0 | 343 | |
michael@0 | 344 | do_check_eq(livemark.guid, "234567890ABC"); |
michael@0 | 345 | |
michael@0 | 346 | yield PlacesUtils.livemarks.removeLivemark({ |
michael@0 | 347 | id: 789, guid: "234567890ABC" |
michael@0 | 348 | }); |
michael@0 | 349 | |
michael@0 | 350 | do_check_eq(PlacesUtils.bookmarks.getItemIndex(livemark.id), -1); |
michael@0 | 351 | }); |
michael@0 | 352 | |
michael@0 | 353 | add_task(function test_removeLivemark_id_succeeds() |
michael@0 | 354 | { |
michael@0 | 355 | let livemark = yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 356 | { title: "test" |
michael@0 | 357 | , parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 358 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 359 | , feedURI: FEED_URI |
michael@0 | 360 | }); |
michael@0 | 361 | |
michael@0 | 362 | yield PlacesUtils.livemarks.removeLivemark({ id: livemark.id }); |
michael@0 | 363 | do_check_eq(PlacesUtils.bookmarks.getItemIndex(livemark.id), -1); |
michael@0 | 364 | }); |
michael@0 | 365 | |
michael@0 | 366 | add_task(function test_getLivemark_emptyObject_throws() |
michael@0 | 367 | { |
michael@0 | 368 | try { |
michael@0 | 369 | yield PlacesUtils.livemarks.getLivemark({}); |
michael@0 | 370 | do_throw("Invoking getLivemark with empty object should throw"); |
michael@0 | 371 | } catch (ex) { |
michael@0 | 372 | do_check_eq(ex.result, Cr.NS_ERROR_INVALID_ARG); |
michael@0 | 373 | } |
michael@0 | 374 | }); |
michael@0 | 375 | |
michael@0 | 376 | add_task(function test_getLivemark_noValidId_throws() |
michael@0 | 377 | { |
michael@0 | 378 | try { |
michael@0 | 379 | yield PlacesUtils.livemarks.getLivemark({ id: -10, guid: "test"}); |
michael@0 | 380 | do_throw("Invoking getLivemark with no valid id should throw"); |
michael@0 | 381 | } catch (ex) { |
michael@0 | 382 | do_check_eq(ex.result, Cr.NS_ERROR_INVALID_ARG); |
michael@0 | 383 | } |
michael@0 | 384 | }); |
michael@0 | 385 | |
michael@0 | 386 | add_task(function test_getLivemark_nonExistentId_fails() |
michael@0 | 387 | { |
michael@0 | 388 | try { |
michael@0 | 389 | yield PlacesUtils.livemarks.getLivemark({ id: 1234 }); |
michael@0 | 390 | do_throw("getLivemark for a non existent id should fail"); |
michael@0 | 391 | } |
michael@0 | 392 | catch(ex) {} |
michael@0 | 393 | }); |
michael@0 | 394 | |
michael@0 | 395 | add_task(function test_getLivemark_nonExistentGUID_fails() |
michael@0 | 396 | { |
michael@0 | 397 | try { |
michael@0 | 398 | yield PlacesUtils.livemarks.getLivemark({ guid: "34567890ABCD" }); |
michael@0 | 399 | do_throw("getLivemark for a non-existent guid should fail"); |
michael@0 | 400 | } |
michael@0 | 401 | catch(ex) {} |
michael@0 | 402 | }); |
michael@0 | 403 | |
michael@0 | 404 | add_task(function test_getLivemark_guid_succeeds() |
michael@0 | 405 | { |
michael@0 | 406 | yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 407 | { title: "test" |
michael@0 | 408 | , parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 409 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 410 | , feedURI: FEED_URI |
michael@0 | 411 | , guid: "34567890ABCD" }); |
michael@0 | 412 | |
michael@0 | 413 | // invalid id to check the guid wins. |
michael@0 | 414 | let livemark = |
michael@0 | 415 | yield PlacesUtils.livemarks.getLivemark({ id: 789, guid: "34567890ABCD" }); |
michael@0 | 416 | |
michael@0 | 417 | do_check_eq(livemark.title, "test"); |
michael@0 | 418 | do_check_eq(livemark.parentId, PlacesUtils.unfiledBookmarksFolderId); |
michael@0 | 419 | do_check_eq(livemark.index, PlacesUtils.bookmarks.getItemIndex(livemark.id)); |
michael@0 | 420 | do_check_true(livemark.feedURI.equals(FEED_URI)); |
michael@0 | 421 | do_check_eq(livemark.siteURI, null); |
michael@0 | 422 | do_check_eq(livemark.guid, "34567890ABCD"); |
michael@0 | 423 | }); |
michael@0 | 424 | |
michael@0 | 425 | add_task(function test_getLivemark_id_succeeds() |
michael@0 | 426 | { |
michael@0 | 427 | let livemark = yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 428 | { title: "test" |
michael@0 | 429 | , parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 430 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 431 | , feedURI: FEED_URI |
michael@0 | 432 | }); |
michael@0 | 433 | |
michael@0 | 434 | livemark = yield PlacesUtils.livemarks.getLivemark({ id: livemark.id }); |
michael@0 | 435 | |
michael@0 | 436 | do_check_eq(livemark.title, "test"); |
michael@0 | 437 | do_check_eq(livemark.parentId, PlacesUtils.unfiledBookmarksFolderId); |
michael@0 | 438 | do_check_eq(livemark.index, PlacesUtils.bookmarks.getItemIndex(livemark.id)); |
michael@0 | 439 | do_check_true(livemark.feedURI.equals(FEED_URI)); |
michael@0 | 440 | do_check_eq(livemark.siteURI, null); |
michael@0 | 441 | do_check_guid_for_bookmark(livemark.id, livemark.guid); |
michael@0 | 442 | }); |
michael@0 | 443 | |
michael@0 | 444 | add_task(function test_getLivemark_removeItem_contention() |
michael@0 | 445 | { |
michael@0 | 446 | PlacesUtils.livemarks.addLivemark({ title: "test" |
michael@0 | 447 | , parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 448 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 449 | , feedURI: FEED_URI |
michael@0 | 450 | }); |
michael@0 | 451 | PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); |
michael@0 | 452 | PlacesUtils.livemarks.addLivemark({ title: "test" |
michael@0 | 453 | , parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 454 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 455 | , feedURI: FEED_URI |
michael@0 | 456 | }); |
michael@0 | 457 | let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, |
michael@0 | 458 | PlacesUtils.bookmarks.DEFAULT_INDEX); |
michael@0 | 459 | |
michael@0 | 460 | let livemark = yield PlacesUtils.livemarks.getLivemark({ id: id }); |
michael@0 | 461 | |
michael@0 | 462 | do_check_eq(livemark.title, "test"); |
michael@0 | 463 | do_check_eq(livemark.parentId, PlacesUtils.unfiledBookmarksFolderId); |
michael@0 | 464 | do_check_eq(livemark.index, PlacesUtils.bookmarks.getItemIndex(livemark.id)); |
michael@0 | 465 | do_check_true(livemark.feedURI.equals(FEED_URI)); |
michael@0 | 466 | do_check_eq(livemark.siteURI, null); |
michael@0 | 467 | do_check_guid_for_bookmark(livemark.id, livemark.guid); |
michael@0 | 468 | }); |
michael@0 | 469 | |
michael@0 | 470 | add_task(function test_title_change() |
michael@0 | 471 | { |
michael@0 | 472 | let livemark = yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 473 | { title: "test" |
michael@0 | 474 | , parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 475 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 476 | , feedURI: FEED_URI }); |
michael@0 | 477 | |
michael@0 | 478 | PlacesUtils.bookmarks.setItemTitle(livemark.id, "test2"); |
michael@0 | 479 | do_check_eq(livemark.title, "test2"); |
michael@0 | 480 | }); |
michael@0 | 481 | |
michael@0 | 482 | add_task(function test_livemark_move() |
michael@0 | 483 | { |
michael@0 | 484 | let livemark = yield PlacesUtils.livemarks.addLivemark( |
michael@0 | 485 | { title: "test" |
michael@0 | 486 | , parentId: PlacesUtils.unfiledBookmarksFolderId |
michael@0 | 487 | , index: PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 488 | , feedURI: FEED_URI } ); |
michael@0 | 489 | |
michael@0 | 490 | PlacesUtils.bookmarks.moveItem(livemark.id, |
michael@0 | 491 | PlacesUtils.toolbarFolderId, |
michael@0 | 492 | PlacesUtils.bookmarks.DEFAULT_INDEX); |
michael@0 | 493 | do_check_eq(livemark.parentId, PlacesUtils.toolbarFolderId); |
michael@0 | 494 | do_check_eq(livemark.index, PlacesUtils.bookmarks.getItemIndex(livemark.id)); |
michael@0 | 495 | }); |
michael@0 | 496 | |
michael@0 | 497 | function run_test() { |
michael@0 | 498 | run_next_test(); |
michael@0 | 499 | } |