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 | /** |
michael@0 | 5 | * This file tests PlacesUtils.asyncGetBookmarkIds method. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | const TEST_URL = "http://www.example.com/"; |
michael@0 | 9 | |
michael@0 | 10 | [ |
michael@0 | 11 | |
michael@0 | 12 | function test_no_bookmark() { |
michael@0 | 13 | PlacesUtils.asyncGetBookmarkIds(TEST_URL, (aItemIds, aURI) => { |
michael@0 | 14 | do_check_eq(aItemIds.length, 0); |
michael@0 | 15 | do_check_eq(aURI, TEST_URL); |
michael@0 | 16 | run_next_test(); |
michael@0 | 17 | }); |
michael@0 | 18 | }, |
michael@0 | 19 | |
michael@0 | 20 | function test_one_bookmark_nsIURI() { |
michael@0 | 21 | let uri = NetUtil.newURI(TEST_URL); |
michael@0 | 22 | let itemId = PlacesUtils.bookmarks.insertBookmark( |
michael@0 | 23 | PlacesUtils.unfiledBookmarksFolderId, uri, "test", |
michael@0 | 24 | PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 25 | ); |
michael@0 | 26 | PlacesUtils.asyncGetBookmarkIds(uri, (aItemIds, aURI) => { |
michael@0 | 27 | do_check_eq(aItemIds.length, 1); |
michael@0 | 28 | do_check_eq(aItemIds[0], itemId); |
michael@0 | 29 | do_check_true(aURI.equals(uri)); |
michael@0 | 30 | PlacesUtils.bookmarks.removeItem(itemId); |
michael@0 | 31 | run_next_test(); |
michael@0 | 32 | }); |
michael@0 | 33 | }, |
michael@0 | 34 | |
michael@0 | 35 | function test_one_bookmark_spec() { |
michael@0 | 36 | let uri = NetUtil.newURI(TEST_URL); |
michael@0 | 37 | let itemId = PlacesUtils.bookmarks.insertBookmark( |
michael@0 | 38 | PlacesUtils.unfiledBookmarksFolderId, uri, "test", |
michael@0 | 39 | PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 40 | ); |
michael@0 | 41 | PlacesUtils.asyncGetBookmarkIds(TEST_URL, (aItemIds, aURI) => { |
michael@0 | 42 | do_check_eq(aItemIds.length, 1); |
michael@0 | 43 | do_check_eq(aItemIds[0], itemId); |
michael@0 | 44 | do_check_eq(aURI, TEST_URL); |
michael@0 | 45 | PlacesUtils.bookmarks.removeItem(itemId); |
michael@0 | 46 | run_next_test(); |
michael@0 | 47 | }); |
michael@0 | 48 | }, |
michael@0 | 49 | |
michael@0 | 50 | function test_multiple_bookmarks() { |
michael@0 | 51 | let uri = NetUtil.newURI(TEST_URL); |
michael@0 | 52 | let itemIds = []; |
michael@0 | 53 | itemIds.push(PlacesUtils.bookmarks.insertBookmark( |
michael@0 | 54 | PlacesUtils.unfiledBookmarksFolderId, uri, "test", |
michael@0 | 55 | PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 56 | )); |
michael@0 | 57 | itemIds.push(PlacesUtils.bookmarks.insertBookmark( |
michael@0 | 58 | PlacesUtils.unfiledBookmarksFolderId, uri, "test", |
michael@0 | 59 | PlacesUtils.bookmarks.DEFAULT_INDEX |
michael@0 | 60 | )); |
michael@0 | 61 | PlacesUtils.asyncGetBookmarkIds(uri, (aItemIds, aURI) => { |
michael@0 | 62 | do_check_eq(aItemIds.length, 2); |
michael@0 | 63 | do_check_true(do_compare_arrays(itemIds, aItemIds)); |
michael@0 | 64 | do_check_true(aURI.equals(uri)); |
michael@0 | 65 | itemIds.forEach(PlacesUtils.bookmarks.removeItem); |
michael@0 | 66 | run_next_test(); |
michael@0 | 67 | }); |
michael@0 | 68 | }, |
michael@0 | 69 | |
michael@0 | 70 | function test_cancel() { |
michael@0 | 71 | let pending = PlacesUtils.asyncGetBookmarkIds(TEST_URL, (aItemIds, aURI) => { |
michael@0 | 72 | do_throw("A canceled pending statement should not be invoked"); |
michael@0 | 73 | }); |
michael@0 | 74 | pending.cancel(); |
michael@0 | 75 | PlacesUtils.asyncGetBookmarkIds(TEST_URL, (aItemIds, aURI) => { |
michael@0 | 76 | do_check_eq(aItemIds.length, 0); |
michael@0 | 77 | do_check_eq(aURI, TEST_URL); |
michael@0 | 78 | run_next_test(); |
michael@0 | 79 | }); |
michael@0 | 80 | }, |
michael@0 | 81 | |
michael@0 | 82 | ].forEach(add_test); |
michael@0 | 83 | |
michael@0 | 84 | function run_test() { |
michael@0 | 85 | run_next_test(); |
michael@0 | 86 | } |