|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 var testnum = 0; |
|
6 var fh; |
|
7 var fac; |
|
8 var prefs; |
|
9 |
|
10 function countAllEntries() { |
|
11 let stmt = fh.DBConnection.createStatement("SELECT COUNT(*) as numEntries FROM moz_formhistory"); |
|
12 do_check_true(stmt.executeStep()); |
|
13 let numEntries = stmt.row.numEntries; |
|
14 stmt.finalize(); |
|
15 return numEntries; |
|
16 } |
|
17 |
|
18 function do_AC_search(searchTerm, previousResult) { |
|
19 var duration = 0; |
|
20 var searchCount = 5; |
|
21 var tempPrevious = null; |
|
22 var startTime; |
|
23 for (var i = 0; i < searchCount; i++) { |
|
24 if (previousResult !== null) |
|
25 tempPrevious = fac.autoCompleteSearch("searchbar-history", previousResult, null, null); |
|
26 startTime = Date.now(); |
|
27 results = fac.autoCompleteSearch("searchbar-history", searchTerm, null, tempPrevious); |
|
28 duration += Date.now() - startTime; |
|
29 } |
|
30 dump("[autoCompleteSearch][test " + testnum + "] for '" + searchTerm + "' "); |
|
31 if (previousResult !== null) |
|
32 dump("with '" + previousResult + "' previous result "); |
|
33 else |
|
34 dump("w/o previous result "); |
|
35 dump("took " + duration + " ms with " + results.matchCount + " matches. "); |
|
36 dump("Average of " + Math.round(duration / searchCount) + " ms per search\n"); |
|
37 return results; |
|
38 } |
|
39 |
|
40 function run_test() { |
|
41 try { |
|
42 |
|
43 // ===== test init ===== |
|
44 var testfile = do_get_file("formhistory_1000.sqlite"); |
|
45 var profileDir = dirSvc.get("ProfD", Ci.nsIFile); |
|
46 var results; |
|
47 |
|
48 // Cleanup from any previous tests or failures. |
|
49 var destFile = profileDir.clone(); |
|
50 destFile.append("formhistory.sqlite"); |
|
51 if (destFile.exists()) |
|
52 destFile.remove(false); |
|
53 |
|
54 testfile.copyTo(profileDir, "formhistory.sqlite"); |
|
55 |
|
56 fh = Cc["@mozilla.org/satchel/form-history;1"]. |
|
57 getService(Ci.nsIFormHistory2); |
|
58 fac = Cc["@mozilla.org/satchel/form-autocomplete;1"]. |
|
59 getService(Ci.nsIFormAutoComplete); |
|
60 prefs = Cc["@mozilla.org/preferences-service;1"]. |
|
61 getService(Ci.nsIPrefBranch); |
|
62 |
|
63 timeGroupingSize = prefs.getIntPref("browser.formfill.timeGroupingSize") * 1000 * 1000; |
|
64 maxTimeGroupings = prefs.getIntPref("browser.formfill.maxTimeGroupings"); |
|
65 bucketSize = prefs.getIntPref("browser.formfill.bucketSize"); |
|
66 |
|
67 // ===== 1 ===== |
|
68 // Check initial state is as expected |
|
69 testnum++; |
|
70 do_check_true(fh.hasEntries); |
|
71 do_check_eq(1000, countAllEntries()); |
|
72 fac.autoCompleteSearch("searchbar-history", "zzzzzzzzzz", null, null); // warm-up search |
|
73 do_check_true(fh.nameExists("searchbar-history")); |
|
74 |
|
75 // ===== 2 ===== |
|
76 // Search for '' with no previous result |
|
77 testnum++; |
|
78 results = do_AC_search("", null); |
|
79 do_check_true(results.matchCount > 0); |
|
80 |
|
81 // ===== 3 ===== |
|
82 // Search for 'r' with no previous result |
|
83 testnum++; |
|
84 results = do_AC_search("r", null); |
|
85 do_check_true(results.matchCount > 0); |
|
86 |
|
87 // ===== 4 ===== |
|
88 // Search for 'r' with '' previous result |
|
89 testnum++; |
|
90 results = do_AC_search("r", ""); |
|
91 do_check_true(results.matchCount > 0); |
|
92 |
|
93 // ===== 5 ===== |
|
94 // Search for 're' with no previous result |
|
95 testnum++; |
|
96 results = do_AC_search("re", null); |
|
97 do_check_true(results.matchCount > 0); |
|
98 |
|
99 // ===== 6 ===== |
|
100 // Search for 're' with 'r' previous result |
|
101 testnum++; |
|
102 results = do_AC_search("re", "r"); |
|
103 do_check_true(results.matchCount > 0); |
|
104 |
|
105 // ===== 7 ===== |
|
106 // Search for 'rea' without previous result |
|
107 testnum++; |
|
108 results = do_AC_search("rea", null); |
|
109 let countREA = results.matchCount; |
|
110 |
|
111 // ===== 8 ===== |
|
112 // Search for 'rea' with 're' previous result |
|
113 testnum++; |
|
114 results = do_AC_search("rea", "re"); |
|
115 do_check_eq(countREA, results.matchCount); |
|
116 |
|
117 // ===== 9 ===== |
|
118 // Search for 'real' with 'rea' previous result |
|
119 testnum++; |
|
120 results = do_AC_search("real", "rea"); |
|
121 let countREAL = results.matchCount; |
|
122 do_check_true(results.matchCount <= countREA); |
|
123 |
|
124 // ===== 10 ===== |
|
125 // Search for 'real' with 're' previous result |
|
126 testnum++; |
|
127 results = do_AC_search("real", "re"); |
|
128 do_check_eq(countREAL, results.matchCount); |
|
129 |
|
130 // ===== 11 ===== |
|
131 // Search for 'real' with no previous result |
|
132 testnum++; |
|
133 results = do_AC_search("real", null); |
|
134 do_check_eq(countREAL, results.matchCount); |
|
135 |
|
136 |
|
137 } catch (e) { |
|
138 throw "FAILED in test #" + testnum + " -- " + e; |
|
139 } |
|
140 } |