Upstream version 8.37.180.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / timeline / timeline-network-resource.html
1 <html>
2 <head>
3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../http/tests/inspector/timeline-test.js"></script>
5 <script>
6
7 var scriptUrl = "timeline-network-resource.js";
8
9 function performActions() 
10 {
11     var script = document.createElement("script");
12     script.src = scriptUrl;
13     document.body.appendChild(script);
14 }
15
16 function test()
17 {
18     var requestId;
19     var scriptUrl = "timeline-network-resource.js";
20
21     var model = WebInspector.panels.timeline._model;
22     var presentationModel = InspectorTest.timelinePresentationModel();
23
24     InspectorTest.startTimeline(step1);
25
26     function step1()
27     {
28         InspectorTest.evaluateInPage("performActions()");
29         InspectorTest.addConsoleSniffer(step2);
30     }
31
32     function step2()
33     {
34         InspectorTest.stopTimeline(step3);
35     }
36
37     function step3()
38     {
39         var lastRecordStartTime;
40         function format(record)
41         {
42             if (record.type() === WebInspector.TimelineModel.RecordType.ResourceSendRequest)
43                 printSend(record._record);
44             else if (record.type() === WebInspector.TimelineModel.RecordType.ResourceReceiveResponse)
45                 printReceive(record._record);
46             else if (record.type() === WebInspector.TimelineModel.RecordType.ResourceFinish)
47                 printFinish(record._record);
48
49             if (record.parent && record.parent.type() === WebInspector.TimelineModel.RecordType.Root) {
50                 if (lastRecordStartTime)
51                     InspectorTest.assertGreaterOrEqual(record.startTime(), lastRecordStartTime, "Top level records order violation");
52                 lastRecordStartTime = record.startTime();
53             }
54         }
55         model.forAllRecords(format);
56         InspectorTest.completeTest();
57     }
58
59     function printRecord(record)
60     {
61         InspectorTest.addResult("");
62         InspectorTest.printTimelineRecordProperties(record);
63     }
64
65     function printSend(record)
66     {
67         printRecord(record);
68         requestId = record.data.requestId;
69         if (record.data.url === undefined) 
70             InspectorTest.addResult("* No 'url' property in record");
71         else if (record.data.url.indexOf(scriptUrl) === -1)
72             InspectorTest.addResult("* Didn't find URL: " + scriptUrl);
73     }
74
75     function printReceive(record)
76     {
77         printRecord(record);
78         if (requestId !== record.data.requestId)
79             InspectorTest.addResult("Didn't find matching requestId: " + requestId);
80         if (record.data.statusCode !== 0)
81             InspectorTest.addResult("Response received status: " + record.data.statusCode);
82     }
83
84     function printFinish(record)
85     {
86         printRecord(record);
87         if (requestId !== record.data.requestId)
88             InspectorTest.addResult("Didn't find matching requestId: " + requestId);
89         if (record.data.didFail)
90             InspectorTest.addResult("Request failed.");
91     }
92 }
93
94 </script>
95 </head>
96
97 <body onload="runTest()">
98 <p>
99 Tests the Timeline API instrumentation of a network resource load
100 </p>
101 </body>
102 </html>