|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // Test that expiration executes ANALYZE when statistics are outdated. |
|
5 |
|
6 const TEST_URL = "http://www.mozilla.org/"; |
|
7 |
|
8 XPCOMUtils.defineLazyServiceGetter(this, "gHistory", |
|
9 "@mozilla.org/browser/history;1", |
|
10 "mozIAsyncHistory"); |
|
11 |
|
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 } |
|
26 |
|
27 function run_test() { |
|
28 do_test_pending(); |
|
29 |
|
30 // Init expiration before "importing". |
|
31 force_expiration_start(); |
|
32 |
|
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); |
|
43 |
|
44 // Set interval to a small value to expire on it. |
|
45 setInterval(1); // 1s |
|
46 |
|
47 Services.obs.addObserver(function observeExpiration(aSubject, aTopic, aData) { |
|
48 Services.obs.removeObserver(observeExpiration, |
|
49 PlacesUtils.TOPIC_EXPIRATION_FINISHED); |
|
50 |
|
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 } |