toolkit/components/places/tests/bookmarks/test_getBookmarkedURIFor.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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 * Test bookmarksService.getBookmarkedURIFor(aURI);
michael@0 9 */
michael@0 10
michael@0 11 let hs = PlacesUtils.history;
michael@0 12 let bs = PlacesUtils.bookmarks;
michael@0 13
michael@0 14 function run_test() {
michael@0 15 run_next_test();
michael@0 16 }
michael@0 17
michael@0 18 add_task(function test_getBookmarkedURIFor() {
michael@0 19 let now = Date.now() * 1000;
michael@0 20 const sourceURI = uri("http://test.mozilla.org/");
michael@0 21 // Add a visit and a bookmark.
michael@0 22 yield promiseAddVisits({ uri: sourceURI, visitDate: now });
michael@0 23 do_check_eq(bs.getBookmarkedURIFor(sourceURI), null);
michael@0 24
michael@0 25 let sourceItemId = bs.insertBookmark(bs.unfiledBookmarksFolder,
michael@0 26 sourceURI,
michael@0 27 bs.DEFAULT_INDEX,
michael@0 28 "bookmark");
michael@0 29 do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI));
michael@0 30
michael@0 31 // Add a redirected visit.
michael@0 32 const permaURI = uri("http://perma.mozilla.org/");
michael@0 33 yield promiseAddVisits({
michael@0 34 uri: permaURI,
michael@0 35 transition: TRANSITION_REDIRECT_PERMANENT,
michael@0 36 visitDate: now++,
michael@0 37 referrer: sourceURI
michael@0 38 });
michael@0 39 do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI));
michael@0 40 do_check_true(bs.getBookmarkedURIFor(permaURI).equals(sourceURI));
michael@0 41 // Add a bookmark to the destination.
michael@0 42 let permaItemId = bs.insertBookmark(bs.unfiledBookmarksFolder,
michael@0 43 permaURI,
michael@0 44 bs.DEFAULT_INDEX,
michael@0 45 "bookmark");
michael@0 46 do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI));
michael@0 47 do_check_true(bs.getBookmarkedURIFor(permaURI).equals(permaURI));
michael@0 48 // Now remove the bookmark on the destination.
michael@0 49 bs.removeItem(permaItemId);
michael@0 50 // We should see the source as bookmark.
michael@0 51 do_check_true(bs.getBookmarkedURIFor(permaURI).equals(sourceURI));
michael@0 52
michael@0 53 // Add another redirected visit.
michael@0 54 const tempURI = uri("http://perma.mozilla.org/");
michael@0 55 yield promiseAddVisits({
michael@0 56 uri: tempURI,
michael@0 57 transition: TRANSITION_REDIRECT_TEMPORARY,
michael@0 58 visitDate: now++,
michael@0 59 referrer: permaURI
michael@0 60 });
michael@0 61
michael@0 62 do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI));
michael@0 63 do_check_true(bs.getBookmarkedURIFor(tempURI).equals(sourceURI));
michael@0 64 // Add a bookmark to the destination.
michael@0 65 let tempItemId = bs.insertBookmark(bs.unfiledBookmarksFolder,
michael@0 66 tempURI,
michael@0 67 bs.DEFAULT_INDEX,
michael@0 68 "bookmark");
michael@0 69 do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI));
michael@0 70 do_check_true(bs.getBookmarkedURIFor(tempURI).equals(tempURI));
michael@0 71
michael@0 72 // Now remove the bookmark on the destination.
michael@0 73 bs.removeItem(tempItemId);
michael@0 74 // We should see the source as bookmark.
michael@0 75 do_check_true(bs.getBookmarkedURIFor(tempURI).equals(sourceURI));
michael@0 76 // Remove the source bookmark as well.
michael@0 77 bs.removeItem(sourceItemId);
michael@0 78 do_check_eq(bs.getBookmarkedURIFor(tempURI), null);
michael@0 79
michael@0 80 // Try to pass in a never seen URI, should return null and a new entry should
michael@0 81 // not be added to the database.
michael@0 82 do_check_eq(bs.getBookmarkedURIFor(uri("http://does.not.exist/")), null);
michael@0 83 do_check_false(page_in_database("http://does.not.exist/"));
michael@0 84 });

mercurial