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..2935952f27db209d5a27df74ffbd14603600082b |
--- /dev/null |
+++ b/LayoutTests/netinfo/multiple-frames.html |
@@ -0,0 +1,54 @@ |
+<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.'); |
+ |
+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> |