3 <script src=
"inspector-test.js"></script>
4 <script src=
"extensions-test.js"></script>
5 <script type=
"text/javascript">
7 function extension_testUserAgent(nextTest
)
9 const requestsToCheck
= [
10 "extensions-useragent.html",
14 var queuedOutput
= [];
16 function onRequestFinished(request
)
18 var url
= request
.request
.url
.replace(/^.*[/]/, "");
19 if (requestsToCheck
.indexOf(url
) < 0)
22 queuedOutput
.push("user-agent header for " + url
+ ": " + getHeader(request
.request
.headers
, "user-agent"));
23 if (++requestCount
< requestsToCheck
.length
)
25 webInspector
.network
.onRequestFinished
.removeListener(onRequestFinished
);
26 webInspector
.inspectedWindow
.eval("navigator.userAgent", onEval
);
28 function getHeader(headers
, name
)
30 for (var i
= 0; i
< headers
.length
; ++i
) {
31 if (headers
[i
].name
.toLowerCase() === name
)
32 return headers
[i
].value
;
35 function onEval(result
)
37 queuedOutput
.push("navigator.userAgent: " + result
);
38 webInspector
.inspectedWindow
.eval("", cleanUp
);
42 evaluateOnFrontend("InspectorTest.runWhenPageLoads(reply)", onPageLoaded
);
43 webInspector
.inspectedWindow
.reload("");
45 function onPageLoaded()
47 for (var i
= 0; i
< queuedOutput
.length
; ++i
)
48 output(queuedOutput
[i
]);
52 webInspector
.network
.onRequestFinished
.addListener(onRequestFinished
);
53 webInspector
.inspectedWindow
.reload("Mozilla/4.0 (compatible; WebInspector Extension User-Agent override; RSX-11M)");
58 var xhr
= new XMLHttpRequest();
59 xhr
.open("GET", "resources/xhr-exists.html", false);
65 <body onload=
"runTest()">
66 <p>Tests overriding user agent via WebInspector extension API
</p>