Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | const bmsvc = PlacesUtils.bookmarks; |
michael@0 | 8 | const histsvc = PlacesUtils.history; |
michael@0 | 9 | |
michael@0 | 10 | function run_test() { |
michael@0 | 11 | run_next_test(); |
michael@0 | 12 | } |
michael@0 | 13 | |
michael@0 | 14 | add_task(function test_addBookmarksAndCheckGuids() { |
michael@0 | 15 | let folder = bmsvc.createFolder(bmsvc.placesRoot, "test folder", bmsvc.DEFAULT_INDEX); |
michael@0 | 16 | let b1 = bmsvc.insertBookmark(folder, uri("http://test1.com/"), |
michael@0 | 17 | bmsvc.DEFAULT_INDEX, "1 title"); |
michael@0 | 18 | let b2 = bmsvc.insertBookmark(folder, uri("http://test2.com/"), |
michael@0 | 19 | bmsvc.DEFAULT_INDEX, "2 title"); |
michael@0 | 20 | let b3 = bmsvc.insertBookmark(folder, uri("http://test3.com/"), |
michael@0 | 21 | bmsvc.DEFAULT_INDEX, "3 title"); |
michael@0 | 22 | let s1 = bmsvc.insertSeparator(folder, bmsvc.DEFAULT_INDEX); |
michael@0 | 23 | let f1 = bmsvc.createFolder(folder, "test folder 2", bmsvc.DEFAULT_INDEX); |
michael@0 | 24 | |
michael@0 | 25 | let root = PlacesUtils.getFolderContents(folder).root; |
michael@0 | 26 | do_check_eq(root.childCount, 5); |
michael@0 | 27 | |
michael@0 | 28 | // check bookmark guids |
michael@0 | 29 | let bookmarkGuidZero = root.getChild(0).bookmarkGuid; |
michael@0 | 30 | do_check_eq(bookmarkGuidZero.length, 12); |
michael@0 | 31 | // bookmarks have bookmark guids |
michael@0 | 32 | do_check_eq(root.getChild(1).bookmarkGuid.length, 12); |
michael@0 | 33 | do_check_eq(root.getChild(2).bookmarkGuid.length, 12); |
michael@0 | 34 | // separator has bookmark guid |
michael@0 | 35 | do_check_eq(root.getChild(3).bookmarkGuid.length, 12); |
michael@0 | 36 | // folder has bookmark guid |
michael@0 | 37 | do_check_eq(root.getChild(4).bookmarkGuid.length, 12); |
michael@0 | 38 | // all bookmark guids are different. |
michael@0 | 39 | do_check_neq(bookmarkGuidZero, root.getChild(1).bookmarkGuid); |
michael@0 | 40 | do_check_neq(root.getChild(1).bookmarkGuid, root.getChild(2).bookmarkGuid); |
michael@0 | 41 | do_check_neq(root.getChild(2).bookmarkGuid, root.getChild(3).bookmarkGuid); |
michael@0 | 42 | do_check_neq(root.getChild(3).bookmarkGuid, root.getChild(4).bookmarkGuid); |
michael@0 | 43 | |
michael@0 | 44 | // check page guids |
michael@0 | 45 | let pageGuidZero = root.getChild(0).pageGuid; |
michael@0 | 46 | do_check_eq(pageGuidZero.length, 12); |
michael@0 | 47 | // bookmarks have page guids |
michael@0 | 48 | do_check_eq(root.getChild(1).pageGuid.length, 12); |
michael@0 | 49 | do_check_eq(root.getChild(2).pageGuid.length, 12); |
michael@0 | 50 | // folder and separator don't have page guids |
michael@0 | 51 | do_check_eq(root.getChild(3).pageGuid, ""); |
michael@0 | 52 | do_check_eq(root.getChild(4).pageGuid, ""); |
michael@0 | 53 | |
michael@0 | 54 | do_check_neq(pageGuidZero, root.getChild(1).pageGuid); |
michael@0 | 55 | do_check_neq(root.getChild(1).pageGuid, root.getChild(2).pageGuid); |
michael@0 | 56 | |
michael@0 | 57 | root.containerOpen = false; |
michael@0 | 58 | |
michael@0 | 59 | remove_all_bookmarks(); |
michael@0 | 60 | }); |
michael@0 | 61 | |
michael@0 | 62 | add_task(function test_updateBookmarksAndCheckGuids() { |
michael@0 | 63 | let folder = bmsvc.createFolder(bmsvc.placesRoot, "test folder", bmsvc.DEFAULT_INDEX); |
michael@0 | 64 | let b1 = bmsvc.insertBookmark(folder, uri("http://test1.com/"), |
michael@0 | 65 | bmsvc.DEFAULT_INDEX, "1 title"); |
michael@0 | 66 | let f1 = bmsvc.createFolder(folder, "test folder 2", bmsvc.DEFAULT_INDEX); |
michael@0 | 67 | |
michael@0 | 68 | let root = PlacesUtils.getFolderContents(folder).root; |
michael@0 | 69 | do_check_eq(root.childCount, 2); |
michael@0 | 70 | |
michael@0 | 71 | // ensure the bookmark and page guids remain the same after modifing other property. |
michael@0 | 72 | let bookmarkGuidZero = root.getChild(0).bookmarkGuid; |
michael@0 | 73 | let pageGuidZero = root.getChild(0).pageGuid; |
michael@0 | 74 | bmsvc.setItemTitle(b1, "1 title mod"); |
michael@0 | 75 | do_check_eq(root.getChild(0).title, "1 title mod"); |
michael@0 | 76 | do_check_eq(root.getChild(0).bookmarkGuid, bookmarkGuidZero); |
michael@0 | 77 | do_check_eq(root.getChild(0).pageGuid, pageGuidZero); |
michael@0 | 78 | |
michael@0 | 79 | let bookmarkGuidOne = root.getChild(1).bookmarkGuid; |
michael@0 | 80 | let pageGuidOne = root.getChild(1).pageGuid; |
michael@0 | 81 | bmsvc.setItemTitle(f1, "test foolder 234"); |
michael@0 | 82 | do_check_eq(root.getChild(1).title, "test foolder 234"); |
michael@0 | 83 | do_check_eq(root.getChild(1).bookmarkGuid, bookmarkGuidOne); |
michael@0 | 84 | do_check_eq(root.getChild(1).pageGuid, pageGuidOne); |
michael@0 | 85 | |
michael@0 | 86 | root.containerOpen = false; |
michael@0 | 87 | |
michael@0 | 88 | remove_all_bookmarks(); |
michael@0 | 89 | }); |
michael@0 | 90 | |
michael@0 | 91 | add_task(function test_addVisitAndCheckGuid() { |
michael@0 | 92 | // add a visit and test page guid and non-existing bookmark guids. |
michael@0 | 93 | let now = Date.now() * 1000; |
michael@0 | 94 | let sourceURI = uri("http://test4.com/"); |
michael@0 | 95 | yield promiseAddVisits({ uri: sourceURI }); |
michael@0 | 96 | do_check_eq(bmsvc.getBookmarkedURIFor(sourceURI), null); |
michael@0 | 97 | |
michael@0 | 98 | let options = histsvc.getNewQueryOptions(); |
michael@0 | 99 | let query = histsvc.getNewQuery(); |
michael@0 | 100 | query.uri = sourceURI; |
michael@0 | 101 | let root = histsvc.executeQuery(query, options).root; |
michael@0 | 102 | root.containerOpen = true; |
michael@0 | 103 | do_check_eq(root.childCount, 1); |
michael@0 | 104 | |
michael@0 | 105 | do_check_valid_places_guid(root.getChild(0).pageGuid); |
michael@0 | 106 | do_check_eq(root.getChild(0).bookmarkGuid, ""); |
michael@0 | 107 | root.containerOpen = false; |
michael@0 | 108 | |
michael@0 | 109 | yield promiseClearHistory(); |
michael@0 | 110 | }); |
michael@0 | 111 | |
michael@0 | 112 | add_task(function test_addItemsWithInvalidGUIDsFails() { |
michael@0 | 113 | const INVALID_GUID = "XYZ"; |
michael@0 | 114 | try { |
michael@0 | 115 | bmsvc.createFolder(bmsvc.placesRoot, "XYZ folder", |
michael@0 | 116 | bmsvc.DEFAULT_INDEX, INVALID_GUID); |
michael@0 | 117 | do_throw("Adding a folder with an invalid guid should fail"); |
michael@0 | 118 | } |
michael@0 | 119 | catch(ex) { } |
michael@0 | 120 | |
michael@0 | 121 | let folder = bmsvc.createFolder(bmsvc.placesRoot, "test folder", |
michael@0 | 122 | bmsvc.DEFAULT_INDEX); |
michael@0 | 123 | try { |
michael@0 | 124 | bmsvc.insertBookmark(folder, uri("http://test.tld"), bmsvc.DEFAULT_INDEX, |
michael@0 | 125 | "title", INVALID_GUID); |
michael@0 | 126 | do_throw("Adding a bookmark with an invalid guid should fail"); |
michael@0 | 127 | } |
michael@0 | 128 | catch(ex) { } |
michael@0 | 129 | |
michael@0 | 130 | try { |
michael@0 | 131 | bmsvc.insertSeparator(folder, bmsvc.DEFAULT_INDEX, INVALID_GUID); |
michael@0 | 132 | do_throw("Adding a separator with an invalid guid should fail"); |
michael@0 | 133 | } |
michael@0 | 134 | catch(ex) { } |
michael@0 | 135 | |
michael@0 | 136 | remove_all_bookmarks(); |
michael@0 | 137 | }); |
michael@0 | 138 | |
michael@0 | 139 | add_task(function test_addItemsWithGUIDs() { |
michael@0 | 140 | const FOLDER_GUID = "FOLDER--GUID"; |
michael@0 | 141 | const BOOKMARK_GUID = "BM------GUID"; |
michael@0 | 142 | const SEPARATOR_GUID = "SEP-----GUID"; |
michael@0 | 143 | |
michael@0 | 144 | let folder = bmsvc.createFolder(bmsvc.placesRoot, "test folder", |
michael@0 | 145 | bmsvc.DEFAULT_INDEX, FOLDER_GUID); |
michael@0 | 146 | bmsvc.insertBookmark(folder, uri("http://test1.com/"), bmsvc.DEFAULT_INDEX, |
michael@0 | 147 | "1 title", BOOKMARK_GUID); |
michael@0 | 148 | bmsvc.insertSeparator(folder, bmsvc.DEFAULT_INDEX, SEPARATOR_GUID); |
michael@0 | 149 | |
michael@0 | 150 | let root = PlacesUtils.getFolderContents(folder).root; |
michael@0 | 151 | do_check_eq(root.childCount, 2); |
michael@0 | 152 | do_check_eq(root.bookmarkGuid, FOLDER_GUID); |
michael@0 | 153 | do_check_eq(root.getChild(0).bookmarkGuid, BOOKMARK_GUID); |
michael@0 | 154 | do_check_eq(root.getChild(1).bookmarkGuid, SEPARATOR_GUID); |
michael@0 | 155 | |
michael@0 | 156 | root.containerOpen = false; |
michael@0 | 157 | remove_all_bookmarks(); |
michael@0 | 158 | }); |
michael@0 | 159 | |
michael@0 | 160 | add_task(function test_emptyGUIDIgnored() { |
michael@0 | 161 | let folder = bmsvc.createFolder(bmsvc.placesRoot, "test folder", |
michael@0 | 162 | bmsvc.DEFAULT_INDEX, ""); |
michael@0 | 163 | do_check_valid_places_guid(PlacesUtils.getFolderContents(folder) |
michael@0 | 164 | .root.bookmarkGuid); |
michael@0 | 165 | remove_all_bookmarks(); |
michael@0 | 166 | }); |
michael@0 | 167 | |
michael@0 | 168 | add_task(function test_usingSameGUIDFails() { |
michael@0 | 169 | const GUID = "XYZXYZXYZXYZ"; |
michael@0 | 170 | bmsvc.createFolder(bmsvc.placesRoot, "test folder", |
michael@0 | 171 | bmsvc.DEFAULT_INDEX, GUID); |
michael@0 | 172 | try { |
michael@0 | 173 | bmsvc.createFolder(bmsvc.placesRoot, "test folder 2", |
michael@0 | 174 | bmsvc.DEFAULT_INDEX, GUID); |
michael@0 | 175 | do_throw("Using the same guid twice should fail"); |
michael@0 | 176 | } |
michael@0 | 177 | catch(ex) { } |
michael@0 | 178 | |
michael@0 | 179 | remove_all_bookmarks(); |
michael@0 | 180 | }); |