chromium/third_party/blink/web_tests/netinfo/estimate-basic-operation.html

<!DOCTYPE html>
<head>
<script src="../resources/js-test.js"></script>
<script src="resources/netinfo_common.js"></script>
</head>
<body>
<script>
description('Tests the basic operation of NetInfo.');

shouldBe('typeof internals.observeGC', '"function"',
'this test requires window.internals');

shouldBeDefined("navigator.connection");
shouldBeDefined("navigator.connection.type");
shouldBeDefined("navigator.connection.saveData");
shouldBeDefined("navigator.connection.downlinkMax");
shouldBeDefined("navigator.connection.effectiveType");
shouldBeDefined("navigator.connection.rtt");
shouldBeDefined("navigator.connection.downlink");

var typeChangeListener = function(e) {
    shouldBe("typeof connection.type", '"string"');
    shouldBe('connection.type', 'newConnectionType');
    shouldBe('connection.saveData', 'false');
    shouldBe('connection.downlinkMax', 'newDownlinkMax');
    shouldBe('connection.effectiveType', 'newEffectiveType');
    shouldBe('connection.rtt', 'newRtt', false, newRttMaxNoise);
    shouldBe('connection.downlink', 'newDownlinkMax', false, newDownlinkMaxNoise);
    finishJSTest();
}

var changeListener = function(e) {
    shouldBe("typeof connection.type", '"string"');
    shouldBe('connection.type', 'initialType');
    shouldBe('connection.saveData', 'false');
    shouldBe('connection.downlinkMax', 'initialDownlinkMax');
    shouldBe('connection.effectiveType', 'newEffectiveType');
    shouldBe('connection.rtt', 'newRtt', false, newRttMaxNoise);
    shouldBe('connection.downlink', 'newDownlinkMax', false, newDownlinkMaxNoise);
    connection.removeEventListener('change', changeListener);
    connection.addEventListener('typechange', typeChangeListener);
    internals.setNetworkConnectionInfoOverride(isTypeOnline(newConnectionType), newConnectionType, newEffectiveType, newRtt, newDownlinkMax);
}

connection.addEventListener('change', changeListener);
internals.setNetworkConnectionInfoOverride(isTypeOnline(initialType), initialType, newEffectiveType, newRtt, initialDownlinkMax);

</script>
</body>
</html>