1 <button onclick=
"testSyncCookiesNoCredentials();">Start
</button>
2 <pre id=
"console"></pre>
4 if (window
.testRunner
) {
5 testRunner
.dumpAsText();
6 testRunner
.waitUntilDone();
7 testRunner
.setCanOpenWindows();
8 testRunner
.setAlwaysAcceptCookies(1);
13 var consoleDiv
= document
.getElementById('console');
14 consoleDiv
.appendChild(document
.createTextNode(message
+ '\n'));
17 function resourceURL(resourceName
)
19 return "http://localhost:8000/xmlhttprequest/resources/" + resourceName
;
22 function clearCookies()
24 var xhr
= new XMLHttpRequest
;
25 xhr
.open("GET", resourceURL("cross-origin-set-cookies.php?clear=1"), false);
26 xhr
.withCredentials
= true;
33 if (window
.testRunner
)
34 testRunner
.notifyDone();
37 function checkForCookie()
39 var xhr
= new XMLHttpRequest
;
40 xhr
.open("GET", resourceURL("cross-origin-check-cookies.php?cookie=WK-xhr-cookie-storage"), false);
41 xhr
.withCredentials
= true;
44 return xhr
.responseText
46 log("FAIL: Got an exception. " + ex
);
50 function testSyncCookiesNoCredentials()
52 log("Cross-origin XMLHttpRequest (sync), testing that cookies are not set when not sending credentials.");
56 var req
= new XMLHttpRequest
;
57 req
.open("GET", resourceURL("cross-origin-set-cookies.php"), false);
58 req
.withCredentials
= false;
60 log("PASS: Finished sync xhr.");
62 var response
= checkForCookie()
63 log(!response
.match(/WK\-xhr\-cookie\-storage: MySpecialValue/) ? "PASS: No cookies set." : ("FAIL: " + response
));
65 testAsyncCookiesNoCredentials();
68 function testAsyncCookiesNoCredentials()
70 log("Cross-origin XMLHttpRequest (async), testing that cookies are not set when not sending credentials.");
74 var req
= new XMLHttpRequest
;
75 req
.open("GET", resourceURL("cross-origin-set-cookies.php"), true);
76 req
.withCredentials
= false;
78 req
.onerror = function() {
79 log("FAIL: Async xhr to set cookies.");
82 req
.onload = function() {
83 log("PASS: Finished async xhr.");
84 var response
= checkForCookie();
85 log(!response
.match(/WK\-xhr\-cookie\-storage: MySpecialValue/) ? "PASS: No cookies set." : ("FAIL: " + response
));
86 testSyncCookiesWithCredentials();
90 function testSyncCookiesWithCredentials()
92 log("Cross-origin XMLHttpRequest (sync), testing that cookies are set when sending credentials.");
96 var req
= new XMLHttpRequest
;
97 req
.open("GET", resourceURL("cross-origin-set-cookies.php"), false);
98 req
.withCredentials
= true;
100 log("PASS: Finished sync xhr.");
102 var response
= checkForCookie();
103 log(response
.match(/WK\-xhr\-cookie\-storage: MySpecialValue/) ? "PASS: Cookie set." : "FAIL: no cookie set.");
108 if (window
.testRunner
)
109 testSyncCookiesNoCredentials();