toolkit/components/places/tests/unit/test_history_removeAllPages.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 let mDBConn = DBConn();
     9 function promiseOnClearHistoryObserved() {
    10   let deferred = Promise.defer();
    12   let historyObserver = {
    13     onBeginUpdateBatch: function() {},
    14     onEndUpdateBatch: function() {},
    15     onVisit: function() {},
    16     onTitleChanged: function() {},
    17     onDeleteURI: function(aURI) {},
    18     onPageChanged: function() {},
    19     onDeleteVisits: function() {},
    21     onClearHistory: function() {
    22       PlacesUtils.history.removeObserver(this, false);
    23       deferred.resolve();
    24     },
    26     QueryInterface: XPCOMUtils.generateQI([
    27       Ci.nsINavHistoryObserver,
    28     ])
    29   }
    30   PlacesUtils.history.addObserver(historyObserver, false);
    31   return deferred.promise;
    32 }
    34 // This global variable is a promise object, initialized in run_test and waited
    35 // upon in the first asynchronous test.  It is resolved when the
    36 // "places-init-complete" notification is received. We cannot initialize it in
    37 // the asynchronous test, because then it's too late to register the observer.
    38 let promiseInit;
    40 function run_test() {
    41   // places-init-complete is notified after run_test, and it will
    42   // run a first frecency fix through async statements.
    43   // To avoid random failures we have to run after all of this.
    44   promiseInit = promiseTopicObserved(PlacesUtils.TOPIC_INIT_COMPLETE);
    46   run_next_test();
    47 }
    49 add_task(function test_history_removeAllPages()
    50 {
    51   yield promiseInit;
    53   yield promiseAddVisits([
    54     { uri: uri("http://typed.mozilla.org/"),
    55       transition: TRANSITION_TYPED },
    56     { uri: uri("http://link.mozilla.org/"),
    57       transition: TRANSITION_LINK },
    58     { uri: uri("http://download.mozilla.org/"),
    59       transition: TRANSITION_DOWNLOAD },
    60     { uri: uri("http://redir_temp.mozilla.org/"),
    61       transition: TRANSITION_REDIRECT_TEMPORARY,
    62       referrer: "http://link.mozilla.org/"},
    63     { uri: uri("http://redir_perm.mozilla.org/"),
    64       transition: TRANSITION_REDIRECT_PERMANENT,
    65       referrer: "http://link.mozilla.org/"},
    66   ]);
    68   // add a place: bookmark
    69   PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
    70                                        uri("place:folder=4"),
    71                                        PlacesUtils.bookmarks.DEFAULT_INDEX,
    72                                        "shortcut");
    74   // Add an expire never annotation
    75   // Actually expire never annotations are removed as soon as a page is removed
    76   // from the database, so this should act as a normal visit.
    77   PlacesUtils.annotations.setPageAnnotation(uri("http://download.mozilla.org/"),
    78                                             "never", "never", 0,
    79                                             PlacesUtils.annotations.EXPIRE_NEVER);
    81   // Add a bookmark
    82   // Bookmarked page should have history cleared and frecency = -old_visit_count
    83   PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
    84                                        uri("http://typed.mozilla.org/"),
    85                                        PlacesUtils.bookmarks.DEFAULT_INDEX,
    86                                        "bookmark");
    88   yield promiseAddVisits([
    89     { uri: uri("http://typed.mozilla.org/"),
    90       transition: TRANSITION_BOOKMARK },
    91     { uri: uri("http://frecency.mozilla.org/"),
    92       transition: TRANSITION_LINK },
    93   ]);
    94   yield promiseAsyncUpdates();
    96   // Clear history and wait for the onClearHistory notification.
    97   let promiseWaitClearHistory = promiseOnClearHistoryObserved();
    98   PlacesUtils.bhistory.removeAllPages();
    99   yield promiseWaitClearHistory;
   101   // check browserHistory returns no entries
   102   do_check_eq(0, PlacesUtils.history.hasHistoryEntries);
   104   yield promiseTopicObserved(PlacesUtils.TOPIC_EXPIRATION_FINISHED);
   105   yield promiseAsyncUpdates();
   107   // Check that frecency for not cleared items (bookmarks) has been converted
   108   // to -MAX(visit_count, 1), so we will be able to recalculate frecency
   109   // starting from most frecent bookmarks.
   110   stmt = mDBConn.createStatement(
   111     "SELECT h.id FROM moz_places h WHERE h.frecency > 0 ");
   112   do_check_false(stmt.executeStep());
   113   stmt.finalize();
   115   stmt = mDBConn.createStatement(
   116     "SELECT h.id FROM moz_places h WHERE h.frecency < 0 " +
   117       "AND EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) LIMIT 1");
   118   do_check_true(stmt.executeStep());
   119   stmt.finalize();
   121   // Check that all visit_counts have been brought to 0
   122   stmt = mDBConn.createStatement(
   123     "SELECT id FROM moz_places WHERE visit_count <> 0 LIMIT 1");
   124   do_check_false(stmt.executeStep());
   125   stmt.finalize();
   127   // Check that history tables are empty
   128   stmt = mDBConn.createStatement(
   129     "SELECT * FROM (SELECT id FROM moz_historyvisits LIMIT 1)");
   130   do_check_false(stmt.executeStep());
   131   stmt.finalize();
   133   // Check that all moz_places entries except bookmarks and place: have been removed
   134   stmt = mDBConn.createStatement(
   135     "SELECT h.id FROM moz_places h WHERE SUBSTR(h.url, 1, 6) <> 'place:' "+
   136       "AND NOT EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) LIMIT 1");
   137   do_check_false(stmt.executeStep());
   138   stmt.finalize();
   140   // Check that we only have favicons for retained places
   141   stmt = mDBConn.createStatement(
   142     "SELECT f.id FROM moz_favicons f WHERE NOT EXISTS " +
   143       "(SELECT id FROM moz_places WHERE favicon_id = f.id) LIMIT 1");
   144   do_check_false(stmt.executeStep());
   145   stmt.finalize();
   147   // Check that we only have annotations for retained places
   148   stmt = mDBConn.createStatement(
   149     "SELECT a.id FROM moz_annos a WHERE NOT EXISTS " +
   150       "(SELECT id FROM moz_places WHERE id = a.place_id) LIMIT 1");
   151   do_check_false(stmt.executeStep());
   152   stmt.finalize();
   154   // Check that we only have inputhistory for retained places
   155   stmt = mDBConn.createStatement(
   156     "SELECT i.place_id FROM moz_inputhistory i WHERE NOT EXISTS " +
   157       "(SELECT id FROM moz_places WHERE id = i.place_id) LIMIT 1");
   158   do_check_false(stmt.executeStep());
   159   stmt.finalize();
   161   // Check that place:uris have frecency 0
   162   stmt = mDBConn.createStatement(
   163     "SELECT h.id FROM moz_places h " +
   164     "WHERE SUBSTR(h.url, 1, 6) = 'place:' AND h.frecency <> 0 LIMIT 1");
   165   do_check_false(stmt.executeStep());
   166   stmt.finalize();
   167 });

mercurial