Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / inspector / network-test.js
1 // This goes before everything else to keep console message line number invariant.
2 var lastXHRIndex = 0;
3 function xhrLoadedCallback()
4 {
5     // We need to make sure the console message text is unique so that we don't end up with repeat count update only.
6     console.log("XHR loaded: " + (++lastXHRIndex));
7 }
8
9 var initialize_NetworkTest = function() {
10
11 InspectorTest.preloadPanel("network");
12
13 InspectorTest.recordNetwork = function()
14 {
15     WebInspector.panels.network._networkLogView._recordButton.toggled = true;
16 }
17
18 InspectorTest.networkRequests = function()
19 {
20     return WebInspector.networkLog.requests.slice();
21 }
22
23 InspectorTest.dumpNetworkRequests = function()
24 {
25     var requests = InspectorTest.networkRequests();
26     requests.sort(function(a, b) {return a.url.localeCompare(b.url);});
27     InspectorTest.addResult("resources count = " + requests.length);
28     for (i = 0; i < requests.length; i++)
29         InspectorTest.addResult(requests[i].url);
30 }
31
32 InspectorTest.resetInspectorResourcesData = function(callback)
33 {
34     InspectorTest.evaluateInPage("resetInspectorResourcesData()", nextStep);
35
36     function nextStep(result)
37     {
38         if (!result) {
39             InspectorTest.addResult("This test can not be run as window.internals is not available.");
40             Inspector.completeTest();
41         } else
42             callback();
43     }
44 }
45
46 InspectorTest.makeSimpleXHR = function(method, url, async, callback)
47 {
48     InspectorTest.makeXHR(method, url, async, undefined, undefined, [], false, undefined, undefined, callback);
49 }
50
51 InspectorTest.makeSimpleXHRWithPayload = function(method, url, async, payload, callback)
52 {
53     InspectorTest.makeXHR(method, url, async, undefined, undefined, [], false, payload, undefined, callback);
54 }
55
56 InspectorTest.makeXHR = function(method, url, async, user, password, headers, withCredentials, payload, type, callback)
57 {
58     var args = {};
59     args.method = method;
60     args.url = url;
61     args.async = async;
62     args.user = user;
63     args.password = password;
64     args.headers = headers;
65     args.withCredentials = withCredentials;
66     args.payload = payload;
67     args.type = type;
68     var jsonArgs = JSON.stringify(args).replace(/\"/g, "\\\"");
69
70     function innerCallback(msg)
71     {
72         if (msg.messageText.indexOf("XHR loaded") !== -1)
73             callback();
74         else
75             InspectorTest.addConsoleSniffer(innerCallback);
76     }
77
78     InspectorTest.addConsoleSniffer(innerCallback);
79     InspectorTest.evaluateInPage("makeXHRForJSONArguments(\"" + jsonArgs + "\")");
80 }
81
82 InspectorTest.HARPropertyFormatters = {
83     bodySize: "formatAsTypeName",
84     compression: "formatAsTypeName",
85     connection: "formatAsTypeName",
86     headers: "formatAsTypeName",
87     headersSize: "formatAsTypeName",
88     id: "formatAsTypeName",
89     onContentLoad: "formatAsTypeName",
90     onLoad: "formatAsTypeName",
91     receive: "formatAsTypeName",
92     startedDateTime: "formatAsRecentTime",
93     time: "formatAsTypeName",
94     timings: "formatAsTypeName",
95     version: "formatAsTypeName",
96     wait: "formatAsTypeName",
97     _error: "skip",
98 };
99
100 // addObject checks own properties only, so make a deep copy rather than use prototype.
101
102 InspectorTest.HARPropertyFormattersWithSize = JSON.parse(JSON.stringify(InspectorTest.HARPropertyFormatters));
103 InspectorTest.HARPropertyFormattersWithSize.size = "formatAsTypeName";
104
105 };
106
107 function makeSimpleXHR(method, url, async, callback)
108 {
109     makeSimpleXHRWithPayload(method, url, async, null, callback);
110 }
111
112 function makeSimpleXHRWithPayload(method, url, async, payload, callback)
113 {
114     makeXHR(method, url, async, undefined, undefined, [], false, payload, callback)
115 }
116
117 function makeXHR(method, url, async, user, password, headers, withCredentials, payload, type, callback)
118 {
119     var xhr = new XMLHttpRequest();
120     xhr.responseType = type;
121     xhr.onreadystatechange = function()
122     {
123         if (xhr.readyState === XMLHttpRequest.DONE) {
124             if (typeof(callback) === "function")
125                 callback();
126         }
127     }
128     xhr.open(method, url, async, user, password);
129     xhr.withCredentials = withCredentials;
130     for (var  i = 0; i < headers.length; ++i)
131         xhr.setRequestHeader(headers[i][0], headers[i][1]);
132     xhr.send(payload);
133 }
134
135 function makeXHRForJSONArguments(jsonArgs)
136 {
137     var args = JSON.parse(jsonArgs);
138     makeXHR(args.method, args.url, args.async, args.user, args.password, args.headers || [], args.withCredentials, args.payload, args.type, xhrLoadedCallback);
139 }
140
141
142 function resetInspectorResourcesData()
143 {
144     if (!window.internals)
145         return false;
146
147     internals.setInspectorResourcesDataSizeLimits(10 * 1000 * 1000, 1000 * 1000);
148     return true;
149 }
150