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 | function check_bookmark_keyword(aItemId, aKeyword) |
michael@0 | 5 | { |
michael@0 | 6 | let keyword = aKeyword ? aKeyword.toLowerCase() : null; |
michael@0 | 7 | do_check_eq(PlacesUtils.bookmarks.getKeywordForBookmark(aItemId), |
michael@0 | 8 | keyword); |
michael@0 | 9 | } |
michael@0 | 10 | |
michael@0 | 11 | function check_uri_keyword(aURI, aKeyword) |
michael@0 | 12 | { |
michael@0 | 13 | let keyword = aKeyword ? aKeyword.toLowerCase() : null; |
michael@0 | 14 | do_check_eq(PlacesUtils.bookmarks.getKeywordForURI(aURI), |
michael@0 | 15 | keyword); |
michael@0 | 16 | |
michael@0 | 17 | if (aKeyword) { |
michael@0 | 18 | // This API can't tell which uri the user wants, so it returns a random one. |
michael@0 | 19 | let re = /http:\/\/test[0-9]\.mozilla\.org/; |
michael@0 | 20 | let url = PlacesUtils.bookmarks.getURIForKeyword(aKeyword).spec; |
michael@0 | 21 | do_check_true(re.test(url)); |
michael@0 | 22 | // Check case insensitivity. |
michael@0 | 23 | url = PlacesUtils.bookmarks.getURIForKeyword(aKeyword.toUpperCase()).spec |
michael@0 | 24 | do_check_true(re.test(url)); |
michael@0 | 25 | } |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function check_orphans() |
michael@0 | 29 | { |
michael@0 | 30 | stmt = DBConn().createStatement( |
michael@0 | 31 | "SELECT id FROM moz_keywords k WHERE NOT EXISTS (" |
michael@0 | 32 | + "SELECT id FROM moz_bookmarks WHERE keyword_id = k.id " |
michael@0 | 33 | + ")" |
michael@0 | 34 | ); |
michael@0 | 35 | try { |
michael@0 | 36 | do_check_false(stmt.executeStep()); |
michael@0 | 37 | } finally { |
michael@0 | 38 | stmt.finalize(); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | print("Check there are no orphan database entries"); |
michael@0 | 42 | let stmt = DBConn().createStatement( |
michael@0 | 43 | "SELECT b.id FROM moz_bookmarks b " |
michael@0 | 44 | + "LEFT JOIN moz_keywords k ON b.keyword_id = k.id " |
michael@0 | 45 | + "WHERE keyword_id NOTNULL AND k.id ISNULL" |
michael@0 | 46 | ); |
michael@0 | 47 | try { |
michael@0 | 48 | do_check_false(stmt.executeStep()); |
michael@0 | 49 | } finally { |
michael@0 | 50 | stmt.finalize(); |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | const URIS = [ |
michael@0 | 55 | uri("http://test1.mozilla.org/"), |
michael@0 | 56 | uri("http://test2.mozilla.org/"), |
michael@0 | 57 | ]; |
michael@0 | 58 | |
michael@0 | 59 | add_test(function test_addBookmarkWithKeyword() |
michael@0 | 60 | { |
michael@0 | 61 | check_uri_keyword(URIS[0], null); |
michael@0 | 62 | |
michael@0 | 63 | let itemId = |
michael@0 | 64 | PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, |
michael@0 | 65 | URIS[0], |
michael@0 | 66 | PlacesUtils.bookmarks.DEFAULT_INDEX, |
michael@0 | 67 | "test"); |
michael@0 | 68 | PlacesUtils.bookmarks.setKeywordForBookmark(itemId, "keyword"); |
michael@0 | 69 | check_bookmark_keyword(itemId, "keyword"); |
michael@0 | 70 | check_uri_keyword(URIS[0], "keyword"); |
michael@0 | 71 | |
michael@0 | 72 | promiseAsyncUpdates().then(function() { |
michael@0 | 73 | check_orphans(); |
michael@0 | 74 | run_next_test(); |
michael@0 | 75 | }); |
michael@0 | 76 | }); |
michael@0 | 77 | |
michael@0 | 78 | add_test(function test_addBookmarkToURIHavingKeyword() |
michael@0 | 79 | { |
michael@0 | 80 | let itemId = |
michael@0 | 81 | PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, |
michael@0 | 82 | URIS[0], |
michael@0 | 83 | PlacesUtils.bookmarks.DEFAULT_INDEX, |
michael@0 | 84 | "test"); |
michael@0 | 85 | // The uri has a keyword, but this specific bookmark has not. |
michael@0 | 86 | check_bookmark_keyword(itemId, null); |
michael@0 | 87 | check_uri_keyword(URIS[0], "keyword"); |
michael@0 | 88 | |
michael@0 | 89 | promiseAsyncUpdates().then(function() { |
michael@0 | 90 | check_orphans(); |
michael@0 | 91 | run_next_test(); |
michael@0 | 92 | }); |
michael@0 | 93 | }); |
michael@0 | 94 | |
michael@0 | 95 | add_test(function test_addSameKeywordToOtherURI() |
michael@0 | 96 | { |
michael@0 | 97 | let itemId = |
michael@0 | 98 | PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, |
michael@0 | 99 | URIS[1], |
michael@0 | 100 | PlacesUtils.bookmarks.DEFAULT_INDEX, |
michael@0 | 101 | "test2"); |
michael@0 | 102 | check_bookmark_keyword(itemId, null); |
michael@0 | 103 | check_uri_keyword(URIS[1], null); |
michael@0 | 104 | |
michael@0 | 105 | PlacesUtils.bookmarks.setKeywordForBookmark(itemId, "kEyWoRd"); |
michael@0 | 106 | check_bookmark_keyword(itemId, "kEyWoRd"); |
michael@0 | 107 | check_uri_keyword(URIS[1], "kEyWoRd"); |
michael@0 | 108 | |
michael@0 | 109 | // Check case insensitivity. |
michael@0 | 110 | check_uri_keyword(URIS[0], "kEyWoRd"); |
michael@0 | 111 | check_bookmark_keyword(itemId, "keyword"); |
michael@0 | 112 | check_uri_keyword(URIS[1], "keyword"); |
michael@0 | 113 | check_uri_keyword(URIS[0], "keyword"); |
michael@0 | 114 | |
michael@0 | 115 | promiseAsyncUpdates().then(function() { |
michael@0 | 116 | check_orphans(); |
michael@0 | 117 | run_next_test(); |
michael@0 | 118 | }); |
michael@0 | 119 | }); |
michael@0 | 120 | |
michael@0 | 121 | add_test(function test_removeBookmarkWithKeyword() |
michael@0 | 122 | { |
michael@0 | 123 | let itemId = |
michael@0 | 124 | PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, |
michael@0 | 125 | URIS[1], |
michael@0 | 126 | PlacesUtils.bookmarks.DEFAULT_INDEX, |
michael@0 | 127 | "test"); |
michael@0 | 128 | PlacesUtils.bookmarks.setKeywordForBookmark(itemId, "keyword"); |
michael@0 | 129 | check_bookmark_keyword(itemId, "keyword"); |
michael@0 | 130 | check_uri_keyword(URIS[1], "keyword"); |
michael@0 | 131 | |
michael@0 | 132 | // The keyword should not be removed from other bookmarks. |
michael@0 | 133 | PlacesUtils.bookmarks.removeItem(itemId); |
michael@0 | 134 | |
michael@0 | 135 | check_uri_keyword(URIS[1], "keyword"); |
michael@0 | 136 | check_uri_keyword(URIS[0], "keyword"); |
michael@0 | 137 | |
michael@0 | 138 | promiseAsyncUpdates().then(function() { |
michael@0 | 139 | check_orphans(); |
michael@0 | 140 | run_next_test(); |
michael@0 | 141 | }); |
michael@0 | 142 | }); |
michael@0 | 143 | |
michael@0 | 144 | add_test(function test_removeFolderWithKeywordedBookmarks() |
michael@0 | 145 | { |
michael@0 | 146 | // Keyword should be removed as well. |
michael@0 | 147 | PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); |
michael@0 | 148 | |
michael@0 | 149 | check_uri_keyword(URIS[1], null); |
michael@0 | 150 | check_uri_keyword(URIS[0], null); |
michael@0 | 151 | |
michael@0 | 152 | promiseAsyncUpdates().then(function() { |
michael@0 | 153 | check_orphans(); |
michael@0 | 154 | run_next_test(); |
michael@0 | 155 | }); |
michael@0 | 156 | }); |
michael@0 | 157 | |
michael@0 | 158 | function run_test() |
michael@0 | 159 | { |
michael@0 | 160 | run_next_test(); |
michael@0 | 161 | } |