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 bookmarksService.getBookmarkedURIFor(aURI); michael@0: */ michael@0: michael@0: let hs = PlacesUtils.history; michael@0: let bs = PlacesUtils.bookmarks; michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function test_getBookmarkedURIFor() { michael@0: let now = Date.now() * 1000; michael@0: const sourceURI = uri("http://test.mozilla.org/"); michael@0: // Add a visit and a bookmark. michael@0: yield promiseAddVisits({ uri: sourceURI, visitDate: now }); michael@0: do_check_eq(bs.getBookmarkedURIFor(sourceURI), null); michael@0: michael@0: let sourceItemId = bs.insertBookmark(bs.unfiledBookmarksFolder, michael@0: sourceURI, michael@0: bs.DEFAULT_INDEX, michael@0: "bookmark"); michael@0: do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI)); michael@0: michael@0: // Add a redirected visit. michael@0: const permaURI = uri("http://perma.mozilla.org/"); michael@0: yield promiseAddVisits({ michael@0: uri: permaURI, michael@0: transition: TRANSITION_REDIRECT_PERMANENT, michael@0: visitDate: now++, michael@0: referrer: sourceURI michael@0: }); michael@0: do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI)); michael@0: do_check_true(bs.getBookmarkedURIFor(permaURI).equals(sourceURI)); michael@0: // Add a bookmark to the destination. michael@0: let permaItemId = bs.insertBookmark(bs.unfiledBookmarksFolder, michael@0: permaURI, michael@0: bs.DEFAULT_INDEX, michael@0: "bookmark"); michael@0: do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI)); michael@0: do_check_true(bs.getBookmarkedURIFor(permaURI).equals(permaURI)); michael@0: // Now remove the bookmark on the destination. michael@0: bs.removeItem(permaItemId); michael@0: // We should see the source as bookmark. michael@0: do_check_true(bs.getBookmarkedURIFor(permaURI).equals(sourceURI)); michael@0: michael@0: // Add another redirected visit. michael@0: const tempURI = uri("http://perma.mozilla.org/"); michael@0: yield promiseAddVisits({ michael@0: uri: tempURI, michael@0: transition: TRANSITION_REDIRECT_TEMPORARY, michael@0: visitDate: now++, michael@0: referrer: permaURI michael@0: }); michael@0: michael@0: do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI)); michael@0: do_check_true(bs.getBookmarkedURIFor(tempURI).equals(sourceURI)); michael@0: // Add a bookmark to the destination. michael@0: let tempItemId = bs.insertBookmark(bs.unfiledBookmarksFolder, michael@0: tempURI, michael@0: bs.DEFAULT_INDEX, michael@0: "bookmark"); michael@0: do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI)); michael@0: do_check_true(bs.getBookmarkedURIFor(tempURI).equals(tempURI)); michael@0: michael@0: // Now remove the bookmark on the destination. michael@0: bs.removeItem(tempItemId); michael@0: // We should see the source as bookmark. michael@0: do_check_true(bs.getBookmarkedURIFor(tempURI).equals(sourceURI)); michael@0: // Remove the source bookmark as well. michael@0: bs.removeItem(sourceItemId); michael@0: do_check_eq(bs.getBookmarkedURIFor(tempURI), null); michael@0: michael@0: // Try to pass in a never seen URI, should return null and a new entry should michael@0: // not be added to the database. michael@0: do_check_eq(bs.getBookmarkedURIFor(uri("http://does.not.exist/")), null); michael@0: do_check_false(page_in_database("http://does.not.exist/")); michael@0: });