3 <script src=
"../resources/js-test.js"></script>
4 <script src=
"resources/netinfo_common.js"></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.");
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.");
47 function maybeFinishTest() {
48 if (hasMainFrameEventFired
&& hasChildFrameEventFired
) {
53 connection
.addEventListener('change', mainFrameListener
);
54 childConnection
.addEventListener('change', childFrameListener
);
56 internals
.setNetworkConnectionInfo(newConnectionType
, newDownlinkMax
);