OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <head> |
| 3 <script src="../resources/js-test.js"></script> |
| 4 <script src="resources/netinfo_common.js"></script> |
| 5 </head> |
| 6 <body> |
| 7 <script> |
| 8 |
| 9 description('Tests using NetInfo from multiple frames.'); |
| 10 |
| 11 shouldBe('typeof window.internals.observeGC', '"function"', |
| 12 'this test requires window.internals'); |
| 13 |
| 14 var childFrame = document.createElement('iframe'); |
| 15 document.body.appendChild(childFrame); |
| 16 |
| 17 var childConnection = childFrame.contentWindow.navigator.connection; |
| 18 |
| 19 if (connection.type != childConnection.type) |
| 20 testFailed("Connection type not the same between main frame and child."); |
| 21 |
| 22 var hasMainFrameEventFired = false; |
| 23 var hasChildFrameEventFired = false; |
| 24 |
| 25 function mainFrameListener() { |
| 26 hasMainFrameEventFired = true; |
| 27 if (connection.type != newConnectionType) |
| 28 testFailed("Event fired event but type not yet changed."); |
| 29 if (!hasChildFrameEventFired && childConnection.type != initialType) |
| 30 testFailed("Child frame connection type changed before firing its event.
"); |
| 31 maybeFinishTest(); |
| 32 } |
| 33 |
| 34 function childFrameListener() { |
| 35 hasChildFrameEventFired = true; |
| 36 if (childConnection.type != newConnectionType) |
| 37 testFailed("Child frame fired event but type not yet changed."); |
| 38 if (!hasMainFrameEventFired && connection.type != initialType) |
| 39 testFailed("Main frame connection type changed before firing its event."
); |
| 40 maybeFinishTest(); |
| 41 } |
| 42 |
| 43 function maybeFinishTest() { |
| 44 if (hasMainFrameEventFired && hasChildFrameEventFired) { |
| 45 if (connection.type != newConnectionType && childConnection.type == newC
onnectionType) |
| 46 testFailed("Connection types did not change in both frames."); |
| 47 finishJSTest(); |
| 48 } |
| 49 } |
| 50 |
| 51 connection.addEventListener('typechange', mainFrameListener); |
| 52 childConnection.addEventListener('typechange', childFrameListener); |
| 53 |
| 54 internals.setNetworkConnectionInfo(newConnectionType); |
| 55 |
| 56 </script> |
| 57 </body> |
| 58 </html> |
OLD | NEW |