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: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
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 * What this is aimed to test:
9 *
10 * Expiring only visits for a page, but not the full page, should fire an
11 * onDeleteVisits notification.
12 */
14 let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
15 getService(Ci.nsINavHistoryService);
16 let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
17 getService(Ci.nsINavBookmarksService);
19 let tests = [
21 { desc: "Add 1 bookmarked page.",
22 addPages: 1,
23 visitsPerPage: 1,
24 addBookmarks: 1,
25 limitExpiration: -1,
26 expectedNotifications: 1, // Will expire visits for 1 page.
27 },
29 { desc: "Add 2 pages, 1 bookmarked.",
30 addPages: 2,
31 visitsPerPage: 1,
32 addBookmarks: 1,
33 limitExpiration: -1,
34 expectedNotifications: 1, // Will expire visits for 1 page.
35 },
37 { desc: "Add 10 pages, none bookmarked.",
38 addPages: 10,
39 visitsPerPage: 1,
40 addBookmarks: 0,
41 limitExpiration: -1,
42 expectedNotifications: 0, // Will expire only full pages.
43 },
45 { desc: "Add 10 pages, all bookmarked.",
46 addPages: 10,
47 visitsPerPage: 1,
48 addBookmarks: 10,
49 limitExpiration: -1,
50 expectedNotifications: 10, // Will expire visist for all pages.
51 },
53 { desc: "Add 10 pages with lot of visits, none bookmarked.",
54 addPages: 10,
55 visitsPerPage: 10,
56 addBookmarks: 0,
57 limitExpiration: 10,
58 expectedNotifications: 10, // Will expire 1 visist for each page, but won't
59 }, // expire pages since they still have visits.
61 ];
63 function run_test() {
64 run_next_test();
65 }
67 add_task(function test_notifications_onDeleteVisits() {
68 // Set interval to a large value so we don't expire on it.
69 setInterval(3600); // 1h
71 // Expire anything that is expirable.
72 setMaxPages(0);
74 for (let testIndex = 1; testIndex <= tests.length; testIndex++) {
75 let currentTest = tests[testIndex -1];
76 print("\nTEST " + testIndex + ": " + currentTest.desc);
77 currentTest.receivedNotifications = 0;
79 // Setup visits.
80 let now = getExpirablePRTime();
81 for (let j = 0; j < currentTest.visitsPerPage; j++) {
82 for (let i = 0; i < currentTest.addPages; i++) {
83 let page = "http://" + testIndex + "." + i + ".mozilla.org/";
84 yield promiseAddVisits({ uri: uri(page), visitDate: now++ });
85 }
86 }
88 // Setup bookmarks.
89 currentTest.bookmarks = [];
90 for (let i = 0; i < currentTest.addBookmarks; i++) {
91 let page = "http://" + testIndex + "." + i + ".mozilla.org/";
92 bs.insertBookmark(bs.unfiledBookmarksFolder, uri(page),
93 bs.DEFAULT_INDEX, null);
94 currentTest.bookmarks.push(page);
95 }
97 // Observe history.
98 historyObserver = {
99 onBeginUpdateBatch: function PEX_onBeginUpdateBatch() {},
100 onEndUpdateBatch: function PEX_onEndUpdateBatch() {},
101 onClearHistory: function() {},
102 onVisit: function() {},
103 onTitleChanged: function() {},
104 onDeleteURI: function(aURI, aGUID, aReason) {
105 // Check this uri was not bookmarked.
106 do_check_eq(currentTest.bookmarks.indexOf(aURI.spec), -1);
107 do_check_valid_places_guid(aGUID);
108 do_check_eq(aReason, Ci.nsINavHistoryObserver.REASON_EXPIRED);
109 },
110 onPageChanged: function() {},
111 onDeleteVisits: function(aURI, aTime, aGUID, aReason) {
112 currentTest.receivedNotifications++;
113 do_check_guid_for_uri(aURI, aGUID);
114 do_check_eq(aReason, Ci.nsINavHistoryObserver.REASON_EXPIRED);
115 },
116 };
117 hs.addObserver(historyObserver, false);
119 // Expire now.
120 yield promiseForceExpirationStep(currentTest.limitExpiration);
122 hs.removeObserver(historyObserver, false);
124 do_check_eq(currentTest.receivedNotifications,
125 currentTest.expectedNotifications);
127 // Clean up.
128 bs.removeFolderChildren(bs.unfiledBookmarksFolder);
129 yield promiseClearHistory();
130 }
132 clearMaxPages();
133 bs.removeFolderChildren(bs.unfiledBookmarksFolder);
134 yield promiseClearHistory();
135 });