5 This test shows that cross-site documents are blocked by SiteIsolationPolicy
6 even if the Same Origin Policy is turned off in the renderer. The Same Origin
7 Policy can be circumvented when the renderer is compromised, but we have
8 SiteIsolationPolicy that blocks cross-site documents at the IPC layer. For now
9 cross-site document blocking by SiteIsolationPolicy is done in the renderer, but
10 our ultimate plan is to do that in the browser process.
14 var pathPrefix
= "http://bar.com/files/site_isolation/";
16 // We only block cross-site documents with a blacklisted mime type(text/html,
17 // text/xml, application/json), that are correctly sniffed as the content type
18 // that they claim to be. We also block text/plain documents when their body
19 // looks like one of the blacklisted content types.
21 var blockedResourceUrls
= ['valid.html', 'comment_valid.html', 'valid.xml',
22 'valid.json', 'html.txt', 'xml.txt', 'json.txt'];
24 var nonBlockedResourceUrls
= ['js.html', 'comment_js.html', 'js.xml', 'js.json',
25 'js.txt', 'img.html', 'img.xml', 'img.json', 'img.txt', 'comment_js.html'];
27 var resourceUrls
= blockedResourceUrls
.concat(nonBlockedResourceUrls
);
30 function sendRequest(resourceUrl
) {
31 var xhr
= new XMLHttpRequest();
32 xhr
.onreadystatechange = function() {
33 if (xhr
.readyState
== 4) {
35 if ((blockedResourceUrls
.indexOf(resourceUrl
) != -1 &&
36 xhr
.responseText
!= " ") ||
37 (nonBlockedResourceUrls
.indexOf(resourceUrl
) != -1 &&
38 xhr
.responseText
== " ")) {
39 // Test failed. Either a resource that should have been blocked is not
40 // blocked, or a resource that should have not been blocked is blocked.
41 domAutomationController
.setAutomationId(0);
42 domAutomationController
.send(0);
43 if (blockedResourceUrls
.indexOf(resourceUrl
) != -1) {
44 prefix
= "[ERROR:resource to be blocked wasn't blocked]";
46 prefix
= "[ERROR:resource to be unblocked was blocked]";
49 document
.getElementById("response_body").value
+=
50 ("\n" + prefix
+ "response to " + resourceUrl
+ "(" +
51 xhr
.getResponseHeader("content-type") + ") " +
52 (xhr
.responseText
== " " ? "blocked" : "not-blocked"));
56 xhr
.open('GET', pathPrefix
+ resourceUrl
);
62 if (cnt
< resourceUrls
.length
) {
63 sendRequest(resourceUrls
[cnt
]);
66 // All the test cases are successfully passed.
67 domAutomationController
.setAutomationId(0);
68 domAutomationController
.send(1);
72 window
.onload = function() {
73 // The call to pushState with another domain will succeed, since the
74 // test uses --disable-web-security.
75 history
.pushState('', '', 'http://bar.com/files/main.html');
79 <textarea rows=
20 cols=
50 id='response_body'
></textarea>