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: * TEST DESCRIPTION: michael@0: * michael@0: * Tests patch to Bug 412132: michael@0: * https://bugzilla.mozilla.org/show_bug.cgi?id=412132 michael@0: */ michael@0: michael@0: add_task(function changeuri_unvisited_bookmark() michael@0: { michael@0: do_log_info("After changing URI of bookmark, frecency of bookmark's " + michael@0: "original URI should be zero if original URI is unvisited and " + michael@0: "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: yield promiseAsyncUpdates(); 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.changeBookmarkURI(id, uri("http://example.com/2")); michael@0: michael@0: yield promiseAsyncUpdates(); 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: yield promiseClearHistory(); michael@0: }); michael@0: michael@0: add_task(function changeuri_visited_bookmark() michael@0: { michael@0: do_log_info("After changing URI of bookmark, frecency of bookmark's " + michael@0: "original URI should not be zero if original 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: michael@0: yield promiseAsyncUpdates(); 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: yield promiseAddVisits(TEST_URI); michael@0: michael@0: yield promiseAsyncUpdates(); michael@0: michael@0: PlacesUtils.bookmarks.changeBookmarkURI(id, uri("http://example.com/2")); michael@0: michael@0: yield promiseAsyncUpdates(); 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: yield promiseClearHistory(); michael@0: }); michael@0: michael@0: add_task(function changeuri_bookmark_still_bookmarked() michael@0: { michael@0: do_log_info("After changing URI of bookmark, frecency of bookmark's " + michael@0: "original URI should not be zero if original 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.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: michael@0: yield promiseAsyncUpdates(); 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.changeBookmarkURI(id1, uri("http://example.com/2")); michael@0: michael@0: yield promiseAsyncUpdates(); 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: yield promiseClearHistory(); michael@0: }); michael@0: michael@0: add_task(function changeuri_nonexistent_bookmark() michael@0: { michael@0: do_log_info("Changing the URI of a nonexistent bookmark should fail."); michael@0: function tryChange(itemId) michael@0: { michael@0: try { michael@0: PlacesUtils.bookmarks.changeBookmarkURI(itemId + 1, uri("http://example.com/2")); michael@0: do_throw("Nonexistent bookmark should throw."); michael@0: } michael@0: catch (ex) {} michael@0: } michael@0: michael@0: // First try a straight-up bogus item ID, one greater than the current max michael@0: // ID. michael@0: let stmt = DBConn().createStatement("SELECT MAX(id) FROM moz_bookmarks"); michael@0: stmt.executeStep(); michael@0: let maxId = stmt.getInt32(0); michael@0: stmt.finalize(); michael@0: tryChange(maxId + 1); michael@0: michael@0: // Now add a bookmark, delete it, and check. michael@0: let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, michael@0: uri("http://example.com/"), michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, michael@0: "bookmark title"); michael@0: PlacesUtils.bookmarks.removeItem(id); michael@0: tryChange(id); michael@0: michael@0: remove_all_bookmarks(); michael@0: yield promiseClearHistory(); michael@0: }); michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: function run_test() michael@0: { michael@0: run_next_test(); michael@0: }