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