toolkit/components/places/tests/expiration/test_outdated_analyze.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 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 // Test that expiration executes ANALYZE when statistics are outdated.
     6 const TEST_URL = "http://www.mozilla.org/";
     8 XPCOMUtils.defineLazyServiceGetter(this, "gHistory",
     9                                    "@mozilla.org/browser/history;1",
    10                                    "mozIAsyncHistory");
    12 /**
    13  * Object that represents a mozIVisitInfo object.
    14  *
    15  * @param [optional] aTransitionType
    16  *        The transition type of the visit.  Defaults to TRANSITION_LINK if not
    17  *        provided.
    18  * @param [optional] aVisitTime
    19  *        The time of the visit.  Defaults to now if not provided.
    20  */
    21 function VisitInfo(aTransitionType, aVisitTime) {
    22   this.transitionType =
    23     aTransitionType === undefined ? TRANSITION_LINK : aTransitionType;
    24   this.visitDate = aVisitTime || Date.now() * 1000;
    25 }
    27 function run_test() {
    28   do_test_pending();
    30   // Init expiration before "importing".
    31   force_expiration_start();
    33   // Add a bunch of pages (at laast IMPORT_PAGES_THRESHOLD pages).
    34   let places = [];
    35   for (let i = 0; i < 100; i++) {
    36     places.push({
    37       uri: NetUtil.newURI(TEST_URL + i),
    38       title: "Title" + i,
    39       visits: [new VisitInfo]
    40     });
    41   };
    42   gHistory.updatePlaces(places);
    44   // Set interval to a small value to expire on it.
    45   setInterval(1); // 1s
    47   Services.obs.addObserver(function observeExpiration(aSubject, aTopic, aData) {
    48     Services.obs.removeObserver(observeExpiration,
    49                                 PlacesUtils.TOPIC_EXPIRATION_FINISHED);
    51     // Check that statistica are up-to-date.
    52     let stmt = DBConn().createAsyncStatement(
    53       "SELECT (SELECT COUNT(*) FROM moz_places) - "
    54       +        "(SELECT SUBSTR(stat,1,LENGTH(stat)-2) FROM sqlite_stat1 "
    55       +         "WHERE idx = 'moz_places_url_uniqueindex')"
    56     );
    57     stmt.executeAsync({
    58       handleResult: function(aResultSet) {
    59         let row = aResultSet.getNextRow();
    60         this._difference = row.getResultByIndex(0);
    61       },
    62       handleError: function(aError) {
    63         do_throw("Unexpected error (" + aError.result + "): " + aError.message);
    64       },
    65       handleCompletion: function(aReason) {
    66         do_check_true(this._difference === 0);
    67         do_test_finished();
    68       }
    69     });
    70     stmt.finalize();
    71   }, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false);
    72 }

mercurial