| <!DOCTYPE html> |
| <head> |
| <script src="../resources/js-test.js"></script> |
| <script src="resources/netinfo_common.js"></script> |
| </head> |
| <body> |
| <script> |
| |
| description('Tests using NetInfo from multiple frames.'); |
| |
| shouldBe('typeof window.internals.observeGC', '"function"', |
| 'this test requires window.internals'); |
| |
| var childFrame = document.createElement('iframe'); |
| document.body.appendChild(childFrame); |
| |
| var childConnection = childFrame.contentWindow.navigator.connection; |
| |
| if (connection.type != childConnection.type) |
| testFailed("Connection type not the same between main frame and child."); |
| |
| var hasMainFrameEventFired = false; |
| var hasChildFrameEventFired = false; |
| |
| function mainFrameListener() { |
| hasMainFrameEventFired = true; |
| if (connection.type != newConnectionType) |
| testFailed("Event fired event but type not yet changed."); |
| if (!hasChildFrameEventFired && childConnection.type != initialType) |
| testFailed("Child frame connection type changed before firing its event."); |
| maybeFinishTest(); |
| } |
| |
| function childFrameListener() { |
| hasChildFrameEventFired = true; |
| if (childConnection.type != newConnectionType) |
| testFailed("Child frame fired event but type not yet changed."); |
| if (!hasMainFrameEventFired && connection.type != initialType) |
| testFailed("Main frame connection type changed before firing its event."); |
| maybeFinishTest(); |
| } |
| |
| function maybeFinishTest() { |
| if (hasMainFrameEventFired && hasChildFrameEventFired) { |
| finishJSTest(); |
| } |
| } |
| |
| connection.addEventListener('typechange', mainFrameListener); |
| childConnection.addEventListener('typechange', childFrameListener); |
| |
| internals.setNetworkConnectionInfo(newConnectionType); |
| |
| </script> |
| </body> |
| </html> |