OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <head> | 2 <head> |
3 <script src="../resources/js-test.js"></script> | 3 <script src="../resources/js-test.js"></script> |
4 <script src="resources/netinfo_common.js"></script> | 4 <script src="resources/netinfo_common.js"></script> |
5 </head> | 5 </head> |
6 <body> | 6 <body> |
7 <script> | 7 <script> |
8 | 8 |
9 description('Tests using NetInfo from multiple frames.'); | 9 description('Tests using NetInfo from multiple frames.'); |
10 | 10 |
11 shouldBe('typeof window.internals.observeGC', '"function"', | 11 shouldBe('typeof window.internals.observeGC', '"function"', |
12 'this test requires window.internals'); | 12 'this test requires window.internals'); |
13 | 13 |
14 var childFrame = document.createElement('iframe'); | 14 var childFrame = document.createElement('iframe'); |
15 document.body.appendChild(childFrame); | 15 document.body.appendChild(childFrame); |
16 | 16 |
17 var childConnection = childFrame.contentWindow.navigator.connection; | 17 var childConnection = childFrame.contentWindow.navigator.connection; |
18 | 18 |
19 if (connection.type != childConnection.type) | 19 if (connection.type != childConnection.type) |
20 testFailed("Connection type not the same between main frame and child."); | 20 testFailed("Connection type not the same between main frame and child."); |
21 | 21 |
22 var hasMainFrameEventFired = false; | 22 var hasMainFrameEventFired = false; |
23 var hasChildFrameEventFired = false; | 23 var hasChildFrameEventFired = false; |
24 | 24 |
25 function mainFrameListener() { | 25 function mainFrameListener() { |
26 hasMainFrameEventFired = true; | 26 hasMainFrameEventFired = true; |
27 if (connection.type != newConnectionType) | 27 if (connection.type != newConnectionType) |
28 testFailed("Event fired event but type not yet changed."); | 28 testFailed("Event fired but type not yet changed."); |
| 29 if (connection.downlinkMax != newDownlinkMax) |
| 30 testFailed("Event fired but downlinkMax not yet changed."); |
29 if (!hasChildFrameEventFired && childConnection.type != initialType) | 31 if (!hasChildFrameEventFired && childConnection.type != initialType) |
30 testFailed("Child frame connection type changed before firing its event.
"); | 32 testFailed("Child frame connection type changed before firing its event.
"); |
31 maybeFinishTest(); | 33 maybeFinishTest(); |
32 } | 34 } |
33 | 35 |
34 function childFrameListener() { | 36 function childFrameListener() { |
35 hasChildFrameEventFired = true; | 37 hasChildFrameEventFired = true; |
36 if (childConnection.type != newConnectionType) | 38 if (childConnection.type != newConnectionType) |
37 testFailed("Child frame fired event but type not yet changed."); | 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."); |
38 if (!hasMainFrameEventFired && connection.type != initialType) | 42 if (!hasMainFrameEventFired && connection.type != initialType) |
39 testFailed("Main frame connection type changed before firing its event."
); | 43 testFailed("Main frame connection type changed before firing its event."
); |
40 maybeFinishTest(); | 44 maybeFinishTest(); |
41 } | 45 } |
42 | 46 |
43 function maybeFinishTest() { | 47 function maybeFinishTest() { |
44 if (hasMainFrameEventFired && hasChildFrameEventFired) { | 48 if (hasMainFrameEventFired && hasChildFrameEventFired) { |
45 finishJSTest(); | 49 finishJSTest(); |
46 } | 50 } |
47 } | 51 } |
48 | 52 |
49 connection.addEventListener('typechange', mainFrameListener); | 53 connection.addEventListener('change', mainFrameListener); |
50 childConnection.addEventListener('typechange', childFrameListener); | 54 childConnection.addEventListener('change', childFrameListener); |
51 | 55 |
52 internals.setNetworkConnectionInfo(newConnectionType); | 56 internals.setNetworkConnectionInfo(newConnectionType, newDownlinkMax); |
53 | 57 |
54 </script> | 58 </script> |
55 </body> | 59 </body> |
56 </html> | 60 </html> |
OLD | NEW |