Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / cross-origin-cookie-storage.html
blob7e43c5388c765ee59b1a4dd9aba5f071a3e8beaf
1 <button onclick="testSyncCookiesNoCredentials();">Start</button>
2 <pre id="console"></pre>
3 <script>
4 if (window.testRunner) {
5 testRunner.dumpAsText();
6 testRunner.waitUntilDone();
7 testRunner.setCanOpenWindows();
8 testRunner.setAlwaysAcceptCookies(1);
11 function log(message)
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;
27 xhr.send("");
30 function endTesting()
32 clearCookies();
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;
42 try {
43 xhr.send();
44 return xhr.responseText
45 } catch (ex) {
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.");
54 clearCookies();
56 var req = new XMLHttpRequest;
57 req.open("GET", resourceURL("cross-origin-set-cookies.php"), false);
58 req.withCredentials = false;
59 req.send();
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.");
72 clearCookies();
74 var req = new XMLHttpRequest;
75 req.open("GET", resourceURL("cross-origin-set-cookies.php"), true);
76 req.withCredentials = false;
77 req.send();
78 req.onerror = function() {
79 log("FAIL: Async xhr to set cookies.");
80 endTesting();
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.");
94 clearCookies();
96 var req = new XMLHttpRequest;
97 req.open("GET", resourceURL("cross-origin-set-cookies.php"), false);
98 req.withCredentials = true;
99 req.send();
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.");
104 log("DONE");
105 endTesting();
108 if (window.testRunner)
109 testSyncCookiesNoCredentials();
110 </script>