michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Test that expiration executes ANALYZE when statistics are outdated. michael@0: michael@0: const TEST_URL = "http://www.mozilla.org/"; michael@0: michael@0: XPCOMUtils.defineLazyServiceGetter(this, "gHistory", michael@0: "@mozilla.org/browser/history;1", michael@0: "mozIAsyncHistory"); michael@0: michael@0: /** michael@0: * Object that represents a mozIVisitInfo object. michael@0: * michael@0: * @param [optional] aTransitionType michael@0: * The transition type of the visit. Defaults to TRANSITION_LINK if not michael@0: * provided. michael@0: * @param [optional] aVisitTime michael@0: * The time of the visit. Defaults to now if not provided. michael@0: */ michael@0: function VisitInfo(aTransitionType, aVisitTime) { michael@0: this.transitionType = michael@0: aTransitionType === undefined ? TRANSITION_LINK : aTransitionType; michael@0: this.visitDate = aVisitTime || Date.now() * 1000; michael@0: } michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: michael@0: // Init expiration before "importing". michael@0: force_expiration_start(); michael@0: michael@0: // Add a bunch of pages (at laast IMPORT_PAGES_THRESHOLD pages). michael@0: let places = []; michael@0: for (let i = 0; i < 100; i++) { michael@0: places.push({ michael@0: uri: NetUtil.newURI(TEST_URL + i), michael@0: title: "Title" + i, michael@0: visits: [new VisitInfo] michael@0: }); michael@0: }; michael@0: gHistory.updatePlaces(places); michael@0: michael@0: // Set interval to a small value to expire on it. michael@0: setInterval(1); // 1s michael@0: michael@0: Services.obs.addObserver(function observeExpiration(aSubject, aTopic, aData) { michael@0: Services.obs.removeObserver(observeExpiration, michael@0: PlacesUtils.TOPIC_EXPIRATION_FINISHED); michael@0: michael@0: // Check that statistica are up-to-date. michael@0: let stmt = DBConn().createAsyncStatement( michael@0: "SELECT (SELECT COUNT(*) FROM moz_places) - " michael@0: + "(SELECT SUBSTR(stat,1,LENGTH(stat)-2) FROM sqlite_stat1 " michael@0: + "WHERE idx = 'moz_places_url_uniqueindex')" michael@0: ); michael@0: stmt.executeAsync({ michael@0: handleResult: function(aResultSet) { michael@0: let row = aResultSet.getNextRow(); michael@0: this._difference = row.getResultByIndex(0); michael@0: }, michael@0: handleError: function(aError) { michael@0: do_throw("Unexpected error (" + aError.result + "): " + aError.message); michael@0: }, michael@0: handleCompletion: function(aReason) { michael@0: do_check_true(this._difference === 0); michael@0: do_test_finished(); michael@0: } michael@0: }); michael@0: stmt.finalize(); michael@0: }, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false); michael@0: }