| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <head> | 2 <head> |
| 3 <script src="../resources/js-test.js"></script> | 3 <script src="../resources/js-test.js"></script> |
| 4 <script src="resources/netinfo_common.js"></script> | 4 <script src="resources/netinfo_common.js"></script> |
| 5 </head> | 5 </head> |
| 6 <body> | 6 <body> |
| 7 <script> | 7 <script> |
| 8 | 8 |
| 9 description('Tests that web-workers have access to NetInfo.'); | 9 description('Tests that web-workers have access to NetInfo.'); |
| 10 | 10 |
| 11 shouldBe('typeof window.internals.observeGC', '"function"', | 11 shouldBe('typeof window.internals.observeGC', '"function"', |
| 12 'this test requires window.internals'); | 12 'this test requires window.internals'); |
| 13 | 13 |
| 14 var worker = new Worker("resources/web-worker.js"); | 14 var worker = new Worker("resources/web-worker.js"); |
| 15 | 15 |
| 16 var msg_count = 0; | 16 var msg_count = 0; |
| 17 | 17 |
| 18 worker.addEventListener('message', function(e) { | 18 worker.addEventListener('message', function(e) { |
| 19 if (msg_count == 0) { | 19 if (msg_count == 0) { |
| 20 if (e.data != connection.type) { | 20 if (e.data != connection.type + ',' + connection.downlinkMax) { |
| 21 testFailed("Worker type disagrees with main frame."); | 21 testFailed("Worker type disagrees with main frame."); |
| 22 } | 22 } |
| 23 internals.setNetworkConnectionInfo(newConnectionType); | 23 internals.setNetworkConnectionInfo(newConnectionType, newDownlinkMax); |
| 24 } else if (msg_count == 1) { | 24 } else if (msg_count == 1) { |
| 25 if (e.data != newConnectionType) | 25 if (e.data != newConnectionType + ',' + newDownlinkMax) |
| 26 testFailed("Worker switched to wrong connection type."); | 26 testFailed("Worker switched to wrong connection type."); |
| 27 internals.setNetworkConnectionInfo(initialType); | 27 internals.setNetworkConnectionInfo(initialType, initialDownlinkMax); |
| 28 } else if (msg_count == 2) { | 28 } else if (msg_count == 2) { |
| 29 if (e.data != initialType) | 29 if (e.data != initialType + ',' + initialDownlinkMax) |
| 30 testFailed("Worker did not revert back to initial type."); | 30 testFailed("Worker did not revert back to initial type."); |
| 31 finishJSTest(); | 31 finishJSTest(); |
| 32 } | 32 } |
| 33 msg_count += 1; | 33 msg_count += 1; |
| 34 }); | 34 }); |
| 35 | 35 |
| 36 worker.postMessage('kickoff'); | 36 worker.postMessage('kickoff'); |
| 37 </script> | 37 </script> |
| 38 </body> | 38 </body> |
| 39 </html> | 39 </html> |
| OLD | NEW |