netinfo-basics.html (2097B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>NetInfo basic functionality</title> 4 <link rel="help" href="https://wicg.github.io/netinfo/"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 8 <script> 9 test(function() { 10 assert_in_array(navigator.connection.type, ["bluetooth", "cellular", 11 "ethernet", "mixed", "none", "other", "unknown", "wifi", "wimax"], 'type is unexpected'); 12 }, "type attribute"); 13 14 test(function() { 15 assert_in_array(navigator.connection.saveData, [false, true], 'saveData is unexpected'); 16 }, "saveData attribute"); 17 18 test(function() { 19 assert_greater_than_equal(navigator.connection.downlinkMax, 0); 20 }, "downlinkMax attribute"); 21 22 test(function() { 23 assert_in_array(navigator.connection.effectiveType, ["slow-2g", "2g", 24 "3g", "4g"], 'effectiveType is unexpected'); 25 }, "effectiveType attribute"); 26 27 test(function() { 28 var rtt = navigator.connection.rtt; 29 assert_greater_than_equal(rtt, 0); 30 assert_less_than_equal(rtt, 3000); 31 assert_equals(rtt % 50, 0, 'rtt must be a multiple of 50 msec'); 32 }, "rtt attribute"); 33 34 test(function() { 35 var downlinkKbps = navigator.connection.downlink * 1000; 36 assert_greater_than_equal(downlinkKbps, 0); 37 assert_less_than_equal(downlinkKbps, 10000); 38 39 // Verify that downlinkKbps is a multiple of 50. 40 var quotient = parseInt(downlinkKbps / 50, 10); 41 // mod is the remainder left after dividing downlinkKbps by 50 while 42 // restricting the quotient to an integer. For example, if downlinkKbps is 43 // 1050, then mod will be 0. If downlinkKpbps is 1030, mod will be 30. 44 var mod = downlinkKbps - 50 * quotient; 45 assert_less_than_equal(0.0, mod, 'mod outside the range'); 46 assert_greater_than(50.0, mod, 'mod outside the range'); 47 // It is possible that mod is not exactly 0 because of floating point 48 // computations. e.g., downlinkKbps may be 99.999999, in which case mod 49 // will be 49.999999. 50 assert_true(mod < 1e-5 || (50-mod) < 1e-5, 'downlink must be a multiple of 50 kbps'); 51 }, "downlink attribute"); 52 </script>