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.networkRequests = function() {
12 return WebInspector.networkLog.requests.slice();
15 InspectorTest.dumpNetworkRequests = function()
17 var requests = InspectorTest.networkRequests();
18 requests.sort(function(a, b) {return a.url.localeCompare(b.url);});
19 InspectorTest.addResult("resources count = " + requests.length);
20 for (i = 0; i < requests.length; i++)
21 InspectorTest.addResult(requests[i].url);
24 InspectorTest.resetInspectorResourcesData = function(callback)
26 InspectorTest.evaluateInPage("resetInspectorResourcesData()", nextStep);
28 function nextStep(result)
31 InspectorTest.addResult("This test can not be run as window.internals is not available.");
32 Inspector.completeTest();
38 InspectorTest.makeSimpleXHR = function(method, url, async, callback)
40 InspectorTest.makeXHR(method, url, async, undefined, undefined, [], false, undefined, undefined, callback);
43 InspectorTest.makeSimpleXHRWithPayload = function(method, url, async, payload, callback)
45 InspectorTest.makeXHR(method, url, async, undefined, undefined, [], false, payload, undefined, callback);
48 InspectorTest.makeXHR = function(method, url, async, user, password, headers, withCredentials, payload, type, callback)
55 args.password = password;
56 args.headers = headers;
57 args.withCredentials = withCredentials;
58 args.payload = payload;
60 var jsonArgs = JSON.stringify(args).replace(/\"/g, "\\\"");
62 function innerCallback(msg)
64 if (msg.consoleMessage().messageText.indexOf("XHR loaded") !== -1)
67 InspectorTest.addConsoleSniffer(innerCallback);
70 InspectorTest.addConsoleSniffer(innerCallback);
71 InspectorTest.evaluateInPage("makeXHRForJSONArguments(\"" + jsonArgs + "\")");
76 function makeSimpleXHR(method, url, async, callback)
78 makeSimpleXHRWithPayload(method, url, async, null, callback);
81 function makeSimpleXHRWithPayload(method, url, async, payload, callback)
83 makeXHR(method, url, async, undefined, undefined, [], false, payload, callback)
86 function makeXHR(method, url, async, user, password, headers, withCredentials, payload, type, callback)
88 var xhr = new XMLHttpRequest();
89 xhr.responseType = type;
90 xhr.onreadystatechange = function()
92 if (xhr.readyState === XMLHttpRequest.DONE) {
93 if (typeof(callback) === "function")
97 xhr.open(method, url, async, user, password);
98 xhr.withCredentials = withCredentials;
99 for (var i = 0; i < headers.length; ++i)
100 xhr.setRequestHeader(headers[i][0], headers[i][1]);
104 function makeXHRForJSONArguments(jsonArgs)
106 var args = JSON.parse(jsonArgs);
107 makeXHR(args.method, args.url, args.async, args.user, args.password, args.headers || [], args.withCredentials, args.payload, args.type, xhrLoadedCallback);
111 function resetInspectorResourcesData()
113 if (!window.internals)
116 internals.setInspectorResourcesDataSizeLimits(10 * 1000 * 1000, 1000 * 1000);