toolkit/components/places/tests/unit/test_412132.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  * TEST DESCRIPTION:
     9  *
    10  * Tests patch to Bug 412132:
    11  * https://bugzilla.mozilla.org/show_bug.cgi?id=412132
    12  */
    14 add_task(function changeuri_unvisited_bookmark()
    15 {
    16   do_log_info("After changing URI of bookmark, frecency of bookmark's " +
    17               "original URI should be zero if original URI is unvisited and " +
    18               "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   yield promiseAsyncUpdates();
    26   do_log_info("Bookmarked => frecency of URI should be != 0");
    27   do_check_neq(frecencyForUrl(TEST_URI), 0);
    29   PlacesUtils.bookmarks.changeBookmarkURI(id, uri("http://example.com/2"));
    31   yield promiseAsyncUpdates();
    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   yield promiseClearHistory();
    38 });
    40 add_task(function changeuri_visited_bookmark()
    41 {
    42   do_log_info("After changing URI of bookmark, frecency of bookmark's " +
    43               "original URI should not be zero if original URI is visited.");
    44   const TEST_URI = NetUtil.newURI("http://example.com/1");
    45   let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
    46                                                 TEST_URI,
    47                                                 PlacesUtils.bookmarks.DEFAULT_INDEX,
    48                                                 "bookmark title");
    50   yield promiseAsyncUpdates();
    52   do_log_info("Bookmarked => frecency of URI should be != 0");
    53   do_check_neq(frecencyForUrl(TEST_URI), 0);
    55   yield promiseAddVisits(TEST_URI);
    57   yield promiseAsyncUpdates();
    59   PlacesUtils.bookmarks.changeBookmarkURI(id, uri("http://example.com/2"));
    61   yield promiseAsyncUpdates();
    63   do_log_info("*Visited* URI no longer bookmarked => frecency should != 0");
    64   do_check_neq(frecencyForUrl(TEST_URI), 0);
    66   remove_all_bookmarks();
    67   yield promiseClearHistory();
    68 });
    70 add_task(function changeuri_bookmark_still_bookmarked()
    71 {
    72   do_log_info("After changing URI of bookmark, frecency of bookmark's " +
    73               "original URI should not be zero if original URI is still " +
    74               "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");
    85   yield promiseAsyncUpdates();
    87   do_log_info("Bookmarked => frecency of URI should be != 0");
    88   do_check_neq(frecencyForUrl(TEST_URI), 0);
    90   PlacesUtils.bookmarks.changeBookmarkURI(id1, uri("http://example.com/2"));
    92   yield promiseAsyncUpdates();
    94   do_log_info("URI still bookmarked => frecency should != 0");
    95   do_check_neq(frecencyForUrl(TEST_URI), 0);
    97   remove_all_bookmarks();
    98   yield promiseClearHistory();
    99 });
   101 add_task(function changeuri_nonexistent_bookmark()
   102 {
   103   do_log_info("Changing the URI of a nonexistent bookmark should fail.");
   104   function tryChange(itemId)
   105   {
   106     try {
   107       PlacesUtils.bookmarks.changeBookmarkURI(itemId + 1, uri("http://example.com/2"));
   108       do_throw("Nonexistent bookmark should throw.");
   109     }
   110     catch (ex) {}
   111   }
   113   // First try a straight-up bogus item ID, one greater than the current max
   114   // ID.
   115   let stmt = DBConn().createStatement("SELECT MAX(id) FROM moz_bookmarks");
   116   stmt.executeStep();
   117   let maxId = stmt.getInt32(0);
   118   stmt.finalize();
   119   tryChange(maxId + 1);
   121   // Now add a bookmark, delete it, and check.
   122   let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
   123                                                 uri("http://example.com/"),
   124                                                 PlacesUtils.bookmarks.DEFAULT_INDEX,
   125                                                 "bookmark title");
   126   PlacesUtils.bookmarks.removeItem(id);
   127   tryChange(id);
   129   remove_all_bookmarks();
   130   yield promiseClearHistory();
   131 });
   133 ///////////////////////////////////////////////////////////////////////////////
   135 function run_test()
   136 {
   137   run_next_test();
   138 }

mercurial