1 // This goes before everything else to keep console message line number invariant.
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 var initialize_NetworkTest = function() {
11 InspectorTest.preloadPanel("network");
13 InspectorTest.recordNetwork = function()
15 WebInspector.panels.network._networkLogView._recordButton.toggled = true;
18 InspectorTest.networkRequests = function()
20 return WebInspector.networkLog.requests.slice();
23 InspectorTest.dumpNetworkRequests = function()
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);
32 InspectorTest.resetInspectorResourcesData = function(callback)
34 InspectorTest.evaluateInPage("resetInspectorResourcesData()", nextStep);
36 function nextStep(result)
39 InspectorTest.addResult("This test can not be run as window.internals is not available.");
40 Inspector.completeTest();
46 InspectorTest.makeSimpleXHR = function(method, url, async, callback)
48 InspectorTest.makeXHR(method, url, async, undefined, undefined, [], false, undefined, undefined, callback);
51 InspectorTest.makeSimpleXHRWithPayload = function(method, url, async, payload, callback)
53 InspectorTest.makeXHR(method, url, async, undefined, undefined, [], false, payload, undefined, callback);
56 InspectorTest.makeXHR = function(method, url, async, user, password, headers, withCredentials, payload, type, callback)
63 args.password = password;
64 args.headers = headers;
65 args.withCredentials = withCredentials;
66 args.payload = payload;
68 var jsonArgs = JSON.stringify(args).replace(/\"/g, "\\\"");
70 function innerCallback(msg)
72 if (msg.messageText.indexOf("XHR loaded") !== -1)
75 InspectorTest.addConsoleSniffer(innerCallback);
78 InspectorTest.addConsoleSniffer(innerCallback);
79 InspectorTest.evaluateInPage("makeXHRForJSONArguments(\"" + jsonArgs + "\")");
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",
100 // addObject checks own properties only, so make a deep copy rather than use prototype.
102 InspectorTest.HARPropertyFormattersWithSize = JSON.parse(JSON.stringify(InspectorTest.HARPropertyFormatters));
103 InspectorTest.HARPropertyFormattersWithSize.size = "formatAsTypeName";
107 function makeSimpleXHR(method, url, async, callback)
109 makeSimpleXHRWithPayload(method, url, async, null, callback);
112 function makeSimpleXHRWithPayload(method, url, async, payload, callback)
114 makeXHR(method, url, async, undefined, undefined, [], false, payload, callback)
117 function makeXHR(method, url, async, user, password, headers, withCredentials, payload, type, callback)
119 var xhr = new XMLHttpRequest();
120 xhr.responseType = type;
121 xhr.onreadystatechange = function()
123 if (xhr.readyState === XMLHttpRequest.DONE) {
124 if (typeof(callback) === "function")
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]);
135 function makeXHRForJSONArguments(jsonArgs)
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);
142 function resetInspectorResourcesData()
144 if (!window.internals)
147 internals.setInspectorResourcesDataSizeLimits(10 * 1000 * 1000, 1000 * 1000);