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