blob: b5035ff56c4af5a439ea28257ca6036bb0aba271 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
/* Android-only TelemetryEnvironment xpcshell test that ensures that the device data is stored in the Environment.
*/
const { TelemetryEnvironment } = ChromeUtils.importESModule(
"resource://gre/modules/TelemetryEnvironment.sys.mjs"
);
/**
* Check that a value is a string and not empty.
*
* @param aValue The variable to check.
* @return True if |aValue| has type "string" and is not empty, False otherwise.
*/
function checkString(aValue) {
return typeof aValue == "string" && aValue != "";
}
/**
* If value is non-null, check if it's a valid string.
*
* @param aValue The variable to check.
* @return True if it's null or a valid string, false if it's non-null and an invalid
* string.
*/
function checkNullOrString(aValue) {
if (aValue) {
return checkString(aValue);
} else if (aValue === null) {
return true;
}
return false;
}
/**
* If value is non-null, check if it's a boolean.
*
* @param aValue The variable to check.
* @return True if it's null or a valid boolean, false if it's non-null and an invalid
* boolean.
*/
function checkNullOrBool(aValue) {
return aValue === null || typeof aValue == "boolean";
}
function checkSystemSection(data) {
Assert.ok("system" in data, "There must be a system section in Environment.");
// Device data is only available on Android.
if (gIsAndroid) {
let deviceData = data.system.device;
Assert.ok(checkNullOrString(deviceData.model));
Assert.ok(checkNullOrString(deviceData.manufacturer));
Assert.ok(checkNullOrString(deviceData.hardware));
Assert.ok(checkNullOrBool(deviceData.isTablet));
}
}
add_task(async function test_systemEnvironment() {
let environmentData = TelemetryEnvironment.currentEnvironment;
checkSystemSection(environmentData);
});
|