set-from-wss.https.sub.html (1635B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset=utf-8> 5 <title>Set 'secure' cookie from `Set-Cookie` HTTP header on a secure WebSocket</title> 6 <meta name=help href="https://tools.ietf.org/html/draft-west-leave-secure-cookies-alone"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="/cookies/resources/testharness-helpers.js"></script> 10 </head> 11 <body> 12 <div id=log></div> 13 <script> 14 function clearKnownCookie() { 15 document.cookie = "ws_test_secure_from_secure=0; Secure; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/"; 16 } 17 18 async_test(function (t) { 19 t.add_cleanup(clearKnownCookie); 20 assert_equals(document.cookie.match(/ws_test_secure_from_secure=/), null); 21 22 clearKnownCookie(); 23 var ws = new WebSocket("wss://{{host}}:{{ports[wss][0]}}/set-cookie-secure?secure_from_secure"); 24 ws.onclose = t.step_func_done(function () { 25 assert_unreached("'close' should not fire before 'open'."); 26 }); 27 ws.onopen = t.step_func(function (e) { 28 ws.onclose = null; 29 ws.close(); 30 assert_regexp_match(document.cookie, /ws_test_secure_from_secure=test/); 31 var ws2 = new WebSocket("wss://{{host}}:{{ports[wss][0]}}/echo-cookie"); 32 ws2.onclose = t.step_func_done(function () { 33 assert_unreached("'close' should not fire before 'open'."); 34 }); 35 ws2.onmessage = t.step_func_done(function (e) { 36 ws2.onclose = null; 37 ws2.close(); 38 assert_regexp_match(e.data, /ws_test_secure_from_secure=test/); 39 }); 40 }); 41 }, "'secure' cookie not sent in HTTP request"); 42 </script> 43 </body> 44 </html>