michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * Bug 455315 michael@0: * https://bugzilla.mozilla.org/show_bug.cgi?id=412132 michael@0: * michael@0: * Ensures that the frecency of a bookmark's URI is what it should be after the michael@0: * bookmark is deleted. michael@0: */ michael@0: michael@0: add_test(function removed_bookmark() michael@0: { michael@0: do_log_info("After removing bookmark, frecency of bookmark's URI should be " + michael@0: "zero if URI is unvisited and no longer bookmarked."); michael@0: const TEST_URI = NetUtil.newURI("http://example.com/1"); michael@0: let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, michael@0: TEST_URI, michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, michael@0: "bookmark title"); michael@0: promiseAsyncUpdates().then(function () michael@0: { michael@0: do_log_info("Bookmarked => frecency of URI should be != 0"); michael@0: do_check_neq(frecencyForUrl(TEST_URI), 0); michael@0: michael@0: PlacesUtils.bookmarks.removeItem(id); michael@0: michael@0: promiseAsyncUpdates().then(function () michael@0: { michael@0: do_log_info("Unvisited URI no longer bookmarked => frecency should = 0"); michael@0: do_check_eq(frecencyForUrl(TEST_URI), 0); michael@0: michael@0: remove_all_bookmarks(); michael@0: promiseClearHistory().then(run_next_test); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: add_test(function removed_but_visited_bookmark() michael@0: { michael@0: do_log_info("After removing bookmark, frecency of bookmark's URI should " + michael@0: "not be zero if URI is visited."); michael@0: const TEST_URI = NetUtil.newURI("http://example.com/1"); michael@0: let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, michael@0: TEST_URI, michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, michael@0: "bookmark title"); michael@0: promiseAsyncUpdates().then(function () michael@0: { michael@0: do_log_info("Bookmarked => frecency of URI should be != 0"); michael@0: do_check_neq(frecencyForUrl(TEST_URI), 0); michael@0: michael@0: promiseAddVisits(TEST_URI).then(function () { michael@0: PlacesUtils.bookmarks.removeItem(id); michael@0: michael@0: promiseAsyncUpdates().then(function () michael@0: { michael@0: do_log_info("*Visited* URI no longer bookmarked => frecency should != 0"); michael@0: do_check_neq(frecencyForUrl(TEST_URI), 0); michael@0: michael@0: remove_all_bookmarks(); michael@0: promiseClearHistory().then(run_next_test); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: add_test(function remove_bookmark_still_bookmarked() michael@0: { michael@0: do_log_info("After removing bookmark, frecency of bookmark's URI should ", michael@0: "not be zero if URI is still bookmarked."); michael@0: const TEST_URI = NetUtil.newURI("http://example.com/1"); michael@0: let id1 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, michael@0: TEST_URI, michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, michael@0: "bookmark 1 title"); michael@0: let id2 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, michael@0: TEST_URI, michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, michael@0: "bookmark 2 title"); michael@0: promiseAsyncUpdates().then(function () michael@0: { michael@0: do_log_info("Bookmarked => frecency of URI should be != 0"); michael@0: do_check_neq(frecencyForUrl(TEST_URI), 0); michael@0: michael@0: PlacesUtils.bookmarks.removeItem(id1); michael@0: michael@0: promiseAsyncUpdates().then(function () michael@0: { michael@0: do_log_info("URI still bookmarked => frecency should != 0"); michael@0: do_check_neq(frecencyForUrl(TEST_URI), 0); michael@0: michael@0: remove_all_bookmarks(); michael@0: promiseClearHistory().then(run_next_test); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: add_test(function cleared_parent_of_visited_bookmark() michael@0: { michael@0: do_log_info("After removing all children from bookmark's parent, frecency " + michael@0: "of bookmark's URI should not be zero if URI is visited."); michael@0: const TEST_URI = NetUtil.newURI("http://example.com/1"); michael@0: let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, michael@0: TEST_URI, michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, michael@0: "bookmark title"); michael@0: promiseAsyncUpdates().then(function () michael@0: { michael@0: do_log_info("Bookmarked => frecency of URI should be != 0"); michael@0: do_check_neq(frecencyForUrl(TEST_URI), 0); michael@0: michael@0: promiseAddVisits(TEST_URI).then(function () { michael@0: PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); michael@0: michael@0: promiseAsyncUpdates().then(function () michael@0: { michael@0: do_log_info("*Visited* URI no longer bookmarked => frecency should != 0"); michael@0: do_check_neq(frecencyForUrl(TEST_URI), 0); michael@0: michael@0: remove_all_bookmarks(); michael@0: promiseClearHistory().then(run_next_test); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: add_test(function cleared_parent_of_bookmark_still_bookmarked() michael@0: { michael@0: do_log_info("After removing all children from bookmark's parent, frecency " + michael@0: "of bookmark's URI should not be zero if URI is still " + michael@0: "bookmarked."); michael@0: const TEST_URI = NetUtil.newURI("http://example.com/1"); michael@0: let id1 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.toolbarFolderId, michael@0: TEST_URI, michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, michael@0: "bookmark 1 title"); michael@0: michael@0: let id2 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, michael@0: TEST_URI, michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, michael@0: "bookmark 2 title"); michael@0: promiseAsyncUpdates().then(function () michael@0: { michael@0: do_log_info("Bookmarked => frecency of URI should be != 0"); michael@0: do_check_neq(frecencyForUrl(TEST_URI), 0); michael@0: michael@0: PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); michael@0: michael@0: promiseAsyncUpdates().then(function () michael@0: { michael@0: // URI still bookmarked => frecency should != 0. michael@0: do_check_neq(frecencyForUrl(TEST_URI), 0); michael@0: michael@0: remove_all_bookmarks(); michael@0: promiseClearHistory().then(run_next_test); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: function run_test() michael@0: { michael@0: run_next_test(); michael@0: }