| <!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 saveData attribute in 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"); |
| |
| shouldBe("typeof connection.type", '"string"'); |
| shouldBe('connection.type', 'initialType'); |
| shouldBe('connection.saveData', 'false'); |
| shouldBe('connection.downlinkMax', 'initialDownlinkMax'); |
| shouldBe('connection.effectiveType', 'initialEffectiveType'); |
| shouldBe('connection.rtt', 'newRtt', false, newRttMaxNoise); |
| shouldBe('connection.downlink', 'newDownlink', false, newDownlinkMaxNoise); |
| |
| |
| var changeListener = function(e) { |
| shouldBe("typeof connection.type", '"string"'); |
| shouldBe('connection.type', 'initialType'); |
| shouldBe('connection.saveData', 'true'); |
| shouldBe('connection.downlinkMax', 'initialDownlinkMax'); |
| shouldBe('connection.effectiveType', 'initialEffectiveType'); |
| shouldBe('connection.rtt', 'newRtt', false, newRttMaxNoise); |
| shouldBe('connection.downlink', 'newDownlink', false, newDownlinkMaxNoise); |
| connection.removeEventListener('change', changeListener); |
| internals.setSaveDataEnabled(false); |
| finishJSTest(); |
| } |
| |
| connection.addEventListener('change', changeListener); |
| // Changing saveData should trigger a callback. |
| internals.setSaveDataEnabled(true); |
| |
| </script> |
| </body> |
| </html> |