зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1234522 - Fix or remove the tests relying on the data reporting service. r=gfritzsche
This commit is contained in:
Родитель
1c59e301ed
Коммит
f935cbdf7c
|
@ -286,8 +286,6 @@ skip-if = e10s # Bug 1094510 - test hits the network in e10s mode only
|
|||
[browser_contextSearchTabPosition.js]
|
||||
skip-if = os == "mac" || e10s # bug 967013; e10s: bug 1094761 - test hits the network in e10s, causing next test to crash
|
||||
[browser_ctrlTab.js]
|
||||
[browser_datareporting_notification.js]
|
||||
skip-if = !datareporting
|
||||
[browser_datachoices_notification.js]
|
||||
skip-if = !datareporting
|
||||
[browser_devedition.js]
|
||||
|
@ -480,7 +478,6 @@ skip-if = os == "linux" # Bug 1073339 - Investigate autocomplete test unreliabil
|
|||
[browser_urlbarStop.js]
|
||||
[browser_urlbarTrimURLs.js]
|
||||
[browser_urlbar_autoFill_backspaced.js]
|
||||
[browser_urlbar_search_healthreport.js]
|
||||
[browser_urlbar_searchsettings.js]
|
||||
[browser_utilityOverlay.js]
|
||||
[browser_viewSourceInTabOnViewSource.js]
|
||||
|
|
|
@ -1,154 +1,143 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
|
||||
"resource://gre/modules/Promise.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
||||
"resource://gre/modules/Task.jsm");
|
||||
|
||||
const CHROME_BASE = "chrome://mochitests/content/browser/browser/base/content/test/general/";
|
||||
const HTTPS_BASE = "https://example.com/browser/browser/base/content/test/general/";
|
||||
|
||||
const TELEMETRY_LOG_PREF = "toolkit.telemetry.log.level";
|
||||
const telemetryOriginalLogPref = Preferences.get(TELEMETRY_LOG_PREF, null);
|
||||
|
||||
const originalReportUrl = Services.prefs.getCharPref("datareporting.healthreport.about.reportUrl");
|
||||
const originalReportUrlUnified = Services.prefs.getCharPref("datareporting.healthreport.about.reportUrlUnified");
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
// Ensure we don't pollute prefs for next tests.
|
||||
if (telemetryOriginalLogPref) {
|
||||
Preferences.set(TELEMETRY_LOG_PREF, telemetryOriginalLogPref);
|
||||
} else {
|
||||
Preferences.reset(TELEMETRY_LOG_PREF);
|
||||
}
|
||||
|
||||
try {
|
||||
Services.prefs.setCharPref("datareporting.healthreport.about.reportUrl", originalReportUrl);
|
||||
Services.prefs.setCharPref("datareporting.healthreport.about.reportUrlUnified", originalReportUrlUnified);
|
||||
let policy = Cc["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Ci.nsISupports)
|
||||
.wrappedJSObject
|
||||
.policy;
|
||||
policy.recordHealthReportUploadEnabled(true,
|
||||
"Resetting after tests.");
|
||||
} catch (ex) {}
|
||||
});
|
||||
|
||||
function fakeTelemetryNow(...args) {
|
||||
let date = new Date(...args);
|
||||
let scope = {};
|
||||
const modules = [
|
||||
Cu.import("resource://gre/modules/TelemetrySession.jsm", scope),
|
||||
Cu.import("resource://gre/modules/TelemetryEnvironment.jsm", scope),
|
||||
Cu.import("resource://gre/modules/TelemetryController.jsm", scope),
|
||||
];
|
||||
|
||||
for (let m of modules) {
|
||||
m.Policy.now = () => new Date(date);
|
||||
}
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
function setupPingArchive() {
|
||||
let scope = {};
|
||||
Cu.import("resource://gre/modules/TelemetryController.jsm", scope);
|
||||
Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader)
|
||||
.loadSubScript(CHROME_BASE + "healthreport_pingData.js", scope);
|
||||
|
||||
for (let p of scope.TEST_PINGS) {
|
||||
fakeTelemetryNow(p.date);
|
||||
p.id = yield scope.TelemetryController.submitExternalPing(p.type, p.payload);
|
||||
}
|
||||
}
|
||||
|
||||
var gTests = [
|
||||
|
||||
{
|
||||
desc: "Test the remote commands",
|
||||
setup: Task.async(function*()
|
||||
{
|
||||
Preferences.set(TELEMETRY_LOG_PREF, "Trace");
|
||||
yield setupPingArchive();
|
||||
Preferences.set("datareporting.healthreport.about.reportUrl",
|
||||
HTTPS_BASE + "healthreport_testRemoteCommands.html");
|
||||
Preferences.set("datareporting.healthreport.about.reportUrlUnified",
|
||||
HTTPS_BASE + "healthreport_testRemoteCommands.html");
|
||||
}),
|
||||
run: function (iframe)
|
||||
{
|
||||
let deferred = Promise.defer();
|
||||
|
||||
let policy = Cc["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Ci.nsISupports)
|
||||
.wrappedJSObject
|
||||
.policy;
|
||||
|
||||
let results = 0;
|
||||
try {
|
||||
iframe.contentWindow.addEventListener("FirefoxHealthReportTestResponse", function evtHandler(event) {
|
||||
let data = event.detail.data;
|
||||
if (data.type == "testResult") {
|
||||
ok(data.pass, data.info);
|
||||
results++;
|
||||
}
|
||||
else if (data.type == "testsComplete") {
|
||||
is(results, data.count, "Checking number of results received matches the number of tests that should have run");
|
||||
iframe.contentWindow.removeEventListener("FirefoxHealthReportTestResponse", evtHandler, true);
|
||||
deferred.resolve();
|
||||
}
|
||||
}, true);
|
||||
|
||||
} catch(e) {
|
||||
ok(false, "Failed to get all commands");
|
||||
deferred.reject();
|
||||
}
|
||||
return deferred.promise;
|
||||
}
|
||||
},
|
||||
|
||||
]; // gTests
|
||||
|
||||
function test()
|
||||
{
|
||||
waitForExplicitFinish();
|
||||
|
||||
// xxxmpc leaving this here until we resolve bug 854038 and bug 854060
|
||||
requestLongerTimeout(10);
|
||||
|
||||
Task.spawn(function () {
|
||||
for (let test of gTests) {
|
||||
info(test.desc);
|
||||
yield test.setup();
|
||||
|
||||
let iframe = yield promiseNewTabLoadEvent("about:healthreport");
|
||||
|
||||
yield test.run(iframe);
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
}
|
||||
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
||||
function promiseNewTabLoadEvent(aUrl, aEventType="load")
|
||||
{
|
||||
let deferred = Promise.defer();
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab(aUrl);
|
||||
tab.linkedBrowser.addEventListener(aEventType, function load(event) {
|
||||
tab.linkedBrowser.removeEventListener(aEventType, load, true);
|
||||
let iframe = tab.linkedBrowser.contentDocument.getElementById("remote-report");
|
||||
iframe.addEventListener("load", function frameLoad(e) {
|
||||
if (iframe.contentWindow.location.href == "about:blank" ||
|
||||
e.target != iframe) {
|
||||
return;
|
||||
}
|
||||
iframe.removeEventListener("load", frameLoad, false);
|
||||
deferred.resolve(iframe);
|
||||
}, false);
|
||||
}, true);
|
||||
return deferred.promise;
|
||||
}
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
|
||||
"resource://gre/modules/Promise.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
||||
"resource://gre/modules/Task.jsm");
|
||||
|
||||
const CHROME_BASE = "chrome://mochitests/content/browser/browser/base/content/test/general/";
|
||||
const HTTPS_BASE = "https://example.com/browser/browser/base/content/test/general/";
|
||||
|
||||
const TELEMETRY_LOG_PREF = "toolkit.telemetry.log.level";
|
||||
const telemetryOriginalLogPref = Preferences.get(TELEMETRY_LOG_PREF, null);
|
||||
|
||||
const originalReportUrl = Services.prefs.getCharPref("datareporting.healthreport.about.reportUrl");
|
||||
const originalReportUrlUnified = Services.prefs.getCharPref("datareporting.healthreport.about.reportUrlUnified");
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
// Ensure we don't pollute prefs for next tests.
|
||||
if (telemetryOriginalLogPref) {
|
||||
Preferences.set(TELEMETRY_LOG_PREF, telemetryOriginalLogPref);
|
||||
} else {
|
||||
Preferences.reset(TELEMETRY_LOG_PREF);
|
||||
}
|
||||
|
||||
try {
|
||||
Services.prefs.setCharPref("datareporting.healthreport.about.reportUrl", originalReportUrl);
|
||||
Services.prefs.setCharPref("datareporting.healthreport.about.reportUrlUnified", originalReportUrlUnified);
|
||||
Services.prefs.setBoolPref("datareporting.healthreport.uploadEnabled", true);
|
||||
} catch (ex) {}
|
||||
});
|
||||
|
||||
function fakeTelemetryNow(...args) {
|
||||
let date = new Date(...args);
|
||||
let scope = {};
|
||||
const modules = [
|
||||
Cu.import("resource://gre/modules/TelemetrySession.jsm", scope),
|
||||
Cu.import("resource://gre/modules/TelemetryEnvironment.jsm", scope),
|
||||
Cu.import("resource://gre/modules/TelemetryController.jsm", scope),
|
||||
];
|
||||
|
||||
for (let m of modules) {
|
||||
m.Policy.now = () => new Date(date);
|
||||
}
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
function setupPingArchive() {
|
||||
let scope = {};
|
||||
Cu.import("resource://gre/modules/TelemetryController.jsm", scope);
|
||||
Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader)
|
||||
.loadSubScript(CHROME_BASE + "healthreport_pingData.js", scope);
|
||||
|
||||
for (let p of scope.TEST_PINGS) {
|
||||
fakeTelemetryNow(p.date);
|
||||
p.id = yield scope.TelemetryController.submitExternalPing(p.type, p.payload);
|
||||
}
|
||||
}
|
||||
|
||||
var gTests = [
|
||||
|
||||
{
|
||||
desc: "Test the remote commands",
|
||||
setup: Task.async(function*()
|
||||
{
|
||||
Preferences.set(TELEMETRY_LOG_PREF, "Trace");
|
||||
yield setupPingArchive();
|
||||
Preferences.set("datareporting.healthreport.about.reportUrl",
|
||||
HTTPS_BASE + "healthreport_testRemoteCommands.html");
|
||||
Preferences.set("datareporting.healthreport.about.reportUrlUnified",
|
||||
HTTPS_BASE + "healthreport_testRemoteCommands.html");
|
||||
}),
|
||||
run: function (iframe)
|
||||
{
|
||||
let deferred = Promise.defer();
|
||||
let results = 0;
|
||||
try {
|
||||
iframe.contentWindow.addEventListener("FirefoxHealthReportTestResponse", function evtHandler(event) {
|
||||
let data = event.detail.data;
|
||||
if (data.type == "testResult") {
|
||||
ok(data.pass, data.info);
|
||||
results++;
|
||||
}
|
||||
else if (data.type == "testsComplete") {
|
||||
is(results, data.count, "Checking number of results received matches the number of tests that should have run");
|
||||
iframe.contentWindow.removeEventListener("FirefoxHealthReportTestResponse", evtHandler, true);
|
||||
deferred.resolve();
|
||||
}
|
||||
}, true);
|
||||
|
||||
} catch(e) {
|
||||
ok(false, "Failed to get all commands");
|
||||
deferred.reject();
|
||||
}
|
||||
return deferred.promise;
|
||||
}
|
||||
},
|
||||
|
||||
]; // gTests
|
||||
|
||||
function test()
|
||||
{
|
||||
waitForExplicitFinish();
|
||||
|
||||
// xxxmpc leaving this here until we resolve bug 854038 and bug 854060
|
||||
requestLongerTimeout(10);
|
||||
|
||||
Task.spawn(function () {
|
||||
for (let test of gTests) {
|
||||
info(test.desc);
|
||||
yield test.setup();
|
||||
|
||||
let iframe = yield promiseNewTabLoadEvent("about:healthreport");
|
||||
|
||||
yield test.run(iframe);
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
}
|
||||
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
||||
function promiseNewTabLoadEvent(aUrl, aEventType="load")
|
||||
{
|
||||
let deferred = Promise.defer();
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab(aUrl);
|
||||
tab.linkedBrowser.addEventListener(aEventType, function load(event) {
|
||||
tab.linkedBrowser.removeEventListener(aEventType, load, true);
|
||||
let iframe = tab.linkedBrowser.contentDocument.getElementById("remote-report");
|
||||
iframe.addEventListener("load", function frameLoad(e) {
|
||||
if (iframe.contentWindow.location.href == "about:blank" ||
|
||||
e.target != iframe) {
|
||||
return;
|
||||
}
|
||||
iframe.removeEventListener("load", frameLoad, false);
|
||||
deferred.resolve(iframe);
|
||||
}, false);
|
||||
}, true);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
|
|
@ -78,24 +78,11 @@ var gTests = [
|
|||
}
|
||||
},
|
||||
|
||||
// Disabled on Linux for intermittent issues with FHR, see Bug 945667.
|
||||
{
|
||||
desc: "Check that performing a search fires a search event and records to " +
|
||||
"Firefox Health Report.",
|
||||
"Telemetry.",
|
||||
setup: function () { },
|
||||
run: function* () {
|
||||
// Skip this test on Linux.
|
||||
if (navigator.platform.indexOf("Linux") == 0) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
try {
|
||||
let cm = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
|
||||
cm.getCategoryEntry("healthreport-js-provider-default", "SearchesProvider");
|
||||
} catch (ex) {
|
||||
// Health Report disabled, or no SearchesProvider.
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
let engine = yield promiseNewEngine("searchSuggestionEngine.xml");
|
||||
// Make this actually work in healthreport by giving it an ID:
|
||||
|
@ -113,23 +100,32 @@ var gTests = [
|
|||
is(engine.name, engineName, "Engine name in DOM should match engine we just added");
|
||||
|
||||
// Get the current number of recorded searches.
|
||||
let searchStr = "a search";
|
||||
getNumberOfSearchesInFHR(engineName, "abouthome").then(num => {
|
||||
numSearchesBefore = num;
|
||||
let histogramKey = engine.identifier + ".abouthome";
|
||||
try {
|
||||
let hs = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS").snapshot();
|
||||
if (histogramKey in hs) {
|
||||
numSearchesBefore = hs[histogramKey].sum;
|
||||
}
|
||||
} catch (ex) {
|
||||
// No searches performed yet, not a problem, |numSearchesBefore| is 0.
|
||||
}
|
||||
|
||||
info("Perform a search.");
|
||||
doc.getElementById("searchText").value = searchStr;
|
||||
doc.getElementById("searchSubmit").click();
|
||||
});
|
||||
// Perform a search to increase the SEARCH_COUNT histogram.
|
||||
let searchStr = "a search";
|
||||
info("Perform a search.");
|
||||
doc.getElementById("searchText").value = searchStr;
|
||||
doc.getElementById("searchSubmit").click();
|
||||
|
||||
let expectedURL = Services.search.currentEngine.
|
||||
getSubmission(searchStr, null, "homepage").
|
||||
uri.spec;
|
||||
let loadPromise = waitForDocLoadAndStopIt(expectedURL).then(() => {
|
||||
getNumberOfSearchesInFHR(engineName, "abouthome").then(num => {
|
||||
is(num, numSearchesBefore + 1, "One more search recorded.");
|
||||
searchEventDeferred.resolve();
|
||||
});
|
||||
// Make sure the SEARCH_COUNTS histogram has the right key and count.
|
||||
let hs = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS").snapshot();
|
||||
Assert.ok(histogramKey in hs, "histogram with key should be recorded");
|
||||
Assert.equal(hs[histogramKey].sum, numSearchesBefore + 1,
|
||||
"histogram sum should be incremented");
|
||||
searchEventDeferred.resolve();
|
||||
});
|
||||
|
||||
try {
|
||||
|
|
|
@ -2,15 +2,34 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
add_task(function* test() {
|
||||
|
||||
// Will need to be changed if Google isn't the default search engine.
|
||||
// Note: geoSpecificDefaults are disabled for mochitests, so this is the
|
||||
// non-US en-US default.
|
||||
let histogramKey = "google.contextmenu";
|
||||
let numSearchesBefore = 0;
|
||||
try {
|
||||
let hs = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS").snapshot();
|
||||
if (histogramKey in hs) {
|
||||
numSearchesBefore = hs[histogramKey].sum;
|
||||
}
|
||||
} catch (ex) {
|
||||
// No searches performed yet, not a problem, |numSearchesBefore| is 0.
|
||||
}
|
||||
|
||||
let tabs = [];
|
||||
let tabsLoadedDeferred = Promise.defer();
|
||||
|
||||
function tabAdded(event) {
|
||||
let tab = event.target;
|
||||
tabs.push(tab);
|
||||
}
|
||||
|
||||
let tabs = [];
|
||||
// We wait for the blank tab and the two context searches tabs to open.
|
||||
if (tabs.length == 3) {
|
||||
tabsLoadedDeferred.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
let container = gBrowser.tabContainer;
|
||||
container.addEventListener("TabOpen", tabAdded, false);
|
||||
|
@ -19,6 +38,9 @@ function test() {
|
|||
BrowserSearch.loadSearchFromContext("mozilla");
|
||||
BrowserSearch.loadSearchFromContext("firefox");
|
||||
|
||||
// Wait for all the tabs to open.
|
||||
yield tabsLoadedDeferred.promise;
|
||||
|
||||
is(tabs[0], gBrowser.tabs[3], "blank tab has been pushed to the end");
|
||||
is(tabs[1], gBrowser.tabs[1], "first search tab opens next to the current tab");
|
||||
is(tabs[2], gBrowser.tabs[2], "second search tab opens next to the first search tab");
|
||||
|
@ -26,45 +48,9 @@ function test() {
|
|||
container.removeEventListener("TabOpen", tabAdded, false);
|
||||
tabs.forEach(gBrowser.removeTab, gBrowser);
|
||||
|
||||
try {
|
||||
let cm = Components.classes["@mozilla.org/categorymanager;1"]
|
||||
.getService(Components.interfaces.nsICategoryManager);
|
||||
cm.getCategoryEntry("healthreport-js-provider-default", "SearchesProvider");
|
||||
} catch (ex) {
|
||||
// Health Report disabled, or no SearchesProvider.
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
let reporter = Components.classes["@mozilla.org/datareporting/service;1"]
|
||||
.getService()
|
||||
.wrappedJSObject
|
||||
.healthReporter;
|
||||
|
||||
// reporter should always be available in automation.
|
||||
ok(reporter, "Health Reporter available.");
|
||||
reporter.onInit().then(function onInit() {
|
||||
let provider = reporter.getProvider("org.mozilla.searches");
|
||||
ok(provider, "Searches provider is available.");
|
||||
|
||||
let m = provider.getMeasurement("counts", 3);
|
||||
m.getValues().then(function onValues(data) {
|
||||
let now = new Date();
|
||||
ok(data.days.hasDay(now), "Have data for today.");
|
||||
let day = data.days.getDay(now);
|
||||
|
||||
// Will need to be changed if Google isn't the default search engine.
|
||||
// Note: geoSpecificDefaults are disabled for mochitests, so this is the
|
||||
// non-US en-US default.
|
||||
let defaultProviderID = "google";
|
||||
let field = defaultProviderID + ".contextmenu";
|
||||
ok(day.has(field), "Have search recorded for context menu.");
|
||||
|
||||
// If any other mochitests perform a context menu search, this will fail.
|
||||
// The solution will be to look up count at test start and ensure it is
|
||||
// incremented by two.
|
||||
is(day.get(field), 2, "2 searches recorded in FHR.");
|
||||
finish();
|
||||
});
|
||||
});
|
||||
}
|
||||
// Make sure that the context searches are correctly recorded.
|
||||
let hs = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS").snapshot();
|
||||
Assert.ok(histogramKey in hs, "The histogram must contain the correct key");
|
||||
Assert.equal(hs[histogramKey].sum, numSearchesBefore + 2,
|
||||
"The histogram must contain the correct search count");
|
||||
});
|
||||
|
|
|
@ -10,11 +10,6 @@ var Preferences = Cu.import("resource://gre/modules/Preferences.jsm", {}).Prefer
|
|||
var TelemetryReportingPolicy =
|
||||
Cu.import("resource://gre/modules/TelemetryReportingPolicy.jsm", {}).TelemetryReportingPolicy;
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "gDatareportingService",
|
||||
() => Cc["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Ci.nsISupports)
|
||||
.wrappedJSObject);
|
||||
|
||||
const PREF_BRANCH = "datareporting.policy.";
|
||||
const PREF_DRS_ENABLED = "datareporting.healthreport.service.enabled";
|
||||
const PREF_BYPASS_NOTIFICATION = PREF_BRANCH + "dataSubmissionPolicyBypassNotification";
|
||||
|
@ -113,9 +108,6 @@ add_task(function* setup(){
|
|||
Preferences.set(PREF_BYPASS_NOTIFICATION, bypassNotification);
|
||||
Preferences.set(PREF_CURRENT_POLICY_VERSION, currentPolicyVersion);
|
||||
|
||||
// Start polling again.
|
||||
gDatareportingService.policy.startPolling();
|
||||
|
||||
return closeAllNotifications();
|
||||
});
|
||||
|
||||
|
@ -125,9 +117,6 @@ add_task(function* setup(){
|
|||
Preferences.set(PREF_BYPASS_NOTIFICATION, false);
|
||||
// Set the current policy version.
|
||||
Preferences.set(PREF_CURRENT_POLICY_VERSION, TEST_POLICY_VERSION);
|
||||
|
||||
// Stop the polling to make sure no policy gets displayed by FHR.
|
||||
gDatareportingService.policy.stopPolling();
|
||||
});
|
||||
|
||||
function clearAcceptedPolicy() {
|
||||
|
|
|
@ -1,213 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
var originalPolicy = null;
|
||||
|
||||
/**
|
||||
* Display a datareporting notification to the user.
|
||||
*
|
||||
* @param {String} name
|
||||
*/
|
||||
function sendNotifyRequest(name) {
|
||||
let ns = {};
|
||||
Cu.import("resource://gre/modules/services/datareporting/policy.jsm", ns);
|
||||
Cu.import("resource://gre/modules/Preferences.jsm", ns);
|
||||
|
||||
let service = Cc["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Ci.nsISupports)
|
||||
.wrappedJSObject;
|
||||
ok(service.healthReporter, "Health Reporter instance is available.");
|
||||
|
||||
Cu.import("resource://gre/modules/Promise.jsm", ns);
|
||||
let deferred = ns.Promise.defer();
|
||||
|
||||
if (!originalPolicy) {
|
||||
originalPolicy = service.policy;
|
||||
}
|
||||
|
||||
let policyPrefs = new ns.Preferences("testing." + name + ".");
|
||||
ok(service._prefs, "Health Reporter prefs are available.");
|
||||
let hrPrefs = service._prefs;
|
||||
|
||||
let policy = new ns.DataReportingPolicy(policyPrefs, hrPrefs, service);
|
||||
policy.dataSubmissionPolicyBypassNotification = false;
|
||||
service.policy = policy;
|
||||
policy.firstRunDate = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
||||
|
||||
service.healthReporter.onInit().then(function onSuccess () {
|
||||
is(policy.ensureUserNotified(), false, "User not notified about data policy on init.");
|
||||
ok(policy._userNotifyPromise, "_userNotifyPromise defined.");
|
||||
policy._userNotifyPromise.then(
|
||||
deferred.resolve.bind(deferred),
|
||||
deferred.reject.bind(deferred)
|
||||
);
|
||||
}.bind(this), deferred.reject.bind(deferred));
|
||||
|
||||
return [policy, deferred.promise];
|
||||
}
|
||||
|
||||
var dumpAppender, rootLogger;
|
||||
|
||||
function test() {
|
||||
registerCleanupFunction(cleanup);
|
||||
waitForExplicitFinish();
|
||||
|
||||
let ns = {};
|
||||
Components.utils.import("resource://gre/modules/Log.jsm", ns);
|
||||
rootLogger = ns.Log.repository.rootLogger;
|
||||
dumpAppender = new ns.Log.DumpAppender();
|
||||
dumpAppender.level = ns.Log.Level.All;
|
||||
rootLogger.addAppender(dumpAppender);
|
||||
|
||||
closeAllNotifications().then(function onSuccess () {
|
||||
let notification = document.getElementById("global-notificationbox");
|
||||
|
||||
notification.addEventListener("AlertActive", function active() {
|
||||
notification.removeEventListener("AlertActive", active, true);
|
||||
is(notification.allNotifications.length, 1, "Notification Displayed.");
|
||||
|
||||
executeSoon(function afterNotification() {
|
||||
waitForNotificationClose(notification.currentNotification, function onClose() {
|
||||
is(notification.allNotifications.length, 0, "No notifications remain.");
|
||||
is(policy.dataSubmissionPolicyAcceptedVersion, 1, "Version pref set.");
|
||||
ok(policy.dataSubmissionPolicyNotifiedDate.getTime() > -1, "Date pref set.");
|
||||
test_multiple_windows();
|
||||
});
|
||||
notification.currentNotification.close();
|
||||
});
|
||||
}, true);
|
||||
|
||||
let [policy, promise] = sendNotifyRequest("single_window_notified");
|
||||
|
||||
is(policy.dataSubmissionPolicyAcceptedVersion, 0, "No version should be set on init.");
|
||||
is(policy.dataSubmissionPolicyNotifiedDate.getTime(), 0, "No date should be set on init.");
|
||||
is(policy.userNotifiedOfCurrentPolicy, false, "User not notified about datareporting policy.");
|
||||
|
||||
promise.then(function () {
|
||||
is(policy.dataSubmissionPolicyAcceptedVersion, 1, "Policy version set.");
|
||||
is(policy.dataSubmissionPolicyNotifiedDate.getTime() > 0, true, "Policy date set.");
|
||||
is(policy.userNotifiedOfCurrentPolicy, true, "User notified about datareporting policy.");
|
||||
}.bind(this), function (err) {
|
||||
throw err;
|
||||
});
|
||||
|
||||
}.bind(this), function onError (err) {
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
|
||||
function test_multiple_windows() {
|
||||
// Ensure we see the notification on all windows and that action on one window
|
||||
// results in dismiss on every window.
|
||||
let window2 = OpenBrowserWindow();
|
||||
whenDelayedStartupFinished(window2, function onWindow() {
|
||||
let notification1 = document.getElementById("global-notificationbox");
|
||||
let notification2 = window2.document.getElementById("global-notificationbox");
|
||||
ok(notification2, "2nd window has a global notification box.");
|
||||
|
||||
let [policy, promise] = sendNotifyRequest("multiple_window_behavior");
|
||||
let displayCount = 0;
|
||||
let prefWindowOpened = false;
|
||||
let mutationObserversRemoved = false;
|
||||
|
||||
function onAlertDisplayed() {
|
||||
displayCount++;
|
||||
|
||||
if (displayCount != 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
ok(true, "Data reporting info bar displayed on all open windows.");
|
||||
|
||||
// We register two independent observers and we need both to clean up
|
||||
// properly. This handles gating for test completion.
|
||||
function maybeFinish() {
|
||||
if (!prefWindowOpened) {
|
||||
dump("Not finishing test yet because pref pane hasn't yet appeared.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mutationObserversRemoved) {
|
||||
dump("Not finishing test yet because mutation observers haven't been removed yet.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
window2.close();
|
||||
|
||||
dump("Finishing multiple window test.\n");
|
||||
rootLogger.removeAppender(dumpAppender);
|
||||
dumpAppender = null;
|
||||
rootLogger = null;
|
||||
finish();
|
||||
}
|
||||
let closeCount = 0;
|
||||
|
||||
function onAlertClose() {
|
||||
closeCount++;
|
||||
|
||||
if (closeCount != 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
ok(true, "Closing info bar on one window closed them on all.");
|
||||
is(policy.userNotifiedOfCurrentPolicy, true, "Data submission policy accepted.");
|
||||
|
||||
is(notification1.allNotifications.length, 0, "No notifications remain on main window.");
|
||||
is(notification2.allNotifications.length, 0, "No notifications remain on 2nd window.");
|
||||
|
||||
mutationObserversRemoved = true;
|
||||
maybeFinish();
|
||||
}
|
||||
|
||||
waitForNotificationClose(notification1.currentNotification, onAlertClose);
|
||||
waitForNotificationClose(notification2.currentNotification, onAlertClose);
|
||||
|
||||
// While we're here, we dual purpose this test to check that pressing the
|
||||
// button does the right thing.
|
||||
let buttons = notification2.currentNotification.getElementsByTagName("button");
|
||||
is(buttons.length, 1, "There is 1 button in the data reporting notification.");
|
||||
let button = buttons[0];
|
||||
|
||||
// Add an observer to ensure the "advanced" pane opened (but don't bother
|
||||
// closing it - we close the entire window when done.)
|
||||
Services.obs.addObserver(function observer(prefWin, topic, data) {
|
||||
Services.obs.removeObserver(observer, "advanced-pane-loaded");
|
||||
|
||||
ok(true, "Advanced preferences opened on info bar button press.");
|
||||
executeSoon(function soon() {
|
||||
prefWindowOpened = true;
|
||||
maybeFinish();
|
||||
});
|
||||
}, "advanced-pane-loaded", false);
|
||||
|
||||
button.click();
|
||||
}
|
||||
|
||||
notification1.addEventListener("AlertActive", function active1() {
|
||||
notification1.removeEventListener("AlertActive", active1, true);
|
||||
executeSoon(onAlertDisplayed);
|
||||
}, true);
|
||||
|
||||
notification2.addEventListener("AlertActive", function active2() {
|
||||
notification2.removeEventListener("AlertActive", active2, true);
|
||||
executeSoon(onAlertDisplayed);
|
||||
}, true);
|
||||
|
||||
promise.then(null, function onError(err) {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function cleanup () {
|
||||
// In case some test fails.
|
||||
if (originalPolicy) {
|
||||
let service = Cc["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Ci.nsISupports)
|
||||
.wrappedJSObject;
|
||||
service.policy = originalPolicy;
|
||||
}
|
||||
|
||||
return closeAllNotifications();
|
||||
}
|
|
@ -103,7 +103,6 @@ function* compareCounts(clickCallback) {
|
|||
// FHR -- first make sure the engine has an identifier so that FHR is happy.
|
||||
Object.defineProperty(engine.wrappedJSObject, "identifier",
|
||||
{ value: engineID });
|
||||
let fhrCount = yield getNumberOfSearchesInFHR(engine.name, "urlbar");
|
||||
|
||||
gURLBar.focus();
|
||||
yield clickCallback();
|
||||
|
@ -126,10 +125,6 @@ function* compareCounts(clickCallback) {
|
|||
Assert.ok(histogramKey in snapshot, "histogram with key should be recorded");
|
||||
Assert.equal(snapshot[histogramKey].sum, histogramCount + 1,
|
||||
"histogram sum should be incremented");
|
||||
|
||||
// FHR
|
||||
let newFHRCount = yield getNumberOfSearchesInFHR(engine.name, "urlbar");
|
||||
Assert.equal(newFHRCount, fhrCount + 1, "should be recorded in FHR");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,85 +0,0 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
add_task(function* test_healthreport_search_recording() {
|
||||
try {
|
||||
let cm = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
|
||||
cm.getCategoryEntry("healthreport-js-provider-default", "SearchesProvider");
|
||||
} catch (ex) {
|
||||
// Health Report disabled, or no SearchesProvider.
|
||||
ok(true, "Firefox Health Report is not enabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
let reporter = Cc["@mozilla.org/datareporting/service;1"]
|
||||
.getService()
|
||||
.wrappedJSObject
|
||||
.healthReporter;
|
||||
ok(reporter, "Health Reporter available.");
|
||||
yield reporter.onInit();
|
||||
let provider = reporter.getProvider("org.mozilla.searches");
|
||||
ok(provider, "Searches provider is available.");
|
||||
let m = provider.getMeasurement("counts", 3);
|
||||
|
||||
let data = yield m.getValues();
|
||||
let now = new Date();
|
||||
let oldCount = 0;
|
||||
|
||||
// This will to be need changed if default search engine is not Google.
|
||||
// Note: geoSpecificDefaults are disabled for mochitests, so this is the
|
||||
// non-US en-US default.
|
||||
let defaultEngineID = "google";
|
||||
|
||||
let field = defaultEngineID + ".urlbar";
|
||||
|
||||
if (data.days.hasDay(now)) {
|
||||
let day = data.days.getDay(now);
|
||||
if (day.has(field)) {
|
||||
oldCount = day.get(field);
|
||||
}
|
||||
}
|
||||
|
||||
let tab = gBrowser.addTab("about:blank");
|
||||
yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||
gBrowser.selectedTab = tab;
|
||||
|
||||
let searchStr = "firefox health report";
|
||||
let expectedURL = Services.search.currentEngine.
|
||||
getSubmission(searchStr, "", "keyword").uri.spec;
|
||||
|
||||
// Expect the search URL to load but stop it as soon as it starts.
|
||||
let docLoadPromise = waitForDocLoadAndStopIt(expectedURL);
|
||||
|
||||
// Trigger the search.
|
||||
gURLBar.value = searchStr;
|
||||
gURLBar.handleCommand();
|
||||
|
||||
yield docLoadPromise;
|
||||
|
||||
data = yield m.getValues();
|
||||
ok(data.days.hasDay(now), "We have a search measurement for today.");
|
||||
let day = data.days.getDay(now);
|
||||
ok(day.has(field), "Have a search count for the urlbar.");
|
||||
let newCount = day.get(field);
|
||||
is(newCount, oldCount + 1, "We recorded one new search.");
|
||||
|
||||
// We should record the default search engine if Telemetry is enabled.
|
||||
let oldTelemetry = Services.prefs.getBoolPref("toolkit.telemetry.enabled");
|
||||
Services.prefs.setBoolPref("toolkit.telemetry.enabled", true);
|
||||
|
||||
m = provider.getMeasurement("engines", 2);
|
||||
yield provider.collectDailyData();
|
||||
data = yield m.getValues();
|
||||
|
||||
ok(data.days.hasDay(now), "Have engines data when Telemetry is enabled.");
|
||||
day = data.days.getDay(now);
|
||||
ok(day.has("default"), "We have default engine data.");
|
||||
is(day.get("default"), defaultEngineID, "The default engine is reported properly.");
|
||||
|
||||
// Restore.
|
||||
Services.prefs.setBoolPref("toolkit.telemetry.enabled", oldTelemetry);
|
||||
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
|
@ -1202,61 +1202,3 @@ function promiseCrashReport(expectedExtra) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the number of searches recorded in FHR for the current day.
|
||||
*
|
||||
* @param aEngineName
|
||||
* name of the setup search engine.
|
||||
* @param aSource
|
||||
* The FHR "source" name for the search, like "abouthome" or "urlbar".
|
||||
*
|
||||
* @return {Promise} Returns a promise resolving to the number of searches.
|
||||
*/
|
||||
function getNumberOfSearchesInFHR(aEngineName, aSource) {
|
||||
let reporter = Components.classes["@mozilla.org/datareporting/service;1"]
|
||||
.getService()
|
||||
.wrappedJSObject
|
||||
.healthReporter;
|
||||
ok(reporter, "Health Reporter instance available.");
|
||||
|
||||
return reporter.onInit().then(function onInit() {
|
||||
let provider = reporter.getProvider("org.mozilla.searches");
|
||||
ok(provider, "Searches provider is available.");
|
||||
|
||||
let m = provider.getMeasurement("counts", 3);
|
||||
return m.getValues().then(data => {
|
||||
let now = new Date();
|
||||
let yday = new Date(now);
|
||||
yday.setDate(yday.getDate() - 1);
|
||||
|
||||
// Add the number of searches recorded yesterday to the number of searches
|
||||
// recorded today. This makes the test not fail intermittently when it is
|
||||
// run at midnight and we accidentally compare the number of searches from
|
||||
// different days. Tests are always run with an empty profile so there
|
||||
// are no searches from yesterday, normally. Should the test happen to run
|
||||
// past midnight we make sure to count them in as well.
|
||||
return getNumberOfSearchesInFHRByDate(aEngineName, aSource, data, now) +
|
||||
getNumberOfSearchesInFHRByDate(aEngineName, aSource, data, yday);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for getNumberOfSearchesInFHR. You probably don't want to call this
|
||||
* directly.
|
||||
*/
|
||||
function getNumberOfSearchesInFHRByDate(aEngineName, aSource, aData, aDate) {
|
||||
if (aData.days.hasDay(aDate)) {
|
||||
let id = Services.search.getEngineByName(aEngineName).identifier;
|
||||
|
||||
let day = aData.days.getDay(aDate);
|
||||
let field = id + "." + aSource;
|
||||
|
||||
if (day.has(field)) {
|
||||
return day.get(field) || 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0; // No records found.
|
||||
}
|
||||
|
|
|
@ -7,35 +7,14 @@
|
|||
<script type="application/javascript;version=1.7">
|
||||
|
||||
function init() {
|
||||
window.addEventListener("message", function process(e) {
|
||||
// The init function of abouthealth.js schedules an initial payload event,
|
||||
// which will be sent after the payload data has been collected. This extra
|
||||
// event can cause unexpected successes/failures in this test, so we wait
|
||||
// for the extra event to arrive here before progressing with the actual
|
||||
// test.
|
||||
if (e.data.type == "payload") {
|
||||
window.removeEventListener("message", process, false);
|
||||
|
||||
window.addEventListener("message", doTest, false);
|
||||
doTest();
|
||||
}
|
||||
}, false);
|
||||
window.addEventListener("message", doTest, false);
|
||||
doTest();
|
||||
}
|
||||
|
||||
function checkSubmissionValue(payload, expectedValue) {
|
||||
return payload.enabled == expectedValue;
|
||||
}
|
||||
|
||||
function validatePayload(payload) {
|
||||
payload = JSON.parse(payload);
|
||||
|
||||
// xxxmpc - this is some pretty low-bar validation, but we have plenty of tests of that API elsewhere
|
||||
if (!payload.thisPingDate)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function isArray(arg) {
|
||||
return Object.prototype.toString.call(arg) === '[object Array]';
|
||||
}
|
||||
|
@ -141,11 +120,11 @@ var tests = [
|
|||
},
|
||||
},
|
||||
{
|
||||
info: "Verifying we can get a payload while submission is disabled",
|
||||
event: "RequestCurrentPayload",
|
||||
payloadType: "payload",
|
||||
info: "Verifying that we can get the current ping data while submission is disabled",
|
||||
event: "RequestCurrentPingData",
|
||||
payloadType: "telemetry-current-ping-data",
|
||||
validateResponse: function(payload) {
|
||||
return validatePayload(payload);
|
||||
return validateCurrentTelemetryPingData(payload);
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -164,14 +143,6 @@ var tests = [
|
|||
return checkSubmissionValue(payload, true);
|
||||
},
|
||||
},
|
||||
{
|
||||
info: "Verifying we can get a payload after re-enabling",
|
||||
event: "RequestCurrentPayload",
|
||||
payloadType: "payload",
|
||||
validateResponse: function(payload) {
|
||||
return validatePayload(payload);
|
||||
},
|
||||
},
|
||||
{
|
||||
info: "Verifying that we can get the current Telemetry environment data",
|
||||
event: "RequestCurrentEnvironment",
|
||||
|
|
|
@ -18,7 +18,7 @@ skip-if = os != "win" # This test tests the windows-specific app selection dialo
|
|||
[browser_connection_bug388287.js]
|
||||
[browser_cookies_exceptions.js]
|
||||
[browser_healthreport.js]
|
||||
skip-if = true || !healthreport || (os == 'linux' && debug) # Bug 1185403 for the "true"
|
||||
skip-if = true || !healthreport # Bug 1185403 for the "true"
|
||||
[browser_homepages_filter_aboutpreferences.js]
|
||||
[browser_notifications_do_not_disturb.js]
|
||||
[browser_permissions_urlFieldHidden.js]
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const FHR_UPLOAD_ENABLED = "datareporting.healthreport.uploadEnabled";
|
||||
|
||||
function runPaneTest(fn) {
|
||||
open_preferences((win) => {
|
||||
let doc = win.document;
|
||||
|
@ -10,14 +12,7 @@ function runPaneTest(fn) {
|
|||
let advancedPrefs = doc.getElementById("advancedPrefs");
|
||||
let tab = doc.getElementById("dataChoicesTab");
|
||||
advancedPrefs.selectedTab = tab;
|
||||
|
||||
let policy = Components.classes["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Components.interfaces.nsISupports)
|
||||
.wrappedJSObject
|
||||
.policy;
|
||||
|
||||
ok(policy, "Policy object is defined.");
|
||||
fn(win, doc, policy);
|
||||
fn(win, doc);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -28,8 +23,9 @@ function test() {
|
|||
runPaneTest(testBasic);
|
||||
}
|
||||
|
||||
function testBasic(win, doc, policy) {
|
||||
is(policy.healthReportUploadEnabled, true, "Health Report upload enabled on app first run.");
|
||||
function testBasic(win, doc) {
|
||||
is(Services.prefs.getBoolPref(FHR_UPLOAD_ENABLED), true,
|
||||
"Health Report upload enabled on app first run.");
|
||||
|
||||
let checkbox = doc.getElementById("submitHealthReportBox");
|
||||
ok(checkbox);
|
||||
|
@ -37,28 +33,30 @@ function testBasic(win, doc, policy) {
|
|||
|
||||
checkbox.checked = false;
|
||||
checkbox.doCommand();
|
||||
is(policy.healthReportUploadEnabled, false, "Unchecking checkbox opts out of FHR upload.");
|
||||
is(Services.prefs.getBoolPref(FHR_UPLOAD_ENABLED), false,
|
||||
"Unchecking checkbox opts out of FHR upload.");
|
||||
|
||||
checkbox.checked = true;
|
||||
checkbox.doCommand();
|
||||
is(policy.healthReportUploadEnabled, true, "Checking checkbox allows FHR upload.");
|
||||
is(Services.prefs.getBoolPref(FHR_UPLOAD_ENABLED), true,
|
||||
"Checking checkbox allows FHR upload.");
|
||||
|
||||
win.close();
|
||||
Services.prefs.lockPref("datareporting.healthreport.uploadEnabled");
|
||||
Services.prefs.lockPref(FHR_UPLOAD_ENABLED);
|
||||
runPaneTest(testUploadDisabled);
|
||||
}
|
||||
|
||||
function testUploadDisabled(win, doc, policy) {
|
||||
ok(policy.healthReportUploadLocked, "Upload enabled flag is locked.");
|
||||
function testUploadDisabled(win, doc) {
|
||||
ok(Services.prefs.prefIsLocked(FHR_UPLOAD_ENABLED), "Upload enabled flag is locked.");
|
||||
let checkbox = doc.getElementById("submitHealthReportBox");
|
||||
is(checkbox.getAttribute("disabled"), "true", "Checkbox is disabled if upload flag is locked.");
|
||||
policy._healthReportPrefs.unlock("uploadEnabled");
|
||||
Services.prefs.unlockPref(FHR_UPLOAD_ENABLED);
|
||||
|
||||
win.close();
|
||||
finish();
|
||||
}
|
||||
|
||||
function resetPreferences() {
|
||||
Services.prefs.clearUserPref("datareporting.healthreport.uploadEnabled");
|
||||
Services.prefs.clearUserPref(FHR_UPLOAD_ENABLED);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,75 +3,50 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var Preferences = Cu.import("resource://gre/modules/Preferences.jsm", {}).Preferences;
|
||||
|
||||
function test() {
|
||||
requestLongerTimeout(2);
|
||||
waitForExplicitFinish();
|
||||
resetPreferences();
|
||||
|
||||
try {
|
||||
let cm = Components.classes["@mozilla.org/categorymanager;1"]
|
||||
.getService(Components.interfaces.nsICategoryManager);
|
||||
cm.getCategoryEntry("healthreport-js-provider-default", "SearchesProvider");
|
||||
} catch (ex) {
|
||||
// Health Report disabled, or no SearchesProvider.
|
||||
// We need a test or else we'll be marked as failure.
|
||||
ok(true, "Firefox Health Report is not enabled.");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
function testTelemetry() {
|
||||
// Find the right bucket for the "Foo" engine.
|
||||
let engine = Services.search.getEngineByName("Foo");
|
||||
let histogramKey = (engine.identifier || "other-Foo") + ".searchbar";
|
||||
let numSearchesBefore = 0;
|
||||
try {
|
||||
let hs = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS").snapshot();
|
||||
if (histogramKey in hs) {
|
||||
numSearchesBefore = hs[histogramKey].sum;
|
||||
}
|
||||
} catch (ex) {
|
||||
// No searches performed yet, not a problem, |numSearchesBefore| is 0.
|
||||
}
|
||||
|
||||
function testFHR() {
|
||||
let reporter = Components.classes["@mozilla.org/datareporting/service;1"]
|
||||
.getService()
|
||||
.wrappedJSObject
|
||||
.healthReporter;
|
||||
ok(reporter, "Health Reporter available.");
|
||||
reporter.onInit().then(function onInit() {
|
||||
let provider = reporter.getProvider("org.mozilla.searches");
|
||||
let m = provider.getMeasurement("counts", 3);
|
||||
// Now perform a search and ensure the count is incremented.
|
||||
let tab = gBrowser.addTab();
|
||||
gBrowser.selectedTab = tab;
|
||||
let searchBar = BrowserSearch.searchBar;
|
||||
|
||||
m.getValues().then(function onData(data) {
|
||||
let now = new Date();
|
||||
let oldCount = 0;
|
||||
searchBar.value = "firefox health report";
|
||||
searchBar.focus();
|
||||
|
||||
function afterSearch() {
|
||||
searchBar.value = "";
|
||||
gBrowser.removeTab(tab);
|
||||
|
||||
// Make sure that the context searches are correctly recorded.
|
||||
let hs = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS").snapshot();
|
||||
Assert.ok(histogramKey in hs, "The histogram must contain the correct key");
|
||||
Assert.equal(hs[histogramKey].sum, numSearchesBefore + 1,
|
||||
"Performing a search increments the related SEARCH_COUNTS key by 1.");
|
||||
|
||||
// Find the right bucket for the "Foo" engine.
|
||||
let engine = Services.search.getEngineByName("Foo");
|
||||
let field = (engine.identifier || "other-Foo") + ".searchbar";
|
||||
Services.search.removeEngine(engine);
|
||||
}
|
||||
|
||||
if (data.days.hasDay(now)) {
|
||||
let day = data.days.getDay(now);
|
||||
if (day.has(field)) {
|
||||
oldCount = day.get(field);
|
||||
}
|
||||
}
|
||||
|
||||
// Now perform a search and ensure the count is incremented.
|
||||
let tab = gBrowser.addTab();
|
||||
gBrowser.selectedTab = tab;
|
||||
let searchBar = BrowserSearch.searchBar;
|
||||
|
||||
searchBar.value = "firefox health report";
|
||||
searchBar.focus();
|
||||
|
||||
function afterSearch() {
|
||||
searchBar.value = "";
|
||||
gBrowser.removeTab(tab);
|
||||
|
||||
m.getValues().then(function onData(data) {
|
||||
ok(data.days.hasDay(now), "Have data for today.");
|
||||
let day = data.days.getDay(now);
|
||||
|
||||
is(day.get(field), oldCount + 1, "Performing a search increments FHR count by 1.");
|
||||
|
||||
let engine = Services.search.getEngineByName("Foo");
|
||||
Services.search.removeEngine(engine);
|
||||
});
|
||||
}
|
||||
|
||||
EventUtils.synthesizeKey("VK_RETURN", {});
|
||||
executeSoon(() => executeSoon(afterSearch));
|
||||
});
|
||||
});
|
||||
EventUtils.synthesizeKey("VK_RETURN", {});
|
||||
executeSoon(() => executeSoon(afterSearch));
|
||||
}
|
||||
|
||||
function observer(subject, topic, data) {
|
||||
|
@ -84,7 +59,7 @@ function test() {
|
|||
|
||||
case "engine-current":
|
||||
is(Services.search.currentEngine.name, "Foo", "Current engine is Foo");
|
||||
testFHR();
|
||||
testTelemetry();
|
||||
break;
|
||||
|
||||
case "engine-removed":
|
||||
|
@ -101,9 +76,6 @@ function test() {
|
|||
}
|
||||
|
||||
function resetPreferences() {
|
||||
let service = Components.classes["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Components.interfaces.nsISupports)
|
||||
.wrappedJSObject;
|
||||
service.policy._prefs.resetBranch("datareporting.policy.");
|
||||
service.policy.dataSubmissionPolicyBypassNotification = true;
|
||||
Preferences.resetBranch("datareporting.policy.");
|
||||
Preferences.set("datareporting.policy.dataSubmissionPolicyBypassNotification", true);
|
||||
}
|
||||
|
|
|
@ -22,10 +22,8 @@ Cu.import("resource://gre/modules/osfile.jsm");
|
|||
Cu.import("resource://gre/modules/Task.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/services-common/utils.js");
|
||||
Cu.import("resource://gre/modules/services/datareporting/policy.jsm");
|
||||
Cu.import("resource://gre/modules/services/healthreport/healthreporter.jsm");
|
||||
Cu.import("resource://gre/modules/services/healthreport/providers.jsm");
|
||||
Cu.import("resource://testing-common/services/datareporting/mocks.jsm");
|
||||
|
||||
|
||||
var APP_INFO = {
|
||||
|
@ -182,14 +180,6 @@ InspectedHealthReporter.prototype = {
|
|||
const DUMMY_URI="http://localhost:62013/";
|
||||
|
||||
this.getHealthReporter = function (name, uri=DUMMY_URI, inspected=false) {
|
||||
// The healthreporters use the client id from the datareporting service,
|
||||
// so we need to ensure it is initialized.
|
||||
let drs = Cc["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Ci.nsISupports)
|
||||
.wrappedJSObject;
|
||||
drs.observe(null, "app-startup", null);
|
||||
drs.observe(null, "profile-after-change", null);
|
||||
|
||||
let branch = "healthreport.testing." + name + ".";
|
||||
|
||||
let prefs = new Preferences(branch + "healthreport.");
|
||||
|
@ -199,18 +189,7 @@ this.getHealthReporter = function (name, uri=DUMMY_URI, inspected=false) {
|
|||
let reporter;
|
||||
|
||||
let policyPrefs = new Preferences(branch + "policy.");
|
||||
let listener = new MockPolicyListener();
|
||||
listener.onRequestDataUpload = function (request) {
|
||||
let promise = reporter.requestDataUpload(request);
|
||||
MockPolicyListener.prototype.onRequestDataUpload.call(this, request);
|
||||
return promise;
|
||||
}
|
||||
listener.onRequestRemoteDelete = function (request) {
|
||||
let promise = reporter.deleteRemoteData(request);
|
||||
MockPolicyListener.prototype.onRequestRemoteDelete.call(this, request);
|
||||
return promise;
|
||||
}
|
||||
let policy = new DataReportingPolicy(policyPrefs, prefs, listener);
|
||||
let policy = {};
|
||||
let type = inspected ? InspectedHealthReporter : HealthReporter;
|
||||
reporter = new type(branch + "healthreport.", policy,
|
||||
"state-" + name + ".json");
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -12,20 +12,9 @@ Cu.import("resource://gre/modules/services/healthreport/providers.jsm");
|
|||
Cu.import("resource://testing-common/services/healthreport/utils.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "gDatareportingService",
|
||||
() => Cc["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Ci.nsISupports)
|
||||
.wrappedJSObject);
|
||||
|
||||
|
||||
function run_test() {
|
||||
do_get_profile();
|
||||
|
||||
// Send the needed startup notifications to the datareporting service
|
||||
// to ensure that it has been initialized.
|
||||
gDatareportingService.observe(null, "app-startup", null);
|
||||
gDatareportingService.observe(null, "profile-after-change", null);
|
||||
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ skip-if = toolkit == 'android' || toolkit == 'gonk'
|
|||
|
||||
[test_load_modules.js]
|
||||
[test_profile.js]
|
||||
[test_healthreporter.js]
|
||||
[test_provider_addons.js]
|
||||
skip-if = buildapp == 'mulet'
|
||||
tags = addons
|
||||
|
|
|
@ -22,8 +22,6 @@ const MILLISECONDS_PER_MINUTE = 60 * 1000;
|
|||
const MILLISECONDS_PER_HOUR = 60 * MILLISECONDS_PER_MINUTE;
|
||||
const MILLISECONDS_PER_DAY = 24 * MILLISECONDS_PER_HOUR;
|
||||
|
||||
const HAS_DATAREPORTINGSERVICE = "@mozilla.org/datareporting/service;1" in Cc;
|
||||
|
||||
const PREF_TELEMETRY_ENABLED = "toolkit.telemetry.enabled";
|
||||
|
||||
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
|
|
|
@ -208,11 +208,7 @@ add_task(function* test_pingHasClientId() {
|
|||
let ping = yield PingServer.promiseNextPing();
|
||||
checkPingFormat(ping, TEST_PING_TYPE, true, false);
|
||||
|
||||
if (HAS_DATAREPORTINGSERVICE &&
|
||||
Services.prefs.getBoolPref(PREF_FHR_UPLOAD_ENABLED)) {
|
||||
Assert.equal(ping.clientId, gClientID,
|
||||
"The correct clientId must be reported.");
|
||||
}
|
||||
Assert.equal(ping.clientId, gClientID, "The correct clientId must be reported.");
|
||||
});
|
||||
|
||||
add_task(function* test_pingHasEnvironment() {
|
||||
|
@ -234,11 +230,7 @@ add_task(function* test_pingHasEnvironmentAndClientId() {
|
|||
// Test a field in the environment build section.
|
||||
Assert.equal(ping.application.buildId, ping.environment.build.buildId);
|
||||
// Test that we have the correct clientId.
|
||||
if (HAS_DATAREPORTINGSERVICE &&
|
||||
Services.prefs.getBoolPref(PREF_FHR_UPLOAD_ENABLED)) {
|
||||
Assert.equal(ping.clientId, gClientID,
|
||||
"The correct clientId must be reported.");
|
||||
}
|
||||
Assert.equal(ping.clientId, gClientID, "The correct clientId must be reported.");
|
||||
});
|
||||
|
||||
add_task(function* test_archivePings() {
|
||||
|
|
|
@ -20,11 +20,6 @@ Cu.import("resource://gre/modules/TelemetryController.jsm", this);
|
|||
Cu.import("resource://gre/modules/TelemetrySession.jsm", this);
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "gDatareportingService",
|
||||
() => Cc["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Ci.nsISupports)
|
||||
.wrappedJSObject);
|
||||
|
||||
// Force the Telemetry enabled preference so that TelemetrySession.reset() doesn't exit early.
|
||||
Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
|
||||
|
||||
|
@ -71,12 +66,5 @@ function run_test() {
|
|||
// Make sure we have a profile directory.
|
||||
do_get_profile();
|
||||
|
||||
// Send the needed startup notifications to the datareporting service
|
||||
// to ensure that it has been initialized.
|
||||
if ("@mozilla.org/datareporting/service;1" in Cc) {
|
||||
gDatareportingService.observe(null, "app-startup", null);
|
||||
gDatareportingService.observe(null, "profile-after-change", null);
|
||||
}
|
||||
|
||||
run_next_test();
|
||||
}
|
||||
|
|
|
@ -34,16 +34,6 @@ function run_test() {
|
|||
Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
|
||||
Services.prefs.setBoolPref(PREF_FHR_UPLOAD_ENABLED, true);
|
||||
|
||||
// Send the needed startup notifications to the datareporting service
|
||||
// to ensure that it has been initialized.
|
||||
if (HAS_DATAREPORTINGSERVICE) {
|
||||
let drs = Cc["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Ci.nsISupports)
|
||||
.wrappedJSObject;
|
||||
drs.observe(null, "app-startup", null);
|
||||
drs.observe(null, "profile-after-change", null);
|
||||
}
|
||||
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,11 +19,6 @@ Cu.import("resource://gre/modules/Task.jsm", this);
|
|||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
var {OS: {File, Path, Constants}} = Cu.import("resource://gre/modules/osfile.jsm", {});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "gDatareportingService",
|
||||
() => Cc["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Ci.nsISupports)
|
||||
.wrappedJSObject);
|
||||
|
||||
// We increment TelemetryStorage's MAX_PING_FILE_AGE and
|
||||
// OVERDUE_PING_FILE_AGE by 1 minute so that our test pings exceed
|
||||
// those points in time, even taking into account file system imprecision.
|
||||
|
@ -165,11 +160,6 @@ function run_test() {
|
|||
do_get_profile();
|
||||
loadAddonManager("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
|
||||
|
||||
// Send the needed startup notifications to the datareporting service
|
||||
// to ensure that it has been initialized.
|
||||
gDatareportingService.observe(null, "app-startup", null);
|
||||
gDatareportingService.observe(null, "profile-after-change", null);
|
||||
|
||||
Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
|
||||
Services.prefs.setCharPref(TelemetryController.Constants.PREF_SERVER,
|
||||
"http://localhost:" + PingServer.port);
|
||||
|
|
|
@ -9,11 +9,6 @@ Cu.import("resource://gre/modules/TelemetryController.jsm", this);
|
|||
Cu.import("resource://gre/modules/TelemetrySession.jsm", this);
|
||||
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "gDatareportingService",
|
||||
() => Cc["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Ci.nsISupports)
|
||||
.wrappedJSObject);
|
||||
|
||||
// The @mozilla/xre/app-info;1 XPCOM object provided by the xpcshell test harness doesn't
|
||||
// implement the nsIAppInfo interface, which is needed by Services.jsm and
|
||||
// TelemetrySession.jsm. updateAppInfo() creates and registers a minimal mock app-info.
|
||||
|
@ -37,13 +32,6 @@ function getSimpleMeasurementsFromTelemetryController() {
|
|||
}
|
||||
|
||||
function initialiseTelemetry() {
|
||||
// Send the needed startup notifications to the datareporting service
|
||||
// to ensure that it has been initialized.
|
||||
if ("@mozilla.org/datareporting/service;1" in Cc) {
|
||||
gDatareportingService.observe(null, "app-startup", null);
|
||||
gDatareportingService.observe(null, "profile-after-change", null);
|
||||
}
|
||||
|
||||
return TelemetryController.setup().then(TelemetrySession.setup);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче