| Index: LayoutTests/netinfo/multiple-frames.html
|
| diff --git a/LayoutTests/netinfo/multiple-frames.html b/LayoutTests/netinfo/multiple-frames.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3c9ecc97b6f71fd16dcd6aef2e8e7bd06b702628
|
| --- /dev/null
|
| +++ b/LayoutTests/netinfo/multiple-frames.html
|
| @@ -0,0 +1,58 @@
|
| +<!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) {
|
| + if (connection.type != newConnectionType && childConnection.type == newConnectionType)
|
| + testFailed("Connection types did not change in both frames.");
|
| + finishJSTest();
|
| + }
|
| +}
|
| +
|
| +connection.addEventListener('typechange', mainFrameListener);
|
| +childConnection.addEventListener('typechange', childFrameListener);
|
| +
|
| +internals.setNetworkConnectionInfo(newConnectionType);
|
| +
|
| +</script>
|
| +</body>
|
| +</html>
|
|
|