browser/base/content/test/general/browser_urlbar_search_healthreport.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 add_task(function* test_healthreport_search_recording() {
michael@0 7 try {
michael@0 8 let cm = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
michael@0 9 cm.getCategoryEntry("healthreport-js-provider-default", "SearchesProvider");
michael@0 10 } catch (ex) {
michael@0 11 // Health Report disabled, or no SearchesProvider.
michael@0 12 ok(true, "Firefox Health Report is not enabled.");
michael@0 13 return;
michael@0 14 }
michael@0 15
michael@0 16 let reporter = Cc["@mozilla.org/datareporting/service;1"]
michael@0 17 .getService()
michael@0 18 .wrappedJSObject
michael@0 19 .healthReporter;
michael@0 20 ok(reporter, "Health Reporter available.");
michael@0 21 yield reporter.onInit();
michael@0 22 let provider = reporter.getProvider("org.mozilla.searches");
michael@0 23 ok(provider, "Searches provider is available.");
michael@0 24 let m = provider.getMeasurement("counts", 3);
michael@0 25
michael@0 26 let data = yield m.getValues();
michael@0 27 let now = new Date();
michael@0 28 let oldCount = 0;
michael@0 29
michael@0 30 // This will to be need changed if default search engine is not Google.
michael@0 31 let field = "google.urlbar";
michael@0 32
michael@0 33 if (data.days.hasDay(now)) {
michael@0 34 let day = data.days.getDay(now);
michael@0 35 if (day.has(field)) {
michael@0 36 oldCount = day.get(field);
michael@0 37 }
michael@0 38 }
michael@0 39
michael@0 40 let tab = gBrowser.addTab();
michael@0 41 gBrowser.selectedTab = tab;
michael@0 42
michael@0 43 let searchStr = "firefox health report";
michael@0 44 let expectedURL = Services.search.currentEngine.
michael@0 45 getSubmission(searchStr, "", "keyword").uri.spec;
michael@0 46
michael@0 47 // Expect the search URL to load but stop it as soon as it starts.
michael@0 48 let docLoadPromise = waitForDocLoadAndStopIt(expectedURL);
michael@0 49
michael@0 50 // Trigger the search.
michael@0 51 gURLBar.value = searchStr;
michael@0 52 gURLBar.handleCommand();
michael@0 53
michael@0 54 yield docLoadPromise;
michael@0 55
michael@0 56 function waitForNextTick() {
michael@0 57 let deferred = Promise.defer();
michael@0 58 executeSoon(function () {
michael@0 59 deferred.resolve();
michael@0 60 });
michael@0 61 return deferred.promise;
michael@0 62 }
michael@0 63 yield waitForNextTick();
michael@0 64
michael@0 65 data = yield m.getValues();
michael@0 66 ok(data.days.hasDay(now), "We have a search measurement for today.");
michael@0 67 let day = data.days.getDay(now);
michael@0 68 ok(day.has(field), "Have a search count for the urlbar.");
michael@0 69 let newCount = day.get(field);
michael@0 70 is(newCount, oldCount + 1, "We recorded one new search.");
michael@0 71
michael@0 72 // We should record the default search engine if Telemetry is enabled.
michael@0 73 let oldTelemetry = Services.prefs.getBoolPref("toolkit.telemetry.enabled");
michael@0 74 Services.prefs.setBoolPref("toolkit.telemetry.enabled", true);
michael@0 75
michael@0 76 m = provider.getMeasurement("engines", 1);
michael@0 77 yield provider.collectDailyData();
michael@0 78 data = yield m.getValues();
michael@0 79
michael@0 80 ok(data.days.hasDay(now), "Have engines data when Telemetry is enabled.");
michael@0 81 day = data.days.getDay(now);
michael@0 82 ok(day.has("default"), "We have default engine data.");
michael@0 83 is(day.get("default"), "google", "The default engine is reported properly.");
michael@0 84
michael@0 85 // Restore.
michael@0 86 Services.prefs.setBoolPref("toolkit.telemetry.enabled", oldTelemetry);
michael@0 87
michael@0 88 gBrowser.removeTab(tab);
michael@0 89 });

mercurial