<!DOCTYPE html>
<head>
<script src="../resources/js-test.js"></script>
<script src="resources/netinfo_common.js"></script>
</head>
<body>
<script>
description('Tests that all rtt and downlink is exposed correctly.');
if (!window.internals)
log("This test requires window.internals");
var values = [
["slow-2g", 50.0, 2.0, "slow-2g", 50.0, 2.0],
["slow-2g", 40.0, 7.0, "slow-2g", 50.0, 7.0],
["slow-2g", 40.0, 0.0, "slow-2g", 50.0, 0.0],
["slow-2g", 100.0, 0.151, "slow-2g", 100.0, 0.150],
["slow-2g", 40.0, 0.100, "slow-2g", 50.0, 0.100],
["slow-2g", 40.0, 0.153, "slow-2g", 50.0, 0.150],
["4g", 40.0, 0.103, "4g", 50.0, 0.100],
["3g", 90.0, 0.0991, "3g", 100.0, 0.100],
["3g", 10.0, 0.101, "3g", 0.0, 0.100],
];
var count = 0;
connection.addEventListener('change', function(e) {
shouldBe('connection.effectiveType', 'values[count][3]');
// Up to 10% noise may be added to rtt and downlink. Use 11% as the buffer
// below to account for any mismatches due to floating point calculations.
// Add 50 (bucket size used) to account for the cases when the sample may spill
// over to the next bucket due to the added noise of 10%. For example, if sample
// is 300, after adding noise, it may become 330, and after rounding off, it
// would spill over to the next bucket of 350.
shouldBe('connection.rtt', 'values[count][4]', false, values[count][4] * 0.11 + 50);
shouldBe('connection.downlink', 'values[count][5]', false, values[count][5] * 0.11 + 50);
if (++count === values.length)
finishJSTest();
});
for(var i = 0; i < values.length; i++)
internals.setNetworkConnectionInfoOverride(isTypeOnline(initialType), initialType, values[i][0], values[i][1], values[i][2]);
</script>
</body>
</html>