Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / inspector / network / network-timing.html
1 <html>
2 <head>
3 <script src="../inspector-test.js"></script>
4 <script src="../network-test.js"></script>
5 <script>
6 function loadScripts()
7 {
8     // Wait 100 ms, then serve for 200ms file containing 300ms loop.
9     var script = document.createElement("script");
10     script.setAttribute("src", "resources/resource.php?type=js&wait=100&send=200&jsdelay=300&jscontent=resourceLoaded()");
11     document.head.appendChild(script);
12
13     // Wait 100 ms, then serve for 100ms and call console.log in content.
14     script = document.createElement("script");
15     script.setAttribute("src", "resources/resource.php?type=js&wait=100&send=100&jscontent=resourceLoaded()");
16     document.head.appendChild(script);
17 }
18
19 var loadedResourceCount = 0;
20 function resourceLoaded()
21 {
22     if (++loadedResourceCount === 2)
23         console.log("Done.");
24 }
25
26 function test()
27 {
28     InspectorTest.addConsoleSniffer(step2);
29     InspectorTest.evaluateInPage("loadScripts()");
30
31     function step2()
32     {
33         // inspector-test.js appears in network panel occasionally in Safari on
34         // Mac, so checking two last requests.
35         var timerThreshold = 15; // Windows timer accuracy.
36         var requests = InspectorTest.networkRequests();
37         var requestsCount = requests.length;
38         var request1 = requests[requestsCount - 2];
39         InspectorTest.addResult(request1.url);
40         InspectorTest.assertGreaterOrEqual(request1.latency * 1000, 100 - timerThreshold, "Latency of the first resource");
41         InspectorTest.assertGreaterOrEqual(request1.duration * 1000, 300 - timerThreshold, "Duration of the first resource");
42
43         var request2 = requests[requestsCount - 1];
44         InspectorTest.addResult(request2.url);
45         InspectorTest.assertGreaterOrEqual(request2.latency * 1000, 100 - timerThreshold, "Latency of the second resource");
46         InspectorTest.assertGreaterOrEqual(request2.duration * 1000, 100 - timerThreshold, "Duration of the second resource");
47         InspectorTest.completeTest();
48     }
49 }
50 </script>
51 </head>
52 <body onload="runTest()">
53 <p>Tests network panel timing.</p>
54 </body>
55 </html>