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