1+ // Flags: --expose-internals
2+
13'use strict' ;
24
35require ( '../common' ) ;
46const assert = require ( 'assert' ) ;
7+ const {
8+ getApproximatedDeviceMemory,
9+ } = require ( 'internal/navigator' ) ;
510
611const is = {
712 number : ( value , key ) => {
@@ -10,6 +15,34 @@ const is = {
1015 } ,
1116} ;
1217
18+ assert . strictEqual ( typeof navigator . deviceMemory , 'number' ) ;
19+ assert . ok ( navigator . deviceMemory >= 0 ) ;
20+
21+ assert . strictEqual ( getApproximatedDeviceMemory ( 0 ) , 0 ) ;
22+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 27 ) , 0.125 ) ;
23+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 28 ) , 0.25 ) ;
24+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 29 ) , 0.5 ) ;
25+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 30 ) , 1 ) ;
26+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 31 ) , 2 ) ;
27+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 32 ) , 4 ) ;
28+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 33 ) , 8 ) ;
29+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 34 ) , 16 ) ;
30+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 35 ) , 32 ) ;
31+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 36 ) , 64 ) ;
32+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 37 ) , 128 ) ;
33+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 38 ) , 256 ) ;
34+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 39 ) , 512 ) ;
35+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 40 ) , 1024 ) ;
36+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 41 ) , 2048 ) ;
37+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 42 ) , 4096 ) ;
38+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 43 ) , 8192 ) ;
39+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 44 ) , 16384 ) ;
40+ assert . strictEqual ( getApproximatedDeviceMemory ( 2 ** 45 ) , 32768 ) ;
41+
42+ // https://github.com/w3c/device-memory#the-header
43+ assert . strictEqual ( getApproximatedDeviceMemory ( 768 * 1024 * 1024 ) , 0.5 ) ;
44+ assert . strictEqual ( getApproximatedDeviceMemory ( 1793 * 1024 * 1024 ) , 2 ) ;
45+
1346is . number ( + navigator . hardwareConcurrency , 'hardwareConcurrency' ) ;
1447is . number ( navigator . hardwareConcurrency , 'hardwareConcurrency' ) ;
1548assert . ok ( navigator . hardwareConcurrency > 0 ) ;
0 commit comments