toolkit/components/places/tests/unit/test_412132.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/unit/test_412132.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,138 @@
     1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +/*
    1.11 + * TEST DESCRIPTION:
    1.12 + *
    1.13 + * Tests patch to Bug 412132:
    1.14 + * https://bugzilla.mozilla.org/show_bug.cgi?id=412132
    1.15 + */
    1.16 +
    1.17 +add_task(function changeuri_unvisited_bookmark()
    1.18 +{
    1.19 +  do_log_info("After changing URI of bookmark, frecency of bookmark's " +
    1.20 +              "original URI should be zero if original URI is unvisited and " +
    1.21 +              "no longer bookmarked.");
    1.22 +  const TEST_URI = NetUtil.newURI("http://example.com/1");
    1.23 +  let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
    1.24 +                                                TEST_URI,
    1.25 +                                                PlacesUtils.bookmarks.DEFAULT_INDEX,
    1.26 +                                                "bookmark title");
    1.27 +  yield promiseAsyncUpdates();
    1.28 +
    1.29 +  do_log_info("Bookmarked => frecency of URI should be != 0");
    1.30 +  do_check_neq(frecencyForUrl(TEST_URI), 0);
    1.31 +
    1.32 +  PlacesUtils.bookmarks.changeBookmarkURI(id, uri("http://example.com/2"));
    1.33 +
    1.34 +  yield promiseAsyncUpdates();
    1.35 +
    1.36 +  do_log_info("Unvisited URI no longer bookmarked => frecency should = 0");
    1.37 +  do_check_eq(frecencyForUrl(TEST_URI), 0);
    1.38 +
    1.39 +  remove_all_bookmarks();
    1.40 +  yield promiseClearHistory();
    1.41 +});
    1.42 +
    1.43 +add_task(function changeuri_visited_bookmark()
    1.44 +{
    1.45 +  do_log_info("After changing URI of bookmark, frecency of bookmark's " +
    1.46 +              "original URI should not be zero if original URI is visited.");
    1.47 +  const TEST_URI = NetUtil.newURI("http://example.com/1");
    1.48 +  let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
    1.49 +                                                TEST_URI,
    1.50 +                                                PlacesUtils.bookmarks.DEFAULT_INDEX,
    1.51 +                                                "bookmark title");
    1.52 +
    1.53 +  yield promiseAsyncUpdates();
    1.54 +
    1.55 +  do_log_info("Bookmarked => frecency of URI should be != 0");
    1.56 +  do_check_neq(frecencyForUrl(TEST_URI), 0);
    1.57 +
    1.58 +  yield promiseAddVisits(TEST_URI);
    1.59 +
    1.60 +  yield promiseAsyncUpdates();
    1.61 +
    1.62 +  PlacesUtils.bookmarks.changeBookmarkURI(id, uri("http://example.com/2"));
    1.63 +
    1.64 +  yield promiseAsyncUpdates();
    1.65 +
    1.66 +  do_log_info("*Visited* URI no longer bookmarked => frecency should != 0");
    1.67 +  do_check_neq(frecencyForUrl(TEST_URI), 0);
    1.68 +
    1.69 +  remove_all_bookmarks();
    1.70 +  yield promiseClearHistory();
    1.71 +});
    1.72 +
    1.73 +add_task(function changeuri_bookmark_still_bookmarked()
    1.74 +{
    1.75 +  do_log_info("After changing URI of bookmark, frecency of bookmark's " +
    1.76 +              "original URI should not be zero if original URI is still " +
    1.77 +              "bookmarked.");
    1.78 +  const TEST_URI = NetUtil.newURI("http://example.com/1");
    1.79 +  let id1 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
    1.80 +                                                 TEST_URI,
    1.81 +                                                 PlacesUtils.bookmarks.DEFAULT_INDEX,
    1.82 +                                                 "bookmark 1 title");
    1.83 +  let id2 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
    1.84 +                                                 TEST_URI,
    1.85 +                                                 PlacesUtils.bookmarks.DEFAULT_INDEX,
    1.86 +                                                 "bookmark 2 title");
    1.87 +
    1.88 +  yield promiseAsyncUpdates();
    1.89 +
    1.90 +  do_log_info("Bookmarked => frecency of URI should be != 0");
    1.91 +  do_check_neq(frecencyForUrl(TEST_URI), 0);
    1.92 +
    1.93 +  PlacesUtils.bookmarks.changeBookmarkURI(id1, uri("http://example.com/2"));
    1.94 +
    1.95 +  yield promiseAsyncUpdates();
    1.96 +
    1.97 +  do_log_info("URI still bookmarked => frecency should != 0");
    1.98 +  do_check_neq(frecencyForUrl(TEST_URI), 0);
    1.99 +
   1.100 +  remove_all_bookmarks();
   1.101 +  yield promiseClearHistory();
   1.102 +});
   1.103 +
   1.104 +add_task(function changeuri_nonexistent_bookmark()
   1.105 +{
   1.106 +  do_log_info("Changing the URI of a nonexistent bookmark should fail.");
   1.107 +  function tryChange(itemId)
   1.108 +  {
   1.109 +    try {
   1.110 +      PlacesUtils.bookmarks.changeBookmarkURI(itemId + 1, uri("http://example.com/2"));
   1.111 +      do_throw("Nonexistent bookmark should throw.");
   1.112 +    }
   1.113 +    catch (ex) {}
   1.114 +  }
   1.115 +
   1.116 +  // First try a straight-up bogus item ID, one greater than the current max
   1.117 +  // ID.
   1.118 +  let stmt = DBConn().createStatement("SELECT MAX(id) FROM moz_bookmarks");
   1.119 +  stmt.executeStep();
   1.120 +  let maxId = stmt.getInt32(0);
   1.121 +  stmt.finalize();
   1.122 +  tryChange(maxId + 1);
   1.123 +
   1.124 +  // Now add a bookmark, delete it, and check.
   1.125 +  let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
   1.126 +                                                uri("http://example.com/"),
   1.127 +                                                PlacesUtils.bookmarks.DEFAULT_INDEX,
   1.128 +                                                "bookmark title");
   1.129 +  PlacesUtils.bookmarks.removeItem(id);
   1.130 +  tryChange(id);
   1.131 +
   1.132 +  remove_all_bookmarks();
   1.133 +  yield promiseClearHistory();
   1.134 +});
   1.135 +
   1.136 +///////////////////////////////////////////////////////////////////////////////
   1.137 +
   1.138 +function run_test()
   1.139 +{
   1.140 +  run_next_test();
   1.141 +}

mercurial