michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: add_task(function* test_healthreport_search_recording() { michael@0: try { michael@0: let cm = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager); michael@0: cm.getCategoryEntry("healthreport-js-provider-default", "SearchesProvider"); michael@0: } catch (ex) { michael@0: // Health Report disabled, or no SearchesProvider. michael@0: ok(true, "Firefox Health Report is not enabled."); michael@0: return; michael@0: } michael@0: michael@0: let reporter = Cc["@mozilla.org/datareporting/service;1"] michael@0: .getService() michael@0: .wrappedJSObject michael@0: .healthReporter; michael@0: ok(reporter, "Health Reporter available."); michael@0: yield reporter.onInit(); michael@0: let provider = reporter.getProvider("org.mozilla.searches"); michael@0: ok(provider, "Searches provider is available."); michael@0: let m = provider.getMeasurement("counts", 3); michael@0: michael@0: let data = yield m.getValues(); michael@0: let now = new Date(); michael@0: let oldCount = 0; michael@0: michael@0: // This will to be need changed if default search engine is not Google. michael@0: let field = "google.urlbar"; michael@0: michael@0: if (data.days.hasDay(now)) { michael@0: let day = data.days.getDay(now); michael@0: if (day.has(field)) { michael@0: oldCount = day.get(field); michael@0: } michael@0: } michael@0: michael@0: let tab = gBrowser.addTab(); michael@0: gBrowser.selectedTab = tab; michael@0: michael@0: let searchStr = "firefox health report"; michael@0: let expectedURL = Services.search.currentEngine. michael@0: getSubmission(searchStr, "", "keyword").uri.spec; michael@0: michael@0: // Expect the search URL to load but stop it as soon as it starts. michael@0: let docLoadPromise = waitForDocLoadAndStopIt(expectedURL); michael@0: michael@0: // Trigger the search. michael@0: gURLBar.value = searchStr; michael@0: gURLBar.handleCommand(); michael@0: michael@0: yield docLoadPromise; michael@0: michael@0: function waitForNextTick() { michael@0: let deferred = Promise.defer(); michael@0: executeSoon(function () { michael@0: deferred.resolve(); michael@0: }); michael@0: return deferred.promise; michael@0: } michael@0: yield waitForNextTick(); michael@0: michael@0: data = yield m.getValues(); michael@0: ok(data.days.hasDay(now), "We have a search measurement for today."); michael@0: let day = data.days.getDay(now); michael@0: ok(day.has(field), "Have a search count for the urlbar."); michael@0: let newCount = day.get(field); michael@0: is(newCount, oldCount + 1, "We recorded one new search."); michael@0: michael@0: // We should record the default search engine if Telemetry is enabled. michael@0: let oldTelemetry = Services.prefs.getBoolPref("toolkit.telemetry.enabled"); michael@0: Services.prefs.setBoolPref("toolkit.telemetry.enabled", true); michael@0: michael@0: m = provider.getMeasurement("engines", 1); michael@0: yield provider.collectDailyData(); michael@0: data = yield m.getValues(); michael@0: michael@0: ok(data.days.hasDay(now), "Have engines data when Telemetry is enabled."); michael@0: day = data.days.getDay(now); michael@0: ok(day.has("default"), "We have default engine data."); michael@0: is(day.get("default"), "google", "The default engine is reported properly."); michael@0: michael@0: // Restore. michael@0: Services.prefs.setBoolPref("toolkit.telemetry.enabled", oldTelemetry); michael@0: michael@0: gBrowser.removeTab(tab); michael@0: });