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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7  /**
     8   * Test bookmarksService.getBookmarkedURIFor(aURI);
     9   */
    11 let hs = PlacesUtils.history;
    12 let bs = PlacesUtils.bookmarks;
    14 function run_test() {
    15   run_next_test();
    16 }
    18 add_task(function test_getBookmarkedURIFor() {
    19   let now = Date.now() * 1000;
    20   const sourceURI = uri("http://test.mozilla.org/");
    21   // Add a visit and a bookmark.
    22   yield promiseAddVisits({ uri: sourceURI, visitDate: now });
    23   do_check_eq(bs.getBookmarkedURIFor(sourceURI), null);
    25   let sourceItemId = bs.insertBookmark(bs.unfiledBookmarksFolder,
    26                                        sourceURI,
    27                                        bs.DEFAULT_INDEX,
    28                                        "bookmark");
    29   do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI));
    31   // Add a redirected visit.
    32   const permaURI = uri("http://perma.mozilla.org/");
    33   yield promiseAddVisits({
    34     uri: permaURI,
    35     transition: TRANSITION_REDIRECT_PERMANENT,
    36     visitDate: now++,
    37     referrer: sourceURI
    38   });
    39   do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI));
    40   do_check_true(bs.getBookmarkedURIFor(permaURI).equals(sourceURI));
    41   // Add a bookmark to the destination.
    42   let permaItemId = bs.insertBookmark(bs.unfiledBookmarksFolder,
    43                                       permaURI,
    44                                       bs.DEFAULT_INDEX,
    45                                       "bookmark");
    46   do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI));
    47   do_check_true(bs.getBookmarkedURIFor(permaURI).equals(permaURI));
    48   // Now remove the bookmark on the destination.
    49   bs.removeItem(permaItemId);
    50   // We should see the source as bookmark.
    51   do_check_true(bs.getBookmarkedURIFor(permaURI).equals(sourceURI));
    53   // Add another redirected visit.
    54   const tempURI = uri("http://perma.mozilla.org/");
    55   yield promiseAddVisits({
    56     uri: tempURI,
    57     transition: TRANSITION_REDIRECT_TEMPORARY,
    58     visitDate: now++,
    59     referrer: permaURI
    60   });
    62   do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI));
    63   do_check_true(bs.getBookmarkedURIFor(tempURI).equals(sourceURI));
    64   // Add a bookmark to the destination.
    65   let tempItemId = bs.insertBookmark(bs.unfiledBookmarksFolder,
    66                                      tempURI,
    67                                      bs.DEFAULT_INDEX,
    68                                      "bookmark");
    69   do_check_true(bs.getBookmarkedURIFor(sourceURI).equals(sourceURI));
    70   do_check_true(bs.getBookmarkedURIFor(tempURI).equals(tempURI));
    72   // Now remove the bookmark on the destination.
    73   bs.removeItem(tempItemId);
    74   // We should see the source as bookmark.
    75   do_check_true(bs.getBookmarkedURIFor(tempURI).equals(sourceURI));
    76   // Remove the source bookmark as well.
    77   bs.removeItem(sourceItemId);
    78   do_check_eq(bs.getBookmarkedURIFor(tempURI), null);
    80   // Try to pass in a never seen URI, should return null and a new entry should
    81   // not be added to the database.
    82   do_check_eq(bs.getBookmarkedURIFor(uri("http://does.not.exist/")), null);
    83   do_check_false(page_in_database("http://does.not.exist/"));
    84 });

mercurial