1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/telemetry/tests/unit/test_TelemetryPingBuildID.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,69 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ 1.6 +*/ 1.7 +/* Test inclusion of previous build ID in telemetry pings when build ID changes. 1.8 + * bug 841028 1.9 + * 1.10 + * Cases to cover: 1.11 + * 1) Run with no "previousBuildID" stored in prefs: 1.12 + * -> no previousBuildID in telemetry system info, new value set in prefs. 1.13 + * 2) previousBuildID in prefs, equal to current build ID: 1.14 + * -> no previousBuildID in telemetry, prefs not updated. 1.15 + * 3) previousBuildID in prefs, not equal to current build ID: 1.16 + * -> previousBuildID in telemetry, new value set in prefs. 1.17 + */ 1.18 + 1.19 +"use strict" 1.20 + 1.21 +const Cu = Components.utils; 1.22 + 1.23 +Cu.import("resource://gre/modules/Services.jsm", this); 1.24 +Cu.import("resource://gre/modules/TelemetryPing.jsm", this); 1.25 + 1.26 +// Force the Telemetry enabled preference so that TelemetryPing.reset() doesn't exit early. 1.27 +Services.prefs.setBoolPref(TelemetryPing.Constants.PREF_ENABLED, true); 1.28 + 1.29 +// Set up our dummy AppInfo object so we can control the appBuildID. 1.30 +Cu.import("resource://testing-common/AppInfo.jsm", this); 1.31 +updateAppInfo(); 1.32 + 1.33 +// Check that when run with no previous build ID stored, we update the pref but do not 1.34 +// put anything into the metadata. 1.35 +add_task(function* test_firstRun() { 1.36 + yield TelemetryPing.reset(); 1.37 + let metadata = TelemetryPing.getMetadata(); 1.38 + do_check_false("previousBuildID" in metadata); 1.39 + let appBuildID = getAppInfo().appBuildID; 1.40 + let buildIDPref = Services.prefs.getCharPref(TelemetryPing.Constants.PREF_PREVIOUS_BUILDID); 1.41 + do_check_eq(appBuildID, buildIDPref); 1.42 +}); 1.43 + 1.44 +// Check that a subsequent run with the same build ID does not put prev build ID in 1.45 +// metadata. Assumes testFirstRun() has already been called to set the previousBuildID pref. 1.46 +add_task(function* test_secondRun() { 1.47 + yield TelemetryPing.reset(); 1.48 + let metadata = TelemetryPing.getMetadata(); 1.49 + do_check_false("previousBuildID" in metadata); 1.50 +}); 1.51 + 1.52 +// Set up telemetry with a different app build ID and check that the old build ID 1.53 +// is returned in the metadata and the pref is updated to the new build ID. 1.54 +// Assumes testFirstRun() has been called to set the previousBuildID pref. 1.55 +const NEW_BUILD_ID = "20130314"; 1.56 +add_task(function* test_newBuild() { 1.57 + let info = getAppInfo(); 1.58 + let oldBuildID = info.appBuildID; 1.59 + info.appBuildID = NEW_BUILD_ID; 1.60 + yield TelemetryPing.reset(); 1.61 + let metadata = TelemetryPing.getMetadata(); 1.62 + do_check_eq(metadata.previousBuildID, oldBuildID); 1.63 + let buildIDPref = Services.prefs.getCharPref(TelemetryPing.Constants.PREF_PREVIOUS_BUILDID); 1.64 + do_check_eq(NEW_BUILD_ID, buildIDPref); 1.65 +}); 1.66 + 1.67 + 1.68 +function run_test() { 1.69 + // Make sure we have a profile directory. 1.70 + do_get_profile(); 1.71 + run_next_test(); 1.72 +}