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 testFolderId = PlacesUtils.bookmarksMenuFolderId; |
michael@0 | 9 | |
michael@0 | 10 | // main |
michael@0 | 11 | function run_test() { |
michael@0 | 12 | var testURI = uri("http://foo.com"); |
michael@0 | 13 | |
michael@0 | 14 | /* |
michael@0 | 15 | 1. Create a bookmark for a URI, with a keyword and post data. |
michael@0 | 16 | 2. Create a bookmark for the same URI, with a different keyword and different post data. |
michael@0 | 17 | 3. Confirm that our method for getting a URI+postdata retains bookmark affinity. |
michael@0 | 18 | */ |
michael@0 | 19 | var bm1 = bmsvc.insertBookmark(testFolderId, testURI, -1, "blah"); |
michael@0 | 20 | bmsvc.setKeywordForBookmark(bm1, "foo"); |
michael@0 | 21 | PlacesUtils.setPostDataForBookmark(bm1, "pdata1"); |
michael@0 | 22 | var bm2 = bmsvc.insertBookmark(testFolderId, testURI, -1, "blah"); |
michael@0 | 23 | bmsvc.setKeywordForBookmark(bm2, "bar"); |
michael@0 | 24 | PlacesUtils.setPostDataForBookmark(bm2, "pdata2"); |
michael@0 | 25 | |
michael@0 | 26 | // check kw, pd for bookmark 1 |
michael@0 | 27 | var url, postdata; |
michael@0 | 28 | [url, postdata] = PlacesUtils.getURLAndPostDataForKeyword("foo"); |
michael@0 | 29 | do_check_eq(testURI.spec, url); |
michael@0 | 30 | do_check_eq(postdata, "pdata1"); |
michael@0 | 31 | |
michael@0 | 32 | // check kw, pd for bookmark 2 |
michael@0 | 33 | [url, postdata] = PlacesUtils.getURLAndPostDataForKeyword("bar"); |
michael@0 | 34 | do_check_eq(testURI.spec, url); |
michael@0 | 35 | do_check_eq(postdata, "pdata2"); |
michael@0 | 36 | |
michael@0 | 37 | // cleanup |
michael@0 | 38 | bmsvc.removeItem(bm1); |
michael@0 | 39 | bmsvc.removeItem(bm2); |
michael@0 | 40 | |
michael@0 | 41 | /* |
michael@0 | 42 | 1. Create two bookmarks with the same URI and keyword. |
michael@0 | 43 | 2. Confirm that the most recently created one is returned for that keyword. |
michael@0 | 44 | */ |
michael@0 | 45 | var bm1 = bmsvc.insertBookmark(testFolderId, testURI, -1, "blah"); |
michael@0 | 46 | bmsvc.setKeywordForBookmark(bm1, "foo"); |
michael@0 | 47 | PlacesUtils.setPostDataForBookmark(bm1, "pdata1"); |
michael@0 | 48 | var bm2 = bmsvc.insertBookmark(testFolderId, testURI, -1, "blah"); |
michael@0 | 49 | bmsvc.setKeywordForBookmark(bm2, "foo"); |
michael@0 | 50 | PlacesUtils.setPostDataForBookmark(bm2, "pdata2"); |
michael@0 | 51 | |
michael@0 | 52 | var bm1da = bmsvc.getItemDateAdded(bm1); |
michael@0 | 53 | var bm1lm = bmsvc.getItemLastModified(bm1); |
michael@0 | 54 | LOG("bm1 dateAdded: " + bm1da + ", lastModified: " + bm1lm); |
michael@0 | 55 | var bm2da = bmsvc.getItemDateAdded(bm2); |
michael@0 | 56 | var bm2lm = bmsvc.getItemLastModified(bm2); |
michael@0 | 57 | LOG("bm2 dateAdded: " + bm2da + ", lastModified: " + bm2lm); |
michael@0 | 58 | do_check_true(bm1da <= bm2da); |
michael@0 | 59 | do_check_true(bm1lm <= bm2lm); |
michael@0 | 60 | |
michael@0 | 61 | [url, postdata] = PlacesUtils.getURLAndPostDataForKeyword("foo"); |
michael@0 | 62 | do_check_eq(testURI.spec, url); |
michael@0 | 63 | do_check_eq(postdata, "pdata2"); |
michael@0 | 64 | |
michael@0 | 65 | // cleanup |
michael@0 | 66 | bmsvc.removeItem(bm1); |
michael@0 | 67 | bmsvc.removeItem(bm2); |
michael@0 | 68 | |
michael@0 | 69 | /* |
michael@0 | 70 | 1. Create two bookmarks with the same URI and keyword. |
michael@0 | 71 | 2. Modify the first-created bookmark. |
michael@0 | 72 | 3. Confirm that the most recently modified one is returned for that keyword. |
michael@0 | 73 | */ |
michael@0 | 74 | var bm1 = bmsvc.insertBookmark(testFolderId, testURI, -1, "blah"); |
michael@0 | 75 | bmsvc.setKeywordForBookmark(bm1, "foo"); |
michael@0 | 76 | PlacesUtils.setPostDataForBookmark(bm1, "pdata1"); |
michael@0 | 77 | var bm2 = bmsvc.insertBookmark(testFolderId, testURI, -1, "blah"); |
michael@0 | 78 | bmsvc.setKeywordForBookmark(bm2, "foo"); |
michael@0 | 79 | PlacesUtils.setPostDataForBookmark(bm2, "pdata2"); |
michael@0 | 80 | |
michael@0 | 81 | // modify the older bookmark |
michael@0 | 82 | bmsvc.setItemTitle(bm1, "change"); |
michael@0 | 83 | |
michael@0 | 84 | var bm1da = bmsvc.getItemDateAdded(bm1); |
michael@0 | 85 | var bm1lm = bmsvc.getItemLastModified(bm1); |
michael@0 | 86 | LOG("bm1 dateAdded: " + bm1da + ", lastModified: " + bm1lm); |
michael@0 | 87 | var bm2da = bmsvc.getItemDateAdded(bm2); |
michael@0 | 88 | var bm2lm = bmsvc.getItemLastModified(bm2); |
michael@0 | 89 | LOG("bm2 dateAdded: " + bm2da + ", lastModified: " + bm2lm); |
michael@0 | 90 | do_check_true(bm1da <= bm2da); |
michael@0 | 91 | // the last modified for bm1 should be at least as big as bm2 |
michael@0 | 92 | // but could be equal if the test runs faster than our PRNow() |
michael@0 | 93 | // granularity |
michael@0 | 94 | do_check_true(bm1lm >= bm2lm); |
michael@0 | 95 | |
michael@0 | 96 | // we need to ensure that bm1 last modified date is greater |
michael@0 | 97 | // that the modified date of bm2, otherwise in case of a "tie" |
michael@0 | 98 | // bm2 will win, as it has a bigger item id |
michael@0 | 99 | if (bm1lm == bm2lm) |
michael@0 | 100 | bmsvc.setItemLastModified(bm1, bm2lm + 1); |
michael@0 | 101 | |
michael@0 | 102 | [url, postdata] = PlacesUtils.getURLAndPostDataForKeyword("foo"); |
michael@0 | 103 | do_check_eq(testURI.spec, url); |
michael@0 | 104 | do_check_eq(postdata, "pdata1"); |
michael@0 | 105 | |
michael@0 | 106 | // cleanup |
michael@0 | 107 | bmsvc.removeItem(bm1); |
michael@0 | 108 | bmsvc.removeItem(bm2); |
michael@0 | 109 | |
michael@0 | 110 | /* |
michael@0 | 111 | Test that id breaks ties: |
michael@0 | 112 | 1. Create two bookmarks with the same URI and keyword, dateAdded and lastModified. |
michael@0 | 113 | 2. Confirm that the most recently created one is returned for that keyword. |
michael@0 | 114 | */ |
michael@0 | 115 | var testDate = Date.now() * 1000; |
michael@0 | 116 | var bm1 = bmsvc.insertBookmark(testFolderId, testURI, -1, "blah"); |
michael@0 | 117 | bmsvc.setKeywordForBookmark(bm1, "foo"); |
michael@0 | 118 | PlacesUtils.setPostDataForBookmark(bm1, "pdata1"); |
michael@0 | 119 | bmsvc.setItemDateAdded(bm1, testDate); |
michael@0 | 120 | bmsvc.setItemLastModified(bm1, testDate); |
michael@0 | 121 | |
michael@0 | 122 | var bm2 = bmsvc.insertBookmark(testFolderId, testURI, -1, "blah"); |
michael@0 | 123 | bmsvc.setKeywordForBookmark(bm2, "foo"); |
michael@0 | 124 | PlacesUtils.setPostDataForBookmark(bm2, "pdata2"); |
michael@0 | 125 | bmsvc.setItemDateAdded(bm2, testDate); |
michael@0 | 126 | bmsvc.setItemLastModified(bm2, testDate); |
michael@0 | 127 | |
michael@0 | 128 | var bm1da = bmsvc.getItemDateAdded(bm1, testDate); |
michael@0 | 129 | var bm1lm = bmsvc.getItemLastModified(bm1); |
michael@0 | 130 | LOG("bm1 dateAdded: " + bm1da + ", lastModified: " + bm1lm); |
michael@0 | 131 | var bm2da = bmsvc.getItemDateAdded(bm2); |
michael@0 | 132 | var bm2lm = bmsvc.getItemLastModified(bm2); |
michael@0 | 133 | LOG("bm2 dateAdded: " + bm2da + ", lastModified: " + bm2lm); |
michael@0 | 134 | |
michael@0 | 135 | do_check_eq(bm1da, bm2da); |
michael@0 | 136 | do_check_eq(bm1lm, bm2lm); |
michael@0 | 137 | |
michael@0 | 138 | |
michael@0 | 139 | var ids = bmsvc.getBookmarkIdsForURI(testURI); |
michael@0 | 140 | do_check_eq(ids[0], bm2); |
michael@0 | 141 | do_check_eq(ids[1], bm1); |
michael@0 | 142 | |
michael@0 | 143 | [url, postdata] = PlacesUtils.getURLAndPostDataForKeyword("foo"); |
michael@0 | 144 | do_check_eq(testURI.spec, url); |
michael@0 | 145 | do_check_eq(postdata, "pdata2"); |
michael@0 | 146 | |
michael@0 | 147 | // cleanup |
michael@0 | 148 | bmsvc.removeItem(bm1); |
michael@0 | 149 | bmsvc.removeItem(bm2); |
michael@0 | 150 | } |