From f935cbdf7c355a714e26f6932e58e1151a600c0e Mon Sep 17 00:00:00 2001 From: Alessio Placitelli Date: Tue, 5 Jan 2016 06:29:00 +0100 Subject: [PATCH] Bug 1234522 - Fix or remove the tests relying on the data reporting service. r=gfritzsche --- browser/base/content/test/general/browser.ini | 3 - .../test/general/browser_aboutHealthReport.js | 297 ++-- .../content/test/general/browser_aboutHome.js | 46 +- .../browser_contextSearchTabPosition.js | 78 +- .../browser_datachoices_notification.js | 11 - .../browser_datareporting_notification.js | 213 --- .../general/browser_urlbarSearchTelemetry.js | 5 - .../browser_urlbar_search_healthreport.js | 85 -- browser/base/content/test/general/head.js | 58 - .../healthreport_testRemoteCommands.html | 41 +- .../preferences/in-content/tests/browser.ini | 2 +- .../in-content/tests/browser_healthreport.js | 32 +- .../search/test/browser_healthreport.js | 104 +- .../healthreport/modules-testing/utils.jsm | 23 +- .../tests/xpcshell/test_healthreporter.js | 1284 ----------------- .../tests/xpcshell/test_provider_appinfo.js | 11 - .../healthreport/tests/xpcshell/xpcshell.ini | 1 - .../components/telemetry/tests/unit/head.js | 2 - .../tests/unit/test_TelemetryController.js | 12 +- .../unit/test_TelemetryControllerBuildID.js | 12 - .../unit/test_TelemetryControllerShutdown.js | 10 - .../tests/unit/test_TelemetrySendOldPings.js | 10 - .../tests/unit/test_TelemetryTimestamps.js | 12 - 23 files changed, 259 insertions(+), 2093 deletions(-) delete mode 100644 browser/base/content/test/general/browser_datareporting_notification.js delete mode 100644 browser/base/content/test/general/browser_urlbar_search_healthreport.js delete mode 100644 services/healthreport/tests/xpcshell/test_healthreporter.js diff --git a/browser/base/content/test/general/browser.ini b/browser/base/content/test/general/browser.ini index 3723d391d203..5c75c85458da 100644 --- a/browser/base/content/test/general/browser.ini +++ b/browser/base/content/test/general/browser.ini @@ -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] diff --git a/browser/base/content/test/general/browser_aboutHealthReport.js b/browser/base/content/test/general/browser_aboutHealthReport.js index d22497fc2cdd..33d1a1c58400 100644 --- a/browser/base/content/test/general/browser_aboutHealthReport.js +++ b/browser/base/content/test/general/browser_aboutHealthReport.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; +} diff --git a/browser/base/content/test/general/browser_aboutHome.js b/browser/base/content/test/general/browser_aboutHome.js index c32eb95ebd72..74696e0cdc3a 100644 --- a/browser/base/content/test/general/browser_aboutHome.js +++ b/browser/base/content/test/general/browser_aboutHome.js @@ -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 { diff --git a/browser/base/content/test/general/browser_contextSearchTabPosition.js b/browser/base/content/test/general/browser_contextSearchTabPosition.js index b8ac3c043560..766467890000 100644 --- a/browser/base/content/test/general/browser_contextSearchTabPosition.js +++ b/browser/base/content/test/general/browser_contextSearchTabPosition.js @@ -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"); +}); diff --git a/browser/base/content/test/general/browser_datachoices_notification.js b/browser/base/content/test/general/browser_datachoices_notification.js index 729a29e3f12f..1a7056bfebf6 100644 --- a/browser/base/content/test/general/browser_datachoices_notification.js +++ b/browser/base/content/test/general/browser_datachoices_notification.js @@ -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() { diff --git a/browser/base/content/test/general/browser_datareporting_notification.js b/browser/base/content/test/general/browser_datareporting_notification.js deleted file mode 100644 index ce18a5f5a0df..000000000000 --- a/browser/base/content/test/general/browser_datareporting_notification.js +++ /dev/null @@ -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(); -} diff --git a/browser/base/content/test/general/browser_urlbarSearchTelemetry.js b/browser/base/content/test/general/browser_urlbarSearchTelemetry.js index 21a8ed7e19c7..98243ac9d256 100644 --- a/browser/base/content/test/general/browser_urlbarSearchTelemetry.js +++ b/browser/base/content/test/general/browser_urlbarSearchTelemetry.js @@ -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"); } /** diff --git a/browser/base/content/test/general/browser_urlbar_search_healthreport.js b/browser/base/content/test/general/browser_urlbar_search_healthreport.js deleted file mode 100644 index 6a37a80fb5d0..000000000000 --- a/browser/base/content/test/general/browser_urlbar_search_healthreport.js +++ /dev/null @@ -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); -}); diff --git a/browser/base/content/test/general/head.js b/browser/base/content/test/general/head.js index 4e5f98f5a074..2f20399e19a1 100644 --- a/browser/base/content/test/general/head.js +++ b/browser/base/content/test/general/head.js @@ -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. -} diff --git a/browser/base/content/test/general/healthreport_testRemoteCommands.html b/browser/base/content/test/general/healthreport_testRemoteCommands.html index cc9e70767084..7978914f2be4 100644 --- a/browser/base/content/test/general/healthreport_testRemoteCommands.html +++ b/browser/base/content/test/general/healthreport_testRemoteCommands.html @@ -7,35 +7,14 @@