michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: /* Test inclusion of previous build ID in telemetry pings when build ID changes. michael@0: * bug 841028 michael@0: * michael@0: * Cases to cover: michael@0: * 1) Run with no "previousBuildID" stored in prefs: michael@0: * -> no previousBuildID in telemetry system info, new value set in prefs. michael@0: * 2) previousBuildID in prefs, equal to current build ID: michael@0: * -> no previousBuildID in telemetry, prefs not updated. michael@0: * 3) previousBuildID in prefs, not equal to current build ID: michael@0: * -> previousBuildID in telemetry, new value set in prefs. michael@0: */ michael@0: michael@0: "use strict" michael@0: michael@0: const Cu = Components.utils; michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm", this); michael@0: Cu.import("resource://gre/modules/TelemetryPing.jsm", this); michael@0: michael@0: // Force the Telemetry enabled preference so that TelemetryPing.reset() doesn't exit early. michael@0: Services.prefs.setBoolPref(TelemetryPing.Constants.PREF_ENABLED, true); michael@0: michael@0: // Set up our dummy AppInfo object so we can control the appBuildID. michael@0: Cu.import("resource://testing-common/AppInfo.jsm", this); michael@0: updateAppInfo(); michael@0: michael@0: // Check that when run with no previous build ID stored, we update the pref but do not michael@0: // put anything into the metadata. michael@0: add_task(function* test_firstRun() { michael@0: yield TelemetryPing.reset(); michael@0: let metadata = TelemetryPing.getMetadata(); michael@0: do_check_false("previousBuildID" in metadata); michael@0: let appBuildID = getAppInfo().appBuildID; michael@0: let buildIDPref = Services.prefs.getCharPref(TelemetryPing.Constants.PREF_PREVIOUS_BUILDID); michael@0: do_check_eq(appBuildID, buildIDPref); michael@0: }); michael@0: michael@0: // Check that a subsequent run with the same build ID does not put prev build ID in michael@0: // metadata. Assumes testFirstRun() has already been called to set the previousBuildID pref. michael@0: add_task(function* test_secondRun() { michael@0: yield TelemetryPing.reset(); michael@0: let metadata = TelemetryPing.getMetadata(); michael@0: do_check_false("previousBuildID" in metadata); michael@0: }); michael@0: michael@0: // Set up telemetry with a different app build ID and check that the old build ID michael@0: // is returned in the metadata and the pref is updated to the new build ID. michael@0: // Assumes testFirstRun() has been called to set the previousBuildID pref. michael@0: const NEW_BUILD_ID = "20130314"; michael@0: add_task(function* test_newBuild() { michael@0: let info = getAppInfo(); michael@0: let oldBuildID = info.appBuildID; michael@0: info.appBuildID = NEW_BUILD_ID; michael@0: yield TelemetryPing.reset(); michael@0: let metadata = TelemetryPing.getMetadata(); michael@0: do_check_eq(metadata.previousBuildID, oldBuildID); michael@0: let buildIDPref = Services.prefs.getCharPref(TelemetryPing.Constants.PREF_PREVIOUS_BUILDID); michael@0: do_check_eq(NEW_BUILD_ID, buildIDPref); michael@0: }); michael@0: michael@0: michael@0: function run_test() { michael@0: // Make sure we have a profile directory. michael@0: do_get_profile(); michael@0: run_next_test(); michael@0: }