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.dumpNetworkRequests = function()
13 var requests = WebInspector.inspectorView.panel("network").requests.slice();
14 requests.sort(function(a, b) {return a.url.localeCompare(b.url);});
15 InspectorTest.addResult("resources count = " + requests.length);
16 for (i = 0; i < requests.length; i++)
17 InspectorTest.addResult(requests[i].url);
20 InspectorTest.resetInspectorResourcesData = function(callback)
22 InspectorTest.evaluateInPage("resetInspectorResourcesData()", nextStep);
24 function nextStep(result)
27 InspectorTest.addResult("This test can not be run as window.internals is not available.");
28 Inspector.completeTest();
34 InspectorTest.makeSimpleXHR = function(method, url, async, callback)
36 InspectorTest.makeXHR(method, url, async, undefined, undefined, [], false, undefined, undefined, callback);
39 InspectorTest.makeSimpleXHRWithPayload = function(method, url, async, payload, callback)
41 InspectorTest.makeXHR(method, url, async, undefined, undefined, [], false, payload, undefined, callback);
44 InspectorTest.makeXHR = function(method, url, async, user, password, headers, withCredentials, payload, type, callback)
51 args.password = password;
52 args.headers = headers;
53 args.withCredentials = withCredentials;
54 args.payload = payload;
56 var jsonArgs = JSON.stringify(args).replace(/\"/g, "\\\"");
58 function innerCallback(msg)
60 if (msg.consoleMessage().messageText.indexOf("XHR loaded") !== -1)
63 InspectorTest.addConsoleSniffer(innerCallback);
66 InspectorTest.addConsoleSniffer(innerCallback);
67 InspectorTest.evaluateInPage("makeXHRForJSONArguments(\"" + jsonArgs + "\")");
72 function makeSimpleXHR(method, url, async, callback)
74 makeSimpleXHRWithPayload(method, url, async, null, callback);
77 function makeSimpleXHRWithPayload(method, url, async, payload, callback)
79 makeXHR(method, url, async, undefined, undefined, [], false, payload, callback)
82 function makeXHR(method, url, async, user, password, headers, withCredentials, payload, type, callback)
84 var xhr = new XMLHttpRequest();
85 xhr.responseType = type;
86 xhr.onreadystatechange = function()
88 if (xhr.readyState === XMLHttpRequest.DONE) {
89 if (typeof(callback) === "function")
93 xhr.open(method, url, async, user, password);
94 xhr.withCredentials = withCredentials;
95 for (var i = 0; i < headers.length; ++i)
96 xhr.setRequestHeader(headers[i][0], headers[i][1]);
100 function makeXHRForJSONArguments(jsonArgs)
102 var args = JSON.parse(jsonArgs);
103 makeXHR(args.method, args.url, args.async, args.user, args.password, args.headers || [], args.withCredentials, args.payload, args.type, xhrLoadedCallback);
107 function resetInspectorResourcesData()
109 if (!window.internals)
112 internals.setInspectorResourcesDataSizeLimits(10 * 1000 * 1000, 1000 * 1000);