|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 "use strict"; |
|
5 |
|
6 function test() { |
|
7 requestLongerTimeout(2); |
|
8 waitForExplicitFinish(); |
|
9 |
|
10 try { |
|
11 let cm = Components.classes["@mozilla.org/categorymanager;1"] |
|
12 .getService(Components.interfaces.nsICategoryManager); |
|
13 cm.getCategoryEntry("healthreport-js-provider-default", "SearchesProvider"); |
|
14 } catch (ex) { |
|
15 // Health Report disabled, or no SearchesProvider. |
|
16 // We need a test or else we'll be marked as failure. |
|
17 ok(true, "Firefox Health Report is not enabled."); |
|
18 finish(); |
|
19 return; |
|
20 } |
|
21 |
|
22 function testFHR() { |
|
23 let reporter = Components.classes["@mozilla.org/datareporting/service;1"] |
|
24 .getService() |
|
25 .wrappedJSObject |
|
26 .healthReporter; |
|
27 ok(reporter, "Health Reporter available."); |
|
28 reporter.onInit().then(function onInit() { |
|
29 let provider = reporter.getProvider("org.mozilla.searches"); |
|
30 let m = provider.getMeasurement("counts", 3); |
|
31 |
|
32 m.getValues().then(function onData(data) { |
|
33 let now = new Date(); |
|
34 let oldCount = 0; |
|
35 |
|
36 // Find the right bucket for the "Foo" engine. |
|
37 let engine = Services.search.getEngineByName("Foo"); |
|
38 let field = (engine.identifier || "other-Foo") + ".searchbar"; |
|
39 |
|
40 if (data.days.hasDay(now)) { |
|
41 let day = data.days.getDay(now); |
|
42 if (day.has(field)) { |
|
43 oldCount = day.get(field); |
|
44 } |
|
45 } |
|
46 |
|
47 // Now perform a search and ensure the count is incremented. |
|
48 let tab = gBrowser.addTab(); |
|
49 gBrowser.selectedTab = tab; |
|
50 let searchBar = BrowserSearch.searchBar; |
|
51 |
|
52 searchBar.value = "firefox health report"; |
|
53 searchBar.focus(); |
|
54 |
|
55 function afterSearch() { |
|
56 searchBar.value = ""; |
|
57 gBrowser.removeTab(tab); |
|
58 |
|
59 m.getValues().then(function onData(data) { |
|
60 ok(data.days.hasDay(now), "Have data for today."); |
|
61 let day = data.days.getDay(now); |
|
62 |
|
63 is(day.get(field), oldCount + 1, "Performing a search increments FHR count by 1."); |
|
64 |
|
65 let engine = Services.search.getEngineByName("Foo"); |
|
66 Services.search.removeEngine(engine); |
|
67 }); |
|
68 } |
|
69 |
|
70 EventUtils.synthesizeKey("VK_RETURN", {}); |
|
71 executeSoon(() => executeSoon(afterSearch)); |
|
72 }); |
|
73 }); |
|
74 } |
|
75 |
|
76 function observer(subject, topic, data) { |
|
77 switch (data) { |
|
78 case "engine-added": |
|
79 let engine = Services.search.getEngineByName("Foo"); |
|
80 ok(engine, "Engine was added."); |
|
81 Services.search.currentEngine = engine; |
|
82 break; |
|
83 |
|
84 case "engine-current": |
|
85 is(Services.search.currentEngine.name, "Foo", "Current engine is Foo"); |
|
86 testFHR(); |
|
87 break; |
|
88 |
|
89 case "engine-removed": |
|
90 Services.obs.removeObserver(observer, "browser-search-engine-modified"); |
|
91 finish(); |
|
92 break; |
|
93 } |
|
94 } |
|
95 |
|
96 Services.obs.addObserver(observer, "browser-search-engine-modified", false); |
|
97 Services.search.addEngine("http://mochi.test:8888/browser/browser/components/search/test/testEngine.xml", |
|
98 Ci.nsISearchEngine.DATA_XML, |
|
99 "data:image/x-icon,%00", |
|
100 false); |
|
101 |
|
102 } |
|
103 |