|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 //////////////////////////////////////////////////////////////////////////////// |
|
5 //// Constants |
|
6 |
|
7 const TOPIC_AUTOCOMPLETE_FEEDBACK_INCOMING = "autocomplete-will-enter-text"; |
|
8 |
|
9 //////////////////////////////////////////////////////////////////////////////// |
|
10 //// Helpers |
|
11 |
|
12 /** |
|
13 * Ensures that we have no data in the tables created by ANALYZE. |
|
14 */ |
|
15 function clearAnalyzeData() |
|
16 { |
|
17 let db = DBConn(); |
|
18 if (!db.tableExists("sqlite_stat1")) { |
|
19 return; |
|
20 } |
|
21 db.executeSimpleSQL("DELETE FROM sqlite_stat1"); |
|
22 } |
|
23 |
|
24 /** |
|
25 * Checks that we ran ANALYZE on the specified table. |
|
26 * |
|
27 * @param aTableName |
|
28 * The table to check if ANALYZE was ran. |
|
29 * @param aRan |
|
30 * True if it was expected to run, false otherwise |
|
31 */ |
|
32 function do_check_analyze_ran(aTableName, aRan) |
|
33 { |
|
34 let db = DBConn(); |
|
35 do_check_true(db.tableExists("sqlite_stat1")); |
|
36 let stmt = db.createStatement("SELECT idx FROM sqlite_stat1 WHERE tbl = :table"); |
|
37 stmt.params.table = aTableName; |
|
38 try { |
|
39 if (aRan) { |
|
40 do_check_true(stmt.executeStep()); |
|
41 do_check_neq(stmt.row.idx, null); |
|
42 } |
|
43 else { |
|
44 do_check_false(stmt.executeStep()); |
|
45 } |
|
46 } |
|
47 finally { |
|
48 stmt.finalize(); |
|
49 } |
|
50 } |
|
51 |
|
52 //////////////////////////////////////////////////////////////////////////////// |
|
53 //// Tests |
|
54 |
|
55 function run_test() |
|
56 { |
|
57 run_next_test(); |
|
58 } |
|
59 |
|
60 add_task(function init_tests() |
|
61 { |
|
62 const TEST_URI = NetUtil.newURI("http://mozilla.org/"); |
|
63 const TEST_TITLE = "This is a test"; |
|
64 let bs = PlacesUtils.bookmarks; |
|
65 bs.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, TEST_URI, |
|
66 bs.DEFAULT_INDEX, TEST_TITLE); |
|
67 yield promiseAddVisits(TEST_URI); |
|
68 let thing = { |
|
69 QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteInput, |
|
70 Ci.nsIAutoCompletePopup, |
|
71 Ci.nsIAutoCompleteController]), |
|
72 get popup() { return thing; }, |
|
73 get controller() { return thing; }, |
|
74 popupOpen: true, |
|
75 selectedIndex: 0, |
|
76 getValueAt: function() { return TEST_URI.spec; }, |
|
77 searchString: TEST_TITLE, |
|
78 }; |
|
79 Services.obs.notifyObservers(thing, TOPIC_AUTOCOMPLETE_FEEDBACK_INCOMING, |
|
80 null); |
|
81 }); |
|
82 |
|
83 add_task(function test_timed() |
|
84 { |
|
85 clearAnalyzeData(); |
|
86 |
|
87 // Set a low interval and wait for the timed expiration to start. |
|
88 let promise = promiseTopicObserved(PlacesUtils.TOPIC_EXPIRATION_FINISHED); |
|
89 setInterval(3); |
|
90 yield promise; |
|
91 setInterval(3600); |
|
92 |
|
93 do_check_analyze_ran("moz_places", false); |
|
94 do_check_analyze_ran("moz_bookmarks", false); |
|
95 do_check_analyze_ran("moz_historyvisits", false); |
|
96 do_check_analyze_ran("moz_inputhistory", true); |
|
97 }); |
|
98 |
|
99 add_task(function test_debug() |
|
100 { |
|
101 clearAnalyzeData(); |
|
102 |
|
103 yield promiseForceExpirationStep(1); |
|
104 |
|
105 do_check_analyze_ran("moz_places", true); |
|
106 do_check_analyze_ran("moz_bookmarks", true); |
|
107 do_check_analyze_ran("moz_historyvisits", true); |
|
108 do_check_analyze_ran("moz_inputhistory", true); |
|
109 }); |
|
110 |
|
111 add_task(function test_clear_history() |
|
112 { |
|
113 clearAnalyzeData(); |
|
114 |
|
115 let promise = promiseTopicObserved(PlacesUtils.TOPIC_EXPIRATION_FINISHED); |
|
116 let listener = Cc["@mozilla.org/places/expiration;1"] |
|
117 .getService(Ci.nsINavHistoryObserver); |
|
118 listener.onClearHistory(); |
|
119 yield promise; |
|
120 |
|
121 do_check_analyze_ran("moz_places", true); |
|
122 do_check_analyze_ran("moz_bookmarks", false); |
|
123 do_check_analyze_ran("moz_historyvisits", true); |
|
124 do_check_analyze_ran("moz_inputhistory", true); |
|
125 }); |