mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-25 02:40:22 -10:00
Bug 1249491 - Add health report client ID migration test. r=sebastian,gfritzche
MozReview-Commit-ID: 9QbkKwEoNwq
This commit is contained in:
1 parent
a536c1c5b1
commit
13466163d7
1 file changed
+87
-1
+87
-1
@@ -6,15 +6,20 @@ package org.mozilla.gecko.tests;
|
||||
|
||||
import static org.mozilla.gecko.tests.helpers.AssertionHelper.*;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.gecko.GeckoProfile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class testUnifiedTelemetryClientId extends JavascriptBridgeTest {
|
||||
private static final String TEST_JS = "testUnifiedTelemetryClientId.js";
|
||||
|
||||
private static final String CLIENT_ID_PATH = "datareporting/state.json";
|
||||
private static final String FHR_DIR_PATH = "healthreport/";
|
||||
private static final String FHR_CLIENT_ID_PATH = FHR_DIR_PATH + "state.json";
|
||||
|
||||
private GeckoProfile profile;
|
||||
private File profileDir;
|
||||
@@ -32,7 +37,6 @@ public class testUnifiedTelemetryClientId extends JavascriptBridgeTest {
|
||||
public void tearDown() throws Exception {
|
||||
// Don't clear cache because who knows what state Gecko is in.
|
||||
resetTest(false);
|
||||
getClientIdFile().delete();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@@ -41,6 +45,8 @@ public class testUnifiedTelemetryClientId extends JavascriptBridgeTest {
|
||||
resetJSCache();
|
||||
}
|
||||
getClientIdFile().delete();
|
||||
getFHRClientIdFile().delete();
|
||||
getFHRClientIdParentDir().delete();
|
||||
}
|
||||
|
||||
// TODO: If the intent service runs in the background, it could break this test. The service is disabled
|
||||
@@ -55,6 +61,10 @@ public class testUnifiedTelemetryClientId extends JavascriptBridgeTest {
|
||||
testJavaCreatesClientId();
|
||||
resetTest(true);
|
||||
testJsCreatesClientId();
|
||||
resetTest(true);
|
||||
testJavaMigratesFromHealthReport();
|
||||
resetTest(true);
|
||||
testJsMigratesFromHealthReport();
|
||||
|
||||
getJS().syncCall("endTest");
|
||||
}
|
||||
@@ -105,6 +115,65 @@ public class testUnifiedTelemetryClientId extends JavascriptBridgeTest {
|
||||
fAssertEquals("Same client ID retrieved from Java", clientIdFromJS, clientIdFromJavaAgain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scenario: Java migrates client ID from FHR client ID file.
|
||||
* * FHR file already exists.
|
||||
* * Fennec starts on fresh profile
|
||||
* * Java code merges client ID to datareporting/state.json from healthreport/state.json
|
||||
* * Js accesses client ID from the same file
|
||||
* * Assert the client IDs are the same
|
||||
*/
|
||||
private void testJavaMigratesFromHealthReport() throws Exception {
|
||||
fAssertFalse("Client id file does not exist yet", getClientIdFile().exists());
|
||||
fAssertFalse("Health report file does not exist yet", getFHRClientIdFile().exists());
|
||||
|
||||
final String expectedClientId = UUID.randomUUID().toString();
|
||||
createFHRClientIdFile(expectedClientId);
|
||||
|
||||
final String clientIdFromJava = getClientIdFromJava();
|
||||
fAssertEquals("Health report client ID merged by Java", expectedClientId, clientIdFromJava);
|
||||
final String clientIdFromJS = getClientIdFromJS();
|
||||
fAssertEquals("Merged client ID read by JS", expectedClientId, clientIdFromJS);
|
||||
|
||||
final String clientIdFromJavaAgain = getClientIdFromJava();
|
||||
final String clientIdFromJSCache = getClientIdFromJS();
|
||||
resetJSCache();
|
||||
final String clientIdFromJSFileAgain = getClientIdFromJS();
|
||||
fAssertEquals("Same client ID retrieved from Java", expectedClientId, clientIdFromJavaAgain);
|
||||
fAssertEquals("Same client ID retrieved from JS cache", expectedClientId, clientIdFromJSCache);
|
||||
fAssertEquals("Same client ID retrieved from JS file", expectedClientId, clientIdFromJSFileAgain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scenario: JS merges client ID from FHR client ID file.
|
||||
* * FHR file already exists.
|
||||
* * Fennec starts on a fresh profile
|
||||
* * Js merges the client ID to datareporting/state.json from healthreport/state.json
|
||||
* * Java access the client ID from the same file
|
||||
* * Assert the client IDs are the same
|
||||
*/
|
||||
private void testJsMigratesFromHealthReport() throws Exception {
|
||||
fAssertFalse("Client id file does not exist yet", getClientIdFile().exists());
|
||||
fAssertFalse("Health report file does not exist yet", getFHRClientIdFile().exists());
|
||||
|
||||
final String expectedClientId = UUID.randomUUID().toString();
|
||||
createFHRClientIdFile(expectedClientId);
|
||||
|
||||
final String clientIdFromJS = getClientIdFromJS();
|
||||
fAssertEquals("Health report client ID merged by JS", expectedClientId, clientIdFromJS);
|
||||
final String clientIdFromJava = getClientIdFromJava();
|
||||
fAssertEquals("Merged client ID read by Java", expectedClientId, clientIdFromJava);
|
||||
|
||||
final String clientIdFromJavaAgain = getClientIdFromJava();
|
||||
final String clientIdFromJSCache = getClientIdFromJS();
|
||||
resetJSCache();
|
||||
final String clientIdFromJSFileAgain = getClientIdFromJS();
|
||||
fAssertEquals("Same client ID retrieved from Java", expectedClientId, clientIdFromJavaAgain);
|
||||
fAssertEquals("Same client ID retrieved from JS cache", expectedClientId, clientIdFromJSCache);
|
||||
fAssertEquals("Same client ID retrieved from JS file", expectedClientId, clientIdFromJSFileAgain);
|
||||
|
||||
}
|
||||
|
||||
private String getClientIdFromJava() throws IOException {
|
||||
// This assumes implementation details: it assumes the client ID
|
||||
// file is created when Java attempts to retrieve it if it does not exist.
|
||||
@@ -131,4 +200,21 @@ public class testUnifiedTelemetryClientId extends JavascriptBridgeTest {
|
||||
private File getClientIdFile() {
|
||||
return new File(profileDir, CLIENT_ID_PATH);
|
||||
}
|
||||
|
||||
private File getFHRClientIdParentDir() {
|
||||
return new File(profileDir, FHR_DIR_PATH);
|
||||
}
|
||||
|
||||
private File getFHRClientIdFile() {
|
||||
return new File(profileDir, FHR_CLIENT_ID_PATH);
|
||||
}
|
||||
|
||||
private void createFHRClientIdFile(final String clientId) throws JSONException {
|
||||
fAssertTrue("FHR directory created", getFHRClientIdParentDir().mkdirs());
|
||||
|
||||
final JSONObject obj = new JSONObject();
|
||||
obj.put("clientID", clientId);
|
||||
profile.writeFile(FHR_CLIENT_ID_PATH, obj.toString());
|
||||
fAssertTrue("FHR client ID file exists after writing", getFHRClientIdFile().exists());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user