4 if ($ENV{"QUERY_STRING"} eq "clear=1") {
5 print "Content-Type: text/plain\r\n",
6 "Set-Cookie: WK-websocket-test=0; Path=/; Max-Age=0\r\n",
7 "Set-Cookie: WK-websocket-test-httponly=0; Path=/; HttpOnly; Max-Age=0\r\n",
9 "Cookies are cleared.";
13 print "Content-Type: text/html\r\n",
14 # The "Path" attribute is set to "/" so that the WebSocket created below
15 # will receive these cookies.
16 "Set-Cookie: WK-websocket-test=1; Path=/\r\n",
17 "Set-Cookie: WK-websocket-test-httponly=1; Path=/; HttpOnly\r\n",
21 <script src="/js-test-resources/js-test.js"></script>
22 <script src="resources/get-request-header.js"></script>
24 description('Test that WebSocket sends HttpOnly cookies.');
26 window.jsTestIsAsync = true;
28 // Normalize a cookie string
29 function normalizeCookie(cookie)
31 // Split the cookie string, sort it and then put it back together.
32 return cookie.split('; ').sort().join('; ');
35 function clearCookies()
37 return new Promise(function(resolve, reject)
39 var xhr = new XMLHttpRequest();
40 xhr.open("GET", "httponly-cookie.pl?clear=1");
41 xhr.onreadystatechange = function()
43 if (xhr.readyState == 4) {
52 connectAndGetRequestHeader('cookie').then(function(value)
55 cookie = normalizeCookie(cookie);
56 shouldBeEqualToString('cookie', 'WK-websocket-test-httponly=1; WK-websocket-test=1');
57 clearCookies().then(finishJSTest);
60 setTimeout(finishJSTest, 1000);