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 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
= "";
25 xhr
.responseType
= type
;
26 xhr
.onreadystatechange = function()
28 if (xhr
.readyState
=== XMLHttpRequest
.DONE
) {
29 if (typeof(callback
) === "function")
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]);
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
)
91 args
.password
= password
;
92 args
.headers
= headers
;
93 args
.withCredentials
= withCredentials
;
94 args
.payload
= payload
;
96 var jsonArgs
= JSON
.stringify(args
).replace(/\"/g, "\\\"");
98 function innerCallback(msg
)
100 if (msg
.messageText
.indexOf("XHR loaded") !== -1)
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",
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";