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.
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/. */
5 var testnum = 0;
6 var fh;
7 var fac;
8 var prefs;
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 }
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 }
40 function run_test() {
41 try {
43 // ===== test init =====
44 var testfile = do_get_file("formhistory_1000.sqlite");
45 var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
46 var results;
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);
54 testfile.copyTo(profileDir, "formhistory.sqlite");
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);
63 timeGroupingSize = prefs.getIntPref("browser.formfill.timeGroupingSize") * 1000 * 1000;
64 maxTimeGroupings = prefs.getIntPref("browser.formfill.maxTimeGroupings");
65 bucketSize = prefs.getIntPref("browser.formfill.bucketSize");
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"));
75 // ===== 2 =====
76 // Search for '' with no previous result
77 testnum++;
78 results = do_AC_search("", null);
79 do_check_true(results.matchCount > 0);
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);
87 // ===== 4 =====
88 // Search for 'r' with '' previous result
89 testnum++;
90 results = do_AC_search("r", "");
91 do_check_true(results.matchCount > 0);
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);
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);
105 // ===== 7 =====
106 // Search for 'rea' without previous result
107 testnum++;
108 results = do_AC_search("rea", null);
109 let countREA = results.matchCount;
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);
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);
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);
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);
137 } catch (e) {
138 throw "FAILED in test #" + testnum + " -- " + e;
139 }
140 }