Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / access-control-preflight-request-must-not-contain-cookie.html
blobd1be954674d558e5919b5582ce54365eb894816c
1 <html>
2 <head>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script>
5 <script>
6 var t = async_test("Preflight request must not contain any cookie header");
7 var runTest = t.step_func(function()
9 var resolveSetCookiePromise = null;
10 var setCookiePromise = new Promise(function(resolve, reject)
12 resolveSetCookiePromise = resolve;
13 });
15 var resolveClearCookiesPromise = null;
16 var clearCookiesPromise = new Promise(function(resolve, reject)
18 resolveClearCookiesPromise = resolve;
19 });
21 var cookieSet = false;
23 window.onmessage = t.step_func(function(evt)
25 assert_equals(evt.data, "done");
27 if (!cookieSet) {
28 resolveSetCookiePromise();
29 cookieSet = true;
30 } else {
31 resolveClearCookiesPromise();
33 });
35 // Set a cookie for localhost:8000.
36 window.frames[0].postMessage("sendXHR setFooCookie", "*");
38 setCookiePromise.then(t.step_func(function()
40 var xhr = new XMLHttpRequest;
41 xhr.open("GET", "http://localhost:8000/xmlhttprequest/resources/access-control-preflight-request-must-not-contain-cookie.php");
42 xhr.setRequestHeader("X-Proprietary-Header", "foo")
43 xhr.withCredentials = true;
44 xhr.onerror = t.step_func(function (e) {
45 assert_unreached(e);
46 });
47 var doneXHRPromise = new Promise(function(resolve, reject)
49 xhr.onreadystatechange = t.step_func(function () {
50 if (xhr.readyState != xhr.DONE)
51 return;
52 assert_equals(xhr.status, 200);
53 assert_equals(xhr.responseText, "awesomevalue");
54 resolve();
55 });
56 });
57 xhr.send();
58 return doneXHRPromise;
59 })).then(t.step_func(function()
61 // Clean up all cookies for localhost:8000.
62 window.frames[0].postMessage("resetCookiesAndNotifyDone", "*");
63 return resolveClearCookiesPromise;
64 })).then(t.step_func(function()
66 t.done();
67 })).catch(t.step_func(function(e)
69 assert_unreached(e);
70 }));
71 });
72 </script>
73 </head>
74 <body onload="runTest()">
75 <iframe src="http://localhost:8000/cookies/resources/third-party-cookie-relaxing-iframe.html"></iframe>
76 </body>
77 </html>