Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /device-memory/device-memory.https.any.html - WPT Dashboard Interop Dashboard
- /device-memory/device-memory.https.any.worker.html - WPT Dashboard Interop Dashboard
function isPowerOfTwo(n) {
const log2 = Math.log2(n);
return log2 == Math.ceil(log2);
}
// Note the spec suggests applying implementation-defined min and max limits
// to reduce fingerprinting risk for less common memory configurations.
// However, it does not recommend limits so these are not tested in WPT.
// These should be tested by implementors.
test(function() {
assert_equals(typeof navigator.deviceMemory, "number",
"navigator.deviceMemory returns a number");
assert_true(navigator.deviceMemory >= 0,
"navigator.deviceMemory returns a positive value");
assert_true(isPowerOfTwo(navigator.deviceMemory),
"navigator.deviceMemory returns a power of 2");
}, "navigator.deviceMemory is a positive number, a power of 2");