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.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /**
8 * Test bookmarksService.getBookmarkedURIFor(aURI);
9 */
11 let hs = PlacesUtils.history;
12 let bs = PlacesUtils.bookmarks;
14 function run_test() {
15 run_next_test();
16 }
18 add_task(function test_getBookmarkedURIFor() {
19 let now = Date.now() * 1000;
20 const sourceURI = uri("http://test.mozilla.org/");
21 // Add a visit and a bookmark.
22 yield promiseAddVisits({ uri: sourceURI, visitDate: now });
23 do_check_eq(bs.getBookmarkedURIFor(sourceURI), null);
25 let sourceItemId = bs.insertBookmark(bs.unfiledBookmarksFolder,
26 sourceURI,
27 bs.DEFAULT_INDEX,
28 "bookmark");
29 do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI));
31 // Add a redirected visit.
32 const permaURI = uri("http://perma.mozilla.org/");
33 yield promiseAddVisits({
34 uri: permaURI,
35 transition: TRANSITION_REDIRECT_PERMANENT,
36 visitDate: now++,
37 referrer: sourceURI
38 });
39 do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI));
40 do_check_true(bs.getBookmarkedURIFor(permaURI).equals(sourceURI));
41 // Add a bookmark to the destination.
42 let permaItemId = bs.insertBookmark(bs.unfiledBookmarksFolder,
43 permaURI,
44 bs.DEFAULT_INDEX,
45 "bookmark");
46 do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI));
47 do_check_true(bs.getBookmarkedURIFor(permaURI).equals(permaURI));
48 // Now remove the bookmark on the destination.
49 bs.removeItem(permaItemId);
50 // We should see the source as bookmark.
51 do_check_true(bs.getBookmarkedURIFor(permaURI).equals(sourceURI));
53 // Add another redirected visit.
54 const tempURI = uri("http://perma.mozilla.org/");
55 yield promiseAddVisits({
56 uri: tempURI,
57 transition: TRANSITION_REDIRECT_TEMPORARY,
58 visitDate: now++,
59 referrer: permaURI
60 });
62 do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI));
63 do_check_true(bs.getBookmarkedURIFor(tempURI).equals(sourceURI));
64 // Add a bookmark to the destination.
65 let tempItemId = bs.insertBookmark(bs.unfiledBookmarksFolder,
66 tempURI,
67 bs.DEFAULT_INDEX,
68 "bookmark");
69 do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI));
70 do_check_true(bs.getBookmarkedURIFor(tempURI).equals(tempURI));
72 // Now remove the bookmark on the destination.
73 bs.removeItem(tempItemId);
74 // We should see the source as bookmark.
75 do_check_true(bs.getBookmarkedURIFor(tempURI).equals(sourceURI));
76 // Remove the source bookmark as well.
77 bs.removeItem(sourceItemId);
78 do_check_eq(bs.getBookmarkedURIFor(tempURI), null);
80 // Try to pass in a never seen URI, should return null and a new entry should
81 // not be added to the database.
82 do_check_eq(bs.getBookmarkedURIFor(uri("http://does.not.exist/")), null);
83 do_check_false(page_in_database("http://does.not.exist/"));
84 });