Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / netinfo / multiple-frames.html
blobf74d953f91163d9aba6805766a14e8e7f409b440
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>
9 description('Tests using NetInfo from multiple frames.');
11 shouldBe('typeof window.internals.observeGC', '"function"',
12 'this test requires window.internals');
14 var childFrame = document.createElement('iframe');
15 document.body.appendChild(childFrame);
17 var childConnection = childFrame.contentWindow.navigator.connection;
19 if (connection.type != childConnection.type)
20 testFailed("Connection type not the same between main frame and child.");
22 var hasMainFrameEventFired = false;
23 var hasChildFrameEventFired = false;
25 function mainFrameListener() {
26 hasMainFrameEventFired = true;
27 if (connection.type != newConnectionType)
28 testFailed("Event fired but type not yet changed.");
29 if (connection.downlinkMax != newDownlinkMax)
30 testFailed("Event fired but downlinkMax not yet changed.");
31 if (!hasChildFrameEventFired && childConnection.type != initialType)
32 testFailed("Child frame connection type changed before firing its event.");
33 maybeFinishTest();
36 function childFrameListener() {
37 hasChildFrameEventFired = true;
38 if (childConnection.type != newConnectionType)
39 testFailed("Child frame fired event but type not yet changed.");
40 if (childConnection.downlinkMax != newDownlinkMax)
41 testFailed("Child frame fired event but downlinkMax not yet changed.");
42 if (!hasMainFrameEventFired && connection.type != initialType)
43 testFailed("Main frame connection type changed before firing its event.");
44 maybeFinishTest();
47 function maybeFinishTest() {
48 if (hasMainFrameEventFired && hasChildFrameEventFired) {
49 finishJSTest();
53 connection.addEventListener('change', mainFrameListener);
54 childConnection.addEventListener('change', childFrameListener);
56 internals.setNetworkConnectionInfo(newConnectionType, newDownlinkMax);
58 </script>
59 </body>
60 </html>