Improve test cases for network information APIs
[WebKit-https.git] / LayoutTests / networkinformation / script-tests / multiple-frames.js
1 description('Tests using NetworkInfo from multiple frames.');
2
3 var bandwidth = 10;
4 var metered = false;
5
6 var connection = navigator.webkitConnection;
7
8 function checkNetworkInformation() {
9     shouldBe("typeof connection.bandwidth", '"number"');
10     shouldBe("typeof connection.metered", '"boolean"');
11 }
12
13 function checkChildNetworkInformation() {
14     shouldBe("typeof connection.bandwidth", '"number"');
15     shouldBe("typeof connection.metered", '"boolean"');
16 }
17
18 var hasMainFrameEventFired = false;
19 function mainFrameListener() {
20     hasMainFrameEventFired = true;
21     maybeFinishTest();
22 }
23
24 var hasChildFrameEventFired = false;
25 function childFrameListener() {
26     hasChildFrameEventFired = true;
27     maybeFinishTest();
28 }
29
30 function maybeFinishTest() {
31     if (hasMainFrameEventFired && hasChildFrameEventFired) {
32         checkNetworkInformation();
33         checkChildNetworkInformation();
34         finishJSTest();
35     }
36 }
37
38 var childFrame = document.createElement('iframe');
39 document.body.appendChild(childFrame);
40 var childConnection = childFrame.contentWindow.navigator.webkitConnection
41 childConnection.addEventListener('webkitnetworkinfochange', childFrameListener);
42 connection.addEventListener('webkitnetworkinfochange', mainFrameListener);
43
44 internals.setNetworkInformation(document, 'webkitnetworkinfochange', bandwidth, metered);
45 window.jsTestIsAsync = true;