toolkit/components/places/tests/unit/test_update_frecency_after_delete.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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 /**
michael@0 8 * Bug 455315
michael@0 9 * https://bugzilla.mozilla.org/show_bug.cgi?id=412132
michael@0 10 *
michael@0 11 * Ensures that the frecency of a bookmark's URI is what it should be after the
michael@0 12 * bookmark is deleted.
michael@0 13 */
michael@0 14
michael@0 15 add_test(function removed_bookmark()
michael@0 16 {
michael@0 17 do_log_info("After removing bookmark, frecency of bookmark's URI should be " +
michael@0 18 "zero if URI is unvisited and no longer bookmarked.");
michael@0 19 const TEST_URI = NetUtil.newURI("http://example.com/1");
michael@0 20 let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
michael@0 21 TEST_URI,
michael@0 22 PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 23 "bookmark title");
michael@0 24 promiseAsyncUpdates().then(function ()
michael@0 25 {
michael@0 26 do_log_info("Bookmarked => frecency of URI should be != 0");
michael@0 27 do_check_neq(frecencyForUrl(TEST_URI), 0);
michael@0 28
michael@0 29 PlacesUtils.bookmarks.removeItem(id);
michael@0 30
michael@0 31 promiseAsyncUpdates().then(function ()
michael@0 32 {
michael@0 33 do_log_info("Unvisited URI no longer bookmarked => frecency should = 0");
michael@0 34 do_check_eq(frecencyForUrl(TEST_URI), 0);
michael@0 35
michael@0 36 remove_all_bookmarks();
michael@0 37 promiseClearHistory().then(run_next_test);
michael@0 38 });
michael@0 39 });
michael@0 40 });
michael@0 41
michael@0 42 add_test(function removed_but_visited_bookmark()
michael@0 43 {
michael@0 44 do_log_info("After removing bookmark, frecency of bookmark's URI should " +
michael@0 45 "not be zero if URI is visited.");
michael@0 46 const TEST_URI = NetUtil.newURI("http://example.com/1");
michael@0 47 let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
michael@0 48 TEST_URI,
michael@0 49 PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 50 "bookmark title");
michael@0 51 promiseAsyncUpdates().then(function ()
michael@0 52 {
michael@0 53 do_log_info("Bookmarked => frecency of URI should be != 0");
michael@0 54 do_check_neq(frecencyForUrl(TEST_URI), 0);
michael@0 55
michael@0 56 promiseAddVisits(TEST_URI).then(function () {
michael@0 57 PlacesUtils.bookmarks.removeItem(id);
michael@0 58
michael@0 59 promiseAsyncUpdates().then(function ()
michael@0 60 {
michael@0 61 do_log_info("*Visited* URI no longer bookmarked => frecency should != 0");
michael@0 62 do_check_neq(frecencyForUrl(TEST_URI), 0);
michael@0 63
michael@0 64 remove_all_bookmarks();
michael@0 65 promiseClearHistory().then(run_next_test);
michael@0 66 });
michael@0 67 });
michael@0 68 });
michael@0 69 });
michael@0 70
michael@0 71 add_test(function remove_bookmark_still_bookmarked()
michael@0 72 {
michael@0 73 do_log_info("After removing bookmark, frecency of bookmark's URI should ",
michael@0 74 "not be zero if URI is still bookmarked.");
michael@0 75 const TEST_URI = NetUtil.newURI("http://example.com/1");
michael@0 76 let id1 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
michael@0 77 TEST_URI,
michael@0 78 PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 79 "bookmark 1 title");
michael@0 80 let id2 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
michael@0 81 TEST_URI,
michael@0 82 PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 83 "bookmark 2 title");
michael@0 84 promiseAsyncUpdates().then(function ()
michael@0 85 {
michael@0 86 do_log_info("Bookmarked => frecency of URI should be != 0");
michael@0 87 do_check_neq(frecencyForUrl(TEST_URI), 0);
michael@0 88
michael@0 89 PlacesUtils.bookmarks.removeItem(id1);
michael@0 90
michael@0 91 promiseAsyncUpdates().then(function ()
michael@0 92 {
michael@0 93 do_log_info("URI still bookmarked => frecency should != 0");
michael@0 94 do_check_neq(frecencyForUrl(TEST_URI), 0);
michael@0 95
michael@0 96 remove_all_bookmarks();
michael@0 97 promiseClearHistory().then(run_next_test);
michael@0 98 });
michael@0 99 });
michael@0 100 });
michael@0 101
michael@0 102 add_test(function cleared_parent_of_visited_bookmark()
michael@0 103 {
michael@0 104 do_log_info("After removing all children from bookmark's parent, frecency " +
michael@0 105 "of bookmark's URI should not be zero if URI is visited.");
michael@0 106 const TEST_URI = NetUtil.newURI("http://example.com/1");
michael@0 107 let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
michael@0 108 TEST_URI,
michael@0 109 PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 110 "bookmark title");
michael@0 111 promiseAsyncUpdates().then(function ()
michael@0 112 {
michael@0 113 do_log_info("Bookmarked => frecency of URI should be != 0");
michael@0 114 do_check_neq(frecencyForUrl(TEST_URI), 0);
michael@0 115
michael@0 116 promiseAddVisits(TEST_URI).then(function () {
michael@0 117 PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
michael@0 118
michael@0 119 promiseAsyncUpdates().then(function ()
michael@0 120 {
michael@0 121 do_log_info("*Visited* URI no longer bookmarked => frecency should != 0");
michael@0 122 do_check_neq(frecencyForUrl(TEST_URI), 0);
michael@0 123
michael@0 124 remove_all_bookmarks();
michael@0 125 promiseClearHistory().then(run_next_test);
michael@0 126 });
michael@0 127 });
michael@0 128 });
michael@0 129 });
michael@0 130
michael@0 131 add_test(function cleared_parent_of_bookmark_still_bookmarked()
michael@0 132 {
michael@0 133 do_log_info("After removing all children from bookmark's parent, frecency " +
michael@0 134 "of bookmark's URI should not be zero if URI is still " +
michael@0 135 "bookmarked.");
michael@0 136 const TEST_URI = NetUtil.newURI("http://example.com/1");
michael@0 137 let id1 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.toolbarFolderId,
michael@0 138 TEST_URI,
michael@0 139 PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 140 "bookmark 1 title");
michael@0 141
michael@0 142 let id2 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
michael@0 143 TEST_URI,
michael@0 144 PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 145 "bookmark 2 title");
michael@0 146 promiseAsyncUpdates().then(function ()
michael@0 147 {
michael@0 148 do_log_info("Bookmarked => frecency of URI should be != 0");
michael@0 149 do_check_neq(frecencyForUrl(TEST_URI), 0);
michael@0 150
michael@0 151 PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
michael@0 152
michael@0 153 promiseAsyncUpdates().then(function ()
michael@0 154 {
michael@0 155 // URI still bookmarked => frecency should != 0.
michael@0 156 do_check_neq(frecencyForUrl(TEST_URI), 0);
michael@0 157
michael@0 158 remove_all_bookmarks();
michael@0 159 promiseClearHistory().then(run_next_test);
michael@0 160 });
michael@0 161 });
michael@0 162 });
michael@0 163
michael@0 164 ///////////////////////////////////////////////////////////////////////////////
michael@0 165
michael@0 166 function run_test()
michael@0 167 {
michael@0 168 run_next_test();
michael@0 169 }

mercurial