Bug 913070 - Move TelemetryPing to a jsm. r=Yoric, r=glandium

--HG--
rename : toolkit/components/telemetry/TelemetryPing.js => toolkit/components/telemetry/TelemetryPing.jsm
This commit is contained in:
Roberto A. Vitillo 2014-01-13 14:20:09 +00:00
parent b4de6399fb
commit c32f755c81
14 changed files with 1204 additions and 1090 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,2 @@
component {55d6a5fa-130e-4ee6-a158-0133af3b86ba} TelemetryPing.js
contract @mozilla.org/base/telemetry-ping;1 {55d6a5fa-130e-4ee6-a158-0133af3b86ba}
category profile-after-change TelemetryPing @mozilla.org/base/telemetry-ping;1

View File

@ -0,0 +1,28 @@
/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */
/* 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/. */
"use strict";
const Cu = Components.utils;
Cu.import("resource://gre/modules/TelemetryPing.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm")
/**
* TelemetryStartup is needed to forward the "profile-after-change" notification
* to TelemetryPing.jsm.
*/
function TelemetryStartup() {
}
TelemetryStartup.prototype.classID = Components.ID("{117b219f-92fe-4bd2-a21b-95a342a9d474}");
TelemetryStartup.prototype.QueryInterface = XPCOMUtils.generateQI([Components.interfaces.nsIObserver])
TelemetryStartup.prototype.observe = function(aSubject, aTopic, aData){
if (aTopic == "profile-after-change") {
TelemetryPing.observe(null, "profile-after-change", null);
}
}
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TelemetryStartup]);

View File

@ -0,0 +1,3 @@
component {117b219f-92fe-4bd2-a21b-95a342a9d474} TelemetryStartup.js
contract @mozilla.org/base/telemetry-startup;1 {117b219f-92fe-4bd2-a21b-95a342a9d474}
category profile-after-change TelemetryStartup @mozilla.org/base/telemetry-startup;1

View File

@ -24,11 +24,10 @@ SOURCES += [
]
EXTRA_COMPONENTS += [
'TelemetryPing.manifest',
]
EXTRA_PP_COMPONENTS += [
'TelemetryPing.js',
'TelemetryPing.manifest',
'TelemetryStartup.js',
'TelemetryStartup.manifest'
]
EXTRA_JS_MODULES += [
@ -38,6 +37,7 @@ EXTRA_JS_MODULES += [
]
EXTRA_PP_JS_MODULES += [
'TelemetryPing.jsm',
'UITelemetry.jsm',
]

View File

@ -17,6 +17,7 @@ Cu.import("resource://testing-common/httpd.js");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/LightweightThemeManager.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/TelemetryPing.jsm");
const IGNORE_HISTOGRAM = "test::ignore_me";
const IGNORE_HISTOGRAM_TO_CLONE = "MEMORY_HEAP_ALLOCATED";
@ -38,7 +39,6 @@ const NUMBER_OF_THREADS_TO_LAUNCH = 30;
var gNumberOfThreadsLaunched = 0;
const Telemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry);
const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsITelemetryPing);
var httpserver = new HttpServer();
var serverStarted = false;

View File

@ -13,13 +13,13 @@
* -> previousBuildID in telemetry, new value set in prefs.
*/
Components.utils.import("resource://gre/modules/Services.jsm");
const Cu = Components.utils;
// Get the TelemetryPing definitions directly so we can test it without going through xpcom.
Services.scriptloader.loadSubScript("resource://gre/components/TelemetryPing.js");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/TelemetryPing.jsm");
// Force the Telemetry enabled preference so that TelemetryPing.setup() doesn't exit early.
Services.prefs.setBoolPref(PREF_ENABLED, true);
// Force the Telemetry enabled preference so that TelemetryPing.reset() doesn't exit early.
Services.prefs.setBoolPref(TelemetryPing.Constants.PREF_ENABLED, true);
// Set up our dummy AppInfo object so we can control the appBuildID.
Cu.import("resource://testing-common/AppInfo.jsm");
@ -28,25 +28,22 @@ updateAppInfo();
// Check that when run with no previous build ID stored, we update the pref but do not
// put anything into the metadata.
function testFirstRun() {
let ping = new TelemetryPing();
ping.setup();
let metadata = ping.getMetadata();
TelemetryPing.reset();
let metadata = TelemetryPing.getMetadata();
do_check_false("previousBuildID" in metadata);
let appBuildID = getAppInfo().appBuildID;
let buildIDPref = Services.prefs.getCharPref(PREF_PREVIOUS_BUILDID);
let buildIDPref = Services.prefs.getCharPref(TelemetryPing.Constants.PREF_PREVIOUS_BUILDID);
do_check_eq(appBuildID, buildIDPref);
}
// Check that a subsequent run with the same build ID does not put prev build ID in
// metadata. Assumes testFirstRun() has already been called to set the previousBuildID pref.
function testSecondRun() {
let ping = new TelemetryPing();
ping.setup();
let metadata = ping.getMetadata();
TelemetryPing.reset();
let metadata = TelemetryPing.getMetadata();
do_check_false("previousBuildID" in metadata);
}
// Set up telemetry with a different app build ID and check that the old build ID
// is returned in the metadata and the pref is updated to the new build ID.
// Assumes testFirstRun() has been called to set the previousBuildID pref.
@ -55,11 +52,10 @@ function testNewBuild() {
let info = getAppInfo();
let oldBuildID = info.appBuildID;
info.appBuildID = NEW_BUILD_ID;
let ping = new TelemetryPing();
ping.setup();
let metadata = ping.getMetadata();
TelemetryPing.reset();
let metadata = TelemetryPing.getMetadata();
do_check_eq(metadata.previousBuildID, oldBuildID);
let buildIDPref = Services.prefs.getCharPref(PREF_PREVIOUS_BUILDID);
let buildIDPref = Services.prefs.getCharPref(TelemetryPing.Constants.PREF_PREVIOUS_BUILDID);
do_check_eq(NEW_BUILD_ID, buildIDPref);
}

View File

@ -1,9 +1,12 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Check that TelemetryPing notifies correctly on idle.
// Check that TelemetryPing notifies correctly on idle-daily.
Components.utils.import("resource://gre/modules/Services.jsm");
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/TelemetryPing.jsm");
function run_test() {
do_test_pending();
@ -13,7 +16,5 @@ function run_test() {
do_test_finished();
}, "gather-telemetry", false);
Components.classes["@mozilla.org/base/telemetry-ping;1"]
.getService(Components.interfaces.nsITelemetryPing)
.observe(null, "idle-daily", null);
TelemetryPing.observe(null, "idle-daily", null);
}

View File

@ -10,16 +10,16 @@
* overdue and recent pings.
*/
Components.utils.import("resource://gre/modules/Services.jsm");
// Get the TelemetryPing definitions directly so we can test it without going through xpcom.
// That gives us Cc, Ci, Cr and Cu, as well as a number of consts like PREF_ENABLED,
// and PREF_SERVER.
Services.scriptloader.loadSubScript("resource://gre/components/TelemetryPing.js");
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://testing-common/httpd.js");
Cu.import("resource://gre/modules/Promise.jsm");
Cu.import("resource://gre/modules/TelemetryFile.jsm");
Cu.import("resource://gre/modules/TelemetryPing.jsm");
// We increment TelemetryFile's MAX_PING_FILE_AGE and
// OVERDUE_PING_FILE_AGE by 1ms so that our test pings exceed
@ -54,11 +54,10 @@ function createSavedPings(aNum, aAge) {
// Create a TelemetryPing service that we can generate payloads from.
// Luckily, the TelemetryPing constructor does nothing that we need to
// clean up.
let pingService = new TelemetryPing();
let pings = [];
let age = Date.now() - aAge;
for (let i = 0; i < aNum; ++i) {
let payload = pingService.getPayload();
let payload = TelemetryPing.getPayload();
let ping = { slug: "test-ping-" + gCreatedPings, reason: "test", payload: payload };
TelemetryFile.savePing(ping);
if (aAge) {
@ -190,8 +189,8 @@ function stopHttpServer() {
* Teardown a TelemetryPing instance and clear out any pending
* pings to put as back in the starting state.
*/
function resetTelemetry(aPingService) {
aPingService.uninstall();
function resetTelemetry() {
TelemetryPing.uninstall();
// Quick and dirty way to clear TelemetryFile's pendingPings
// collection, and put it back in its initial state.
let gen = TelemetryFile.popPendingPings();
@ -203,17 +202,15 @@ function resetTelemetry(aPingService) {
* mode.
*/
function startTelemetry() {
let service = new TelemetryPing();
service.setup(true);
return service;
TelemetryPing.setup();
}
function run_test() {
gHttpServer.registerPrefixHandler("/submit/telemetry/", pingHandler);
gHttpServer.start(-1);
do_get_profile();
Services.prefs.setBoolPref(PREF_ENABLED, true);
Services.prefs.setCharPref(PREF_SERVER,
Services.prefs.setBoolPref(TelemetryPing.Constants.PREF_ENABLED, true);
Services.prefs.setCharPref(TelemetryPing.Constants.PREF_SERVER,
"http://localhost:" + gHttpServer.identity.primaryPort);
run_next_test();
}
@ -224,20 +221,20 @@ function run_test() {
*/
add_task(function test_expired_pings_are_deleted() {
let expiredPings = createSavedPings(EXPIRED_PINGS, EXPIRED_PING_FILE_AGE);
let pingService = startTelemetry();
startTelemetry();
yield assertReceivedNoPings();
assertNotSaved(expiredPings);
resetTelemetry(pingService);
})
resetTelemetry();
});
/**
* Test that really recent pings are not sent on Telemetry initialization.
*/
add_task(function test_recent_pings_not_sent() {
let recentPings = createSavedPings(RECENT_PINGS);
let pingService = startTelemetry();
startTelemetry();
yield assertReceivedNoPings();
resetTelemetry(pingService);
resetTelemetry();
clearPings(recentPings);
});
@ -251,14 +248,14 @@ add_task(function test_overdue_pings_trigger_send() {
let expiredPings = createSavedPings(EXPIRED_PINGS, EXPIRED_PING_FILE_AGE);
let overduePings = createSavedPings(OVERDUE_PINGS, OVERDUE_PING_FILE_AGE);
let pingService = startTelemetry();
startTelemetry();
yield assertReceivedPings(TOTAL_EXPECTED_PINGS);
assertNotSaved(recentPings);
assertNotSaved(expiredPings);
assertNotSaved(overduePings);
resetTelemetry(pingService);
})
resetTelemetry();
});
add_task(function teardown() {
yield stopHttpServer();

View File

@ -9,6 +9,7 @@ Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/ThirdPartyCookieProbe.jsm");
Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
Cu.import("resource://gre/modules/TelemetryPing.jsm");
let TOPIC_ACCEPTED = "third-party-cookie-accepted";
let TOPIC_REJECTED = "third-party-cookie-rejected";
@ -19,8 +20,6 @@ const NUMBER_OF_REJECTS = 30;
const NUMBER_OF_ACCEPTS = 17;
const NUMBER_OF_REPEATS = 5;
const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsITelemetryPing);
let gCookieService;
let gThirdPartyCookieProbe;

View File

@ -10,14 +10,13 @@ const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/TelemetryTimestamps.jsm");
Cu.import("resource://gre/modules/TelemetryPing.jsm");
const Telemetry = Services.telemetry;
const bundle = Services.strings.createBundle(
"chrome://global/locale/aboutTelemetry.properties");
const brandBundle = Services.strings.createBundle(
"chrome://branding/locale/brand.properties");
const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].
getService(Ci.nsITelemetryPing);
// Maximum height of a histogram bar (in em for html, in chars for text)
const MAX_BAR_HEIGHT = 18;

View File

@ -13,10 +13,8 @@ Cu.import("resource://testing-common/AppInfo.jsm");
updateAppInfo();
function getSimpleMeasurementsFromTelemetryPing() {
const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsITelemetryPing);
let ping = TelemetryPing.getPayload();
return ping.simpleMeasurements;
return Cu.import("resource://gre/modules/TelemetryPing.jsm", {}).
TelemetryPing.getPayload().simpleMeasurements;
}
function run_test() {

View File

@ -2264,8 +2264,7 @@ var XPIProvider = {
}
catch (e) { }
const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsITelemetryPing);
TelemetryPing.setAddOns(data);
Cu.import("resource://gre/modules/TelemetryPing.jsm", {}).TelemetryPing.setAddOns(data);
},
/**