| <html> |
| <head> |
| <script src="inspector-test.js"></script> |
| <script src="extensions-test.js"></script> |
| <script type="text/javascript"> |
| |
| function extension_testUserAgent(nextTest) |
| { |
| const requestsToCheck = [ |
| "extensions-useragent.html", |
| "xhr-exists.html" |
| ]; |
| var requestCount = 0; |
| var queuedOutput = []; |
| |
| function onRequestFinished(request) |
| { |
| var url = request.request.url.replace(/^.*[/]/, ""); |
| if (requestsToCheck.indexOf(url) < 0) |
| return; |
| |
| queuedOutput.push("user-agent header for " + url + ": " + getHeader(request.request.headers, "user-agent")); |
| if (++requestCount < requestsToCheck.length) |
| return; |
| webInspector.network.onRequestFinished.removeListener(onRequestFinished); |
| webInspector.inspectedWindow.eval("navigator.userAgent", onEval); |
| } |
| function getHeader(headers, name) |
| { |
| for (var i = 0; i < headers.length; ++i) { |
| if (headers[i].name.toLowerCase() === name) |
| return headers[i].value; |
| } |
| } |
| function onEval(result) |
| { |
| queuedOutput.push("navigator.userAgent: " + result); |
| webInspector.inspectedWindow.eval("", cleanUp); |
| } |
| function cleanUp() |
| { |
| evaluateOnFrontend("InspectorTest.runWhenPageLoads(reply)", onPageLoaded); |
| webInspector.inspectedWindow.reload(""); |
| } |
| function onPageLoaded() |
| { |
| for (var i = 0; i < queuedOutput.length; ++i) |
| output(queuedOutput[i]); |
| nextTest(); |
| } |
| |
| webInspector.network.onRequestFinished.addListener(onRequestFinished); |
| webInspector.inspectedWindow.reload("Mozilla/4.0 (compatible; WebInspector Extension User-Agent override; RSX-11M)"); |
| } |
| |
| (function() |
| { |
| var xhr = new XMLHttpRequest(); |
| xhr.open("GET", "resources/xhr-exists.html", false); |
| xhr.send(null); |
| })(); |
| |
| </script> |
| </head> |
| <body onload="runTest()"> |
| <p>Tests overriding user agent via WebInspector extension API</p> |
| </body> |
| </html> |