Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / inspector / network-test.js
blob3780e5d34522ad7ca658499b9c41c3dc99f86207
1 // This goes before everything else to keep console message line number invariant.
2 var lastXHRIndex = 0;
3 function xhrLoadedCallback()
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));
9 function makeSimpleXHR(method, url, async, callback)
11 makeSimpleXHRWithPayload(method, url, async, null, callback);
14 function makeSimpleXHRWithPayload(method, url, async, payload, callback)
16 makeXHR(method, url, async, undefined, undefined, [], false, payload, callback)
19 function makeXHR(method, url, async, user, password, headers, withCredentials, payload, type, callback)
21 var xhr = new XMLHttpRequest();
22 if (type == undefined)
23 xhr.responseType = "";
24 else
25 xhr.responseType = type;
26 xhr.onreadystatechange = function()
28 if (xhr.readyState === XMLHttpRequest.DONE) {
29 if (typeof(callback) === "function")
30 callback();
33 xhr.open(method, url, async, user, password);
34 xhr.withCredentials = withCredentials;
35 for (var i = 0; i < headers.length; ++i)
36 xhr.setRequestHeader(headers[i][0], headers[i][1]);
37 xhr.send(payload);
40 function makeXHRForJSONArguments(jsonArgs)
42 var args = JSON.parse(jsonArgs);
43 makeXHR(args.method, args.url, args.async, args.user, args.password, args.headers || [], args.withCredentials, args.payload, args.type, xhrLoadedCallback);
46 function makeFetch(url, requestInitializer, callback)
48 fetch(url, requestInitializer).then(callback).catch(callback);
51 var initialize_NetworkTest = function() {
53 InspectorTest.preloadPanel("network");
55 InspectorTest.recordNetwork = function()
57 WebInspector.panels.network._networkLogView.setRecording(true);
60 InspectorTest.networkRequests = function()
62 return WebInspector.NetworkLog.requests();
65 InspectorTest.dumpNetworkRequests = function()
67 var requests = InspectorTest.networkRequests();
68 requests.sort(function(a, b) {return a.url.localeCompare(b.url);});
69 InspectorTest.addResult("resources count = " + requests.length);
70 for (i = 0; i < requests.length; i++)
71 InspectorTest.addResult(requests[i].url);
74 InspectorTest.makeSimpleXHR = function(method, url, async, callback)
76 InspectorTest.makeXHR(method, url, async, undefined, undefined, [], false, undefined, undefined, callback);
79 InspectorTest.makeSimpleXHRWithPayload = function(method, url, async, payload, callback)
81 InspectorTest.makeXHR(method, url, async, undefined, undefined, [], false, payload, undefined, callback);
84 InspectorTest.makeXHR = function(method, url, async, user, password, headers, withCredentials, payload, type, callback)
86 var args = {};
87 args.method = method;
88 args.url = url;
89 args.async = async;
90 args.user = user;
91 args.password = password;
92 args.headers = headers;
93 args.withCredentials = withCredentials;
94 args.payload = payload;
95 args.type = type;
96 var jsonArgs = JSON.stringify(args).replace(/\"/g, "\\\"");
98 function innerCallback(msg)
100 if (msg.messageText.indexOf("XHR loaded") !== -1)
101 callback();
102 else
103 InspectorTest.addConsoleSniffer(innerCallback);
106 InspectorTest.addConsoleSniffer(innerCallback);
107 InspectorTest.evaluateInPage("makeXHRForJSONArguments(\"" + jsonArgs + "\")");
110 InspectorTest.makeFetch = function(url, requestInitializer, callback)
112 InspectorTest.invokePageFunctionAsync("makeFetch", url, requestInitializer, callback);
115 InspectorTest.HARPropertyFormatters = {
116 bodySize: "formatAsTypeName",
117 compression: "formatAsTypeName",
118 connection: "formatAsTypeName",
119 headers: "formatAsTypeName",
120 headersSize: "formatAsTypeName",
121 id: "formatAsTypeName",
122 onContentLoad: "formatAsTypeName",
123 onLoad: "formatAsTypeName",
124 receive: "formatAsTypeName",
125 startedDateTime: "formatAsRecentTime",
126 time: "formatAsTypeName",
127 timings: "formatAsTypeName",
128 version: "formatAsTypeName",
129 wait: "formatAsTypeName",
130 _transferSize: "formatAsTypeName",
131 _error: "skip",
134 // addObject checks own properties only, so make a deep copy rather than use prototype.
135 InspectorTest.HARPropertyFormattersWithSize = JSON.parse(JSON.stringify(InspectorTest.HARPropertyFormatters));
136 InspectorTest.HARPropertyFormattersWithSize.size = "formatAsTypeName";