1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/expiration/test_outdated_analyze.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Test that expiration executes ANALYZE when statistics are outdated. 1.8 + 1.9 +const TEST_URL = "http://www.mozilla.org/"; 1.10 + 1.11 +XPCOMUtils.defineLazyServiceGetter(this, "gHistory", 1.12 + "@mozilla.org/browser/history;1", 1.13 + "mozIAsyncHistory"); 1.14 + 1.15 +/** 1.16 + * Object that represents a mozIVisitInfo object. 1.17 + * 1.18 + * @param [optional] aTransitionType 1.19 + * The transition type of the visit. Defaults to TRANSITION_LINK if not 1.20 + * provided. 1.21 + * @param [optional] aVisitTime 1.22 + * The time of the visit. Defaults to now if not provided. 1.23 + */ 1.24 +function VisitInfo(aTransitionType, aVisitTime) { 1.25 + this.transitionType = 1.26 + aTransitionType === undefined ? TRANSITION_LINK : aTransitionType; 1.27 + this.visitDate = aVisitTime || Date.now() * 1000; 1.28 +} 1.29 + 1.30 +function run_test() { 1.31 + do_test_pending(); 1.32 + 1.33 + // Init expiration before "importing". 1.34 + force_expiration_start(); 1.35 + 1.36 + // Add a bunch of pages (at laast IMPORT_PAGES_THRESHOLD pages). 1.37 + let places = []; 1.38 + for (let i = 0; i < 100; i++) { 1.39 + places.push({ 1.40 + uri: NetUtil.newURI(TEST_URL + i), 1.41 + title: "Title" + i, 1.42 + visits: [new VisitInfo] 1.43 + }); 1.44 + }; 1.45 + gHistory.updatePlaces(places); 1.46 + 1.47 + // Set interval to a small value to expire on it. 1.48 + setInterval(1); // 1s 1.49 + 1.50 + Services.obs.addObserver(function observeExpiration(aSubject, aTopic, aData) { 1.51 + Services.obs.removeObserver(observeExpiration, 1.52 + PlacesUtils.TOPIC_EXPIRATION_FINISHED); 1.53 + 1.54 + // Check that statistica are up-to-date. 1.55 + let stmt = DBConn().createAsyncStatement( 1.56 + "SELECT (SELECT COUNT(*) FROM moz_places) - " 1.57 + + "(SELECT SUBSTR(stat,1,LENGTH(stat)-2) FROM sqlite_stat1 " 1.58 + + "WHERE idx = 'moz_places_url_uniqueindex')" 1.59 + ); 1.60 + stmt.executeAsync({ 1.61 + handleResult: function(aResultSet) { 1.62 + let row = aResultSet.getNextRow(); 1.63 + this._difference = row.getResultByIndex(0); 1.64 + }, 1.65 + handleError: function(aError) { 1.66 + do_throw("Unexpected error (" + aError.result + "): " + aError.message); 1.67 + }, 1.68 + handleCompletion: function(aReason) { 1.69 + do_check_true(this._difference === 0); 1.70 + do_test_finished(); 1.71 + } 1.72 + }); 1.73 + stmt.finalize(); 1.74 + }, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false); 1.75 +}