1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/unit/test_update_frecency_after_delete.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,169 @@ 1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +/** 1.11 + * Bug 455315 1.12 + * https://bugzilla.mozilla.org/show_bug.cgi?id=412132 1.13 + * 1.14 + * Ensures that the frecency of a bookmark's URI is what it should be after the 1.15 + * bookmark is deleted. 1.16 + */ 1.17 + 1.18 +add_test(function removed_bookmark() 1.19 +{ 1.20 + do_log_info("After removing bookmark, frecency of bookmark's URI should be " + 1.21 + "zero if URI is unvisited and no longer bookmarked."); 1.22 + const TEST_URI = NetUtil.newURI("http://example.com/1"); 1.23 + let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, 1.24 + TEST_URI, 1.25 + PlacesUtils.bookmarks.DEFAULT_INDEX, 1.26 + "bookmark title"); 1.27 + promiseAsyncUpdates().then(function () 1.28 + { 1.29 + do_log_info("Bookmarked => frecency of URI should be != 0"); 1.30 + do_check_neq(frecencyForUrl(TEST_URI), 0); 1.31 + 1.32 + PlacesUtils.bookmarks.removeItem(id); 1.33 + 1.34 + promiseAsyncUpdates().then(function () 1.35 + { 1.36 + do_log_info("Unvisited URI no longer bookmarked => frecency should = 0"); 1.37 + do_check_eq(frecencyForUrl(TEST_URI), 0); 1.38 + 1.39 + remove_all_bookmarks(); 1.40 + promiseClearHistory().then(run_next_test); 1.41 + }); 1.42 + }); 1.43 +}); 1.44 + 1.45 +add_test(function removed_but_visited_bookmark() 1.46 +{ 1.47 + do_log_info("After removing bookmark, frecency of bookmark's URI should " + 1.48 + "not be zero if URI is visited."); 1.49 + const TEST_URI = NetUtil.newURI("http://example.com/1"); 1.50 + let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, 1.51 + TEST_URI, 1.52 + PlacesUtils.bookmarks.DEFAULT_INDEX, 1.53 + "bookmark title"); 1.54 + promiseAsyncUpdates().then(function () 1.55 + { 1.56 + do_log_info("Bookmarked => frecency of URI should be != 0"); 1.57 + do_check_neq(frecencyForUrl(TEST_URI), 0); 1.58 + 1.59 + promiseAddVisits(TEST_URI).then(function () { 1.60 + PlacesUtils.bookmarks.removeItem(id); 1.61 + 1.62 + promiseAsyncUpdates().then(function () 1.63 + { 1.64 + do_log_info("*Visited* URI no longer bookmarked => frecency should != 0"); 1.65 + do_check_neq(frecencyForUrl(TEST_URI), 0); 1.66 + 1.67 + remove_all_bookmarks(); 1.68 + promiseClearHistory().then(run_next_test); 1.69 + }); 1.70 + }); 1.71 + }); 1.72 +}); 1.73 + 1.74 +add_test(function remove_bookmark_still_bookmarked() 1.75 +{ 1.76 + do_log_info("After removing bookmark, frecency of bookmark's URI should ", 1.77 + "not be zero if URI is still bookmarked."); 1.78 + const TEST_URI = NetUtil.newURI("http://example.com/1"); 1.79 + let id1 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, 1.80 + TEST_URI, 1.81 + PlacesUtils.bookmarks.DEFAULT_INDEX, 1.82 + "bookmark 1 title"); 1.83 + let id2 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, 1.84 + TEST_URI, 1.85 + PlacesUtils.bookmarks.DEFAULT_INDEX, 1.86 + "bookmark 2 title"); 1.87 + promiseAsyncUpdates().then(function () 1.88 + { 1.89 + do_log_info("Bookmarked => frecency of URI should be != 0"); 1.90 + do_check_neq(frecencyForUrl(TEST_URI), 0); 1.91 + 1.92 + PlacesUtils.bookmarks.removeItem(id1); 1.93 + 1.94 + promiseAsyncUpdates().then(function () 1.95 + { 1.96 + do_log_info("URI still bookmarked => frecency should != 0"); 1.97 + do_check_neq(frecencyForUrl(TEST_URI), 0); 1.98 + 1.99 + remove_all_bookmarks(); 1.100 + promiseClearHistory().then(run_next_test); 1.101 + }); 1.102 + }); 1.103 +}); 1.104 + 1.105 +add_test(function cleared_parent_of_visited_bookmark() 1.106 +{ 1.107 + do_log_info("After removing all children from bookmark's parent, frecency " + 1.108 + "of bookmark's URI should not be zero if URI is visited."); 1.109 + const TEST_URI = NetUtil.newURI("http://example.com/1"); 1.110 + let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, 1.111 + TEST_URI, 1.112 + PlacesUtils.bookmarks.DEFAULT_INDEX, 1.113 + "bookmark title"); 1.114 + promiseAsyncUpdates().then(function () 1.115 + { 1.116 + do_log_info("Bookmarked => frecency of URI should be != 0"); 1.117 + do_check_neq(frecencyForUrl(TEST_URI), 0); 1.118 + 1.119 + promiseAddVisits(TEST_URI).then(function () { 1.120 + PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); 1.121 + 1.122 + promiseAsyncUpdates().then(function () 1.123 + { 1.124 + do_log_info("*Visited* URI no longer bookmarked => frecency should != 0"); 1.125 + do_check_neq(frecencyForUrl(TEST_URI), 0); 1.126 + 1.127 + remove_all_bookmarks(); 1.128 + promiseClearHistory().then(run_next_test); 1.129 + }); 1.130 + }); 1.131 + }); 1.132 +}); 1.133 + 1.134 +add_test(function cleared_parent_of_bookmark_still_bookmarked() 1.135 +{ 1.136 + do_log_info("After removing all children from bookmark's parent, frecency " + 1.137 + "of bookmark's URI should not be zero if URI is still " + 1.138 + "bookmarked."); 1.139 + const TEST_URI = NetUtil.newURI("http://example.com/1"); 1.140 + let id1 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.toolbarFolderId, 1.141 + TEST_URI, 1.142 + PlacesUtils.bookmarks.DEFAULT_INDEX, 1.143 + "bookmark 1 title"); 1.144 + 1.145 + let id2 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, 1.146 + TEST_URI, 1.147 + PlacesUtils.bookmarks.DEFAULT_INDEX, 1.148 + "bookmark 2 title"); 1.149 + promiseAsyncUpdates().then(function () 1.150 + { 1.151 + do_log_info("Bookmarked => frecency of URI should be != 0"); 1.152 + do_check_neq(frecencyForUrl(TEST_URI), 0); 1.153 + 1.154 + PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); 1.155 + 1.156 + promiseAsyncUpdates().then(function () 1.157 + { 1.158 + // URI still bookmarked => frecency should != 0. 1.159 + do_check_neq(frecencyForUrl(TEST_URI), 0); 1.160 + 1.161 + remove_all_bookmarks(); 1.162 + promiseClearHistory().then(run_next_test); 1.163 + }); 1.164 + }); 1.165 +}); 1.166 + 1.167 +/////////////////////////////////////////////////////////////////////////////// 1.168 + 1.169 +function run_test() 1.170 +{ 1.171 + run_next_test(); 1.172 +}