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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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  * Bug 455315
     9  * https://bugzilla.mozilla.org/show_bug.cgi?id=412132
    10  *
    11  * Ensures that the frecency of a bookmark's URI is what it should be after the
    12  * bookmark is deleted.
    13  */
    15 add_test(function removed_bookmark()
    16 {
    17   do_log_info("After removing bookmark, frecency of bookmark's URI should be " +
    18               "zero if URI is unvisited and no longer bookmarked.");
    19   const TEST_URI = NetUtil.newURI("http://example.com/1");
    20   let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
    21                                                 TEST_URI,
    22                                                 PlacesUtils.bookmarks.DEFAULT_INDEX,
    23                                                 "bookmark title");
    24   promiseAsyncUpdates().then(function ()
    25   {
    26     do_log_info("Bookmarked => frecency of URI should be != 0");
    27     do_check_neq(frecencyForUrl(TEST_URI), 0);
    29     PlacesUtils.bookmarks.removeItem(id);
    31     promiseAsyncUpdates().then(function ()
    32     {
    33       do_log_info("Unvisited URI no longer bookmarked => frecency should = 0");
    34       do_check_eq(frecencyForUrl(TEST_URI), 0);
    36       remove_all_bookmarks();
    37       promiseClearHistory().then(run_next_test);
    38     });
    39   });
    40 });
    42 add_test(function removed_but_visited_bookmark()
    43 {
    44   do_log_info("After removing bookmark, frecency of bookmark's URI should " +
    45               "not be zero if URI is visited.");
    46   const TEST_URI = NetUtil.newURI("http://example.com/1");
    47   let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
    48                                                 TEST_URI,
    49                                                 PlacesUtils.bookmarks.DEFAULT_INDEX,
    50                                                 "bookmark title");
    51   promiseAsyncUpdates().then(function ()
    52   {
    53     do_log_info("Bookmarked => frecency of URI should be != 0");
    54     do_check_neq(frecencyForUrl(TEST_URI), 0);
    56     promiseAddVisits(TEST_URI).then(function () {
    57       PlacesUtils.bookmarks.removeItem(id);
    59       promiseAsyncUpdates().then(function ()
    60       {
    61         do_log_info("*Visited* URI no longer bookmarked => frecency should != 0");
    62         do_check_neq(frecencyForUrl(TEST_URI), 0);
    64         remove_all_bookmarks();
    65         promiseClearHistory().then(run_next_test);
    66       });
    67     });
    68   });
    69 });
    71 add_test(function remove_bookmark_still_bookmarked()
    72 {
    73   do_log_info("After removing bookmark, frecency of bookmark's URI should ",
    74               "not be zero if URI is still bookmarked.");
    75   const TEST_URI = NetUtil.newURI("http://example.com/1");
    76   let id1 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
    77                                                  TEST_URI,
    78                                                  PlacesUtils.bookmarks.DEFAULT_INDEX,
    79                                                  "bookmark 1 title");
    80   let id2 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
    81                                                  TEST_URI,
    82                                                  PlacesUtils.bookmarks.DEFAULT_INDEX,
    83                                                  "bookmark 2 title");
    84   promiseAsyncUpdates().then(function ()
    85   {
    86     do_log_info("Bookmarked => frecency of URI should be != 0");
    87     do_check_neq(frecencyForUrl(TEST_URI), 0);
    89     PlacesUtils.bookmarks.removeItem(id1);
    91     promiseAsyncUpdates().then(function ()
    92     {
    93       do_log_info("URI still bookmarked => frecency should != 0");
    94       do_check_neq(frecencyForUrl(TEST_URI), 0);
    96       remove_all_bookmarks();
    97       promiseClearHistory().then(run_next_test);
    98     });
    99   });
   100 });
   102 add_test(function cleared_parent_of_visited_bookmark()
   103 {
   104   do_log_info("After removing all children from bookmark's parent, frecency " +
   105               "of bookmark's URI should not be zero if URI is visited.");
   106   const TEST_URI = NetUtil.newURI("http://example.com/1");
   107   let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
   108                                                 TEST_URI,
   109                                                 PlacesUtils.bookmarks.DEFAULT_INDEX,
   110                                                 "bookmark title");
   111   promiseAsyncUpdates().then(function ()
   112   {
   113     do_log_info("Bookmarked => frecency of URI should be != 0");
   114     do_check_neq(frecencyForUrl(TEST_URI), 0);
   116     promiseAddVisits(TEST_URI).then(function () {
   117       PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
   119       promiseAsyncUpdates().then(function ()
   120       {
   121         do_log_info("*Visited* URI no longer bookmarked => frecency should != 0");
   122         do_check_neq(frecencyForUrl(TEST_URI), 0);
   124         remove_all_bookmarks();
   125         promiseClearHistory().then(run_next_test);
   126       });
   127     });
   128   });
   129 });
   131 add_test(function cleared_parent_of_bookmark_still_bookmarked()
   132 {
   133   do_log_info("After removing all children from bookmark's parent, frecency " +
   134               "of bookmark's URI should not be zero if URI is still " +
   135               "bookmarked.");
   136   const TEST_URI = NetUtil.newURI("http://example.com/1");
   137   let id1 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.toolbarFolderId,
   138                                                  TEST_URI,
   139                                                  PlacesUtils.bookmarks.DEFAULT_INDEX,
   140                                                  "bookmark 1 title");
   142   let id2 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
   143                                                 TEST_URI,
   144                                                 PlacesUtils.bookmarks.DEFAULT_INDEX,
   145                                                 "bookmark 2 title");
   146   promiseAsyncUpdates().then(function ()
   147   {
   148     do_log_info("Bookmarked => frecency of URI should be != 0");
   149     do_check_neq(frecencyForUrl(TEST_URI), 0);
   151     PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
   153     promiseAsyncUpdates().then(function ()
   154     {
   155       // URI still bookmarked => frecency should != 0.
   156       do_check_neq(frecencyForUrl(TEST_URI), 0);
   158       remove_all_bookmarks();
   159       promiseClearHistory().then(run_next_test);
   160     });
   161   });
   162 });
   164 ///////////////////////////////////////////////////////////////////////////////
   166 function run_test()
   167 {
   168   run_next_test();
   169 }

mercurial