toolkit/components/telemetry/tests/unit/test_TelemetryPingBuildID.js

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/
michael@0 3 */
michael@0 4 /* Test inclusion of previous build ID in telemetry pings when build ID changes.
michael@0 5 * bug 841028
michael@0 6 *
michael@0 7 * Cases to cover:
michael@0 8 * 1) Run with no "previousBuildID" stored in prefs:
michael@0 9 * -> no previousBuildID in telemetry system info, new value set in prefs.
michael@0 10 * 2) previousBuildID in prefs, equal to current build ID:
michael@0 11 * -> no previousBuildID in telemetry, prefs not updated.
michael@0 12 * 3) previousBuildID in prefs, not equal to current build ID:
michael@0 13 * -> previousBuildID in telemetry, new value set in prefs.
michael@0 14 */
michael@0 15
michael@0 16 "use strict"
michael@0 17
michael@0 18 const Cu = Components.utils;
michael@0 19
michael@0 20 Cu.import("resource://gre/modules/Services.jsm", this);
michael@0 21 Cu.import("resource://gre/modules/TelemetryPing.jsm", this);
michael@0 22
michael@0 23 // Force the Telemetry enabled preference so that TelemetryPing.reset() doesn't exit early.
michael@0 24 Services.prefs.setBoolPref(TelemetryPing.Constants.PREF_ENABLED, true);
michael@0 25
michael@0 26 // Set up our dummy AppInfo object so we can control the appBuildID.
michael@0 27 Cu.import("resource://testing-common/AppInfo.jsm", this);
michael@0 28 updateAppInfo();
michael@0 29
michael@0 30 // Check that when run with no previous build ID stored, we update the pref but do not
michael@0 31 // put anything into the metadata.
michael@0 32 add_task(function* test_firstRun() {
michael@0 33 yield TelemetryPing.reset();
michael@0 34 let metadata = TelemetryPing.getMetadata();
michael@0 35 do_check_false("previousBuildID" in metadata);
michael@0 36 let appBuildID = getAppInfo().appBuildID;
michael@0 37 let buildIDPref = Services.prefs.getCharPref(TelemetryPing.Constants.PREF_PREVIOUS_BUILDID);
michael@0 38 do_check_eq(appBuildID, buildIDPref);
michael@0 39 });
michael@0 40
michael@0 41 // Check that a subsequent run with the same build ID does not put prev build ID in
michael@0 42 // metadata. Assumes testFirstRun() has already been called to set the previousBuildID pref.
michael@0 43 add_task(function* test_secondRun() {
michael@0 44 yield TelemetryPing.reset();
michael@0 45 let metadata = TelemetryPing.getMetadata();
michael@0 46 do_check_false("previousBuildID" in metadata);
michael@0 47 });
michael@0 48
michael@0 49 // Set up telemetry with a different app build ID and check that the old build ID
michael@0 50 // is returned in the metadata and the pref is updated to the new build ID.
michael@0 51 // Assumes testFirstRun() has been called to set the previousBuildID pref.
michael@0 52 const NEW_BUILD_ID = "20130314";
michael@0 53 add_task(function* test_newBuild() {
michael@0 54 let info = getAppInfo();
michael@0 55 let oldBuildID = info.appBuildID;
michael@0 56 info.appBuildID = NEW_BUILD_ID;
michael@0 57 yield TelemetryPing.reset();
michael@0 58 let metadata = TelemetryPing.getMetadata();
michael@0 59 do_check_eq(metadata.previousBuildID, oldBuildID);
michael@0 60 let buildIDPref = Services.prefs.getCharPref(TelemetryPing.Constants.PREF_PREVIOUS_BUILDID);
michael@0 61 do_check_eq(NEW_BUILD_ID, buildIDPref);
michael@0 62 });
michael@0 63
michael@0 64
michael@0 65 function run_test() {
michael@0 66 // Make sure we have a profile directory.
michael@0 67 do_get_profile();
michael@0 68 run_next_test();
michael@0 69 }

mercurial