diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /toolkit/components/places/tests/expiration/test_outdated_analyze.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/components/places/tests/expiration/test_outdated_analyze.js')
-rw-r--r-- | toolkit/components/places/tests/expiration/test_outdated_analyze.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/toolkit/components/places/tests/expiration/test_outdated_analyze.js b/toolkit/components/places/tests/expiration/test_outdated_analyze.js new file mode 100644 index 000000000..9cf61f06b --- /dev/null +++ b/toolkit/components/places/tests/expiration/test_outdated_analyze.js @@ -0,0 +1,72 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that expiration executes ANALYZE when statistics are outdated. + +const TEST_URL = "http://www.mozilla.org/"; + +XPCOMUtils.defineLazyServiceGetter(this, "gHistory", + "@mozilla.org/browser/history;1", + "mozIAsyncHistory"); + +/** + * Object that represents a mozIVisitInfo object. + * + * @param [optional] aTransitionType + * The transition type of the visit. Defaults to TRANSITION_LINK if not + * provided. + * @param [optional] aVisitTime + * The time of the visit. Defaults to now if not provided. + */ +function VisitInfo(aTransitionType, aVisitTime) { + this.transitionType = + aTransitionType === undefined ? TRANSITION_LINK : aTransitionType; + this.visitDate = aVisitTime || Date.now() * 1000; +} + +function run_test() { + do_test_pending(); + + // Init expiration before "importing". + force_expiration_start(); + + // Add a bunch of pages (at laast IMPORT_PAGES_THRESHOLD pages). + let places = []; + for (let i = 0; i < 100; i++) { + places.push({ + uri: NetUtil.newURI(TEST_URL + i), + title: "Title" + i, + visits: [new VisitInfo] + }); + } + gHistory.updatePlaces(places); + + // Set interval to a small value to expire on it. + setInterval(1); // 1s + + Services.obs.addObserver(function observeExpiration(aSubject, aTopic, aData) { + Services.obs.removeObserver(observeExpiration, + PlacesUtils.TOPIC_EXPIRATION_FINISHED); + + // Check that statistica are up-to-date. + let stmt = DBConn().createAsyncStatement( + "SELECT (SELECT COUNT(*) FROM moz_places) - " + + "(SELECT SUBSTR(stat,1,LENGTH(stat)-2) FROM sqlite_stat1 " + + "WHERE idx = 'moz_places_url_hashindex')" + ); + stmt.executeAsync({ + handleResult: function(aResultSet) { + let row = aResultSet.getNextRow(); + this._difference = row.getResultByIndex(0); + }, + handleError: function(aError) { + do_throw("Unexpected error (" + aError.result + "): " + aError.message); + }, + handleCompletion: function(aReason) { + do_check_true(this._difference === 0); + do_test_finished(); + } + }); + stmt.finalize(); + }, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false); +} |