Bug 1161515 - Extend test coverage. r=gfritzsche a=sledru
authorQeole <qeole@outlook.com>
Tue, 26 May 2015 05:50:00 -0400
changeset 275130 abc32c4f3a3d910b085fdd70183c1b7970dbaa95
parent 275129 4f9750a7c70f454128d88979f7433569e9a4bbc7
child 275131 b33a6c442083deabc5e5a575949d4a36e3584e43
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche, sledru
bugs1161515
milestone40.0a2
Bug 1161515 - Extend test coverage. r=gfritzsche a=sledru
toolkit/components/telemetry/tests/unit/test_TelemetrySession.js
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySession.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySession.js
@@ -230,17 +230,18 @@ function checkPayloadInfo(data) {
   };
 
   const EXPECTED_INFO_FIELDS_TYPES = {
     reason: stringCheck,
     revision: revisionCheck,
     timezoneOffset: numberCheck,
     sessionId: uuidCheck,
     subsessionId: uuidCheck,
-    // Special case: previousSubsessionId is null on first run.
+    // Special cases: previousSessionId and previousSubsessionId are null on first run.
+    previousSessionId: (arg) => { return (arg) ? uuidCheck(arg) : true; },
     previousSubsessionId: (arg) => { return (arg) ? uuidCheck(arg) : true; },
     subsessionCounter: positiveNumberCheck,
     profileSubsessionCounter: positiveNumberCheck,
     sessionStartDate: isoDateCheck,
     subsessionStartDate: isoDateCheck,
     subsessionLength: positiveNumberCheck,
   };
 
@@ -1177,18 +1178,19 @@ add_task(function* test_savedSessionData
   Preferences.reset(PREF_TEST);
   const PREFS_TO_WATCH = new Map([
     [PREF_TEST, TelemetryEnvironment.RECORD_PREF_VALUE],
   ]);
 
   // We expect one new subsession when starting TelemetrySession and one after triggering
   // an environment change.
   const expectedSubsessions = sessionState.profileSubsessionCounter + 2;
-  const expectedUUID = "009fd1ad-b85e-4817-b3e5-000000003785";
-  fakeGenerateUUID(generateUUID, () => expectedUUID);
+  const expectedSessionUUID = "ff602e52-47a1-b7e8-4c1a-ffffffffc87a";
+  const expectedSubsessionUUID = "009fd1ad-b85e-4817-b3e5-000000003785";
+  fakeGenerateUUID(() => expectedSessionUUID, () => expectedSubsessionUUID);
 
   if (gIsAndroid) {
     // We don't support subsessions yet on Android, so skip the next checks.
     return;
   }
 
   // Start TelemetrySession so that it loads the session data file.
   yield TelemetrySession.reset();
@@ -1205,50 +1207,53 @@ add_task(function* test_savedSessionData
 
   let payload = TelemetrySession.getPayload();
   Assert.equal(payload.info.profileSubsessionCounter, expectedSubsessions);
   yield TelemetrySession.shutdown();
 
   // Load back the serialised session data.
   let data = yield CommonUtils.readJSON(dataFilePath);
   Assert.equal(data.profileSubsessionCounter, expectedSubsessions);
-  Assert.equal(data.subsessionId, expectedUUID);
+  Assert.equal(data.sessionId, expectedSessionUUID);
+  Assert.equal(data.subsessionId, expectedSubsessionUUID);
 });
 
 add_task(function* test_sessionData_ShortSession() {
   if (gIsAndroid) {
     // We don't support subsessions yet on Android, so skip the next checks.
     return;
   }
 
   const SESSION_STATE_PATH = OS.Path.join(DATAREPORTING_PATH, "session-state.json");
 
   // Shut down Telemetry and remove the session state file.
   yield TelemetrySession.shutdown();
   yield OS.File.remove(SESSION_STATE_PATH, { ignoreAbsent: true });
 
-  const expectedUUID = "009fd1ad-b85e-4817-b3e5-000000003785";
-  fakeGenerateUUID(generateUUID, () => expectedUUID);
+  const expectedSessionUUID = "ff602e52-47a1-b7e8-4c1a-ffffffffc87a";
+  const expectedSubsessionUUID = "009fd1ad-b85e-4817-b3e5-000000003785";
+  fakeGenerateUUID(() => expectedSessionUUID, () => expectedSubsessionUUID);
 
   // We intentionally don't wait for the setup to complete and shut down to simulate
   // short sessions. We expect the profile subsession counter to be 1.
   TelemetrySession.reset();
   yield TelemetrySession.shutdown();
 
   // Restore the UUID generation functions.
   fakeGenerateUUID(generateUUID, generateUUID);
 
   // Start TelemetrySession so that it loads the session data file. We expect the profile
   // subsession counter to be incremented by 1 again.
   yield TelemetrySession.reset();
 
   // We expect 2 profile subsession counter updates.
   let payload = TelemetrySession.getPayload();
   Assert.equal(payload.info.profileSubsessionCounter, 2);
-  Assert.equal(payload.info.previousSubsessionId, expectedUUID);
+  Assert.equal(payload.info.previousSessionId, expectedSessionUUID);
+  Assert.equal(payload.info.previousSubsessionId, expectedSubsessionUUID);
 });
 
 add_task(function* test_invalidSessionData() {
   // Create the directory which will contain the data file, if it doesn't already
   // exist.
   yield OS.File.makeDir(DATAREPORTING_PATH);
 
   // Write test data to the session data file.
@@ -1256,28 +1261,30 @@ add_task(function* test_invalidSessionDa
   const sessionState = {
     profileSubsessionCounter: "not-a-number?",
     someOtherField: 12,
   };
   yield CommonUtils.writeJSON(sessionState, dataFilePath);
 
   // The session data file should not load. Only expect the current subsession.
   const expectedSubsessions = 1;
-  const expectedUUID = "009fd1ad-b85e-4817-b3e5-000000003785";
-  fakeGenerateUUID(() => expectedUUID, () => expectedUUID);
+  const expectedSessionUUID = "ff602e52-47a1-b7e8-4c1a-ffffffffc87a";
+  const expectedSubsessionUUID = "009fd1ad-b85e-4817-b3e5-000000003785";
+  fakeGenerateUUID(() => expectedSessionUUID, () => expectedSubsessionUUID);
   // Start TelemetrySession so that it loads the session data file.
   yield TelemetrySession.reset();
   let payload = TelemetrySession.getPayload();
   Assert.equal(payload.info.profileSubsessionCounter, expectedSubsessions);
   yield TelemetrySession.shutdown();
 
   // Load back the serialised session data.
   let data = yield CommonUtils.readJSON(dataFilePath);
   Assert.equal(data.profileSubsessionCounter, expectedSubsessions);
-  Assert.equal(data.subsessionId, expectedUUID);
+  Assert.equal(data.sessionId, expectedSessionUUID);
+  Assert.equal(data.subsessionId, expectedSubsessionUUID);
 });
 
 add_task(function* test_abortedSession() {
   if (gIsAndroid || gIsGonk) {
     // We don't have the aborted session ping here.
     return;
   }