tizen beta release
[framework/web/webkit-efl.git] / LayoutTests / http / tests / websocket / tests / hybi / httponly-cookie.pl
1 #!/usr/bin/perl -wT
2 use strict;
3
4 if ($ENV{"QUERY_STRING"} eq "clear=1") {
5     print "Content-Type: text/plain\r\n";
6     print "Set-Cookie: WK-websocket-test=0; Max-Age=0\r\n";
7     print "Set-Cookie: WK-websocket-test-httponly=0; HttpOnly; Max-Age=0\r\n";
8     print "\r\n";
9     print "Cookies are cleared.";
10     exit;
11 }
12
13 print "Content-Type: text/html\r\n";
14 print "Set-Cookie: WK-websocket-test=1\r\n";
15 print "Set-Cookie: WK-websocket-test-httponly=1; HttpOnly\r\n";
16 print "\r\n";
17 print <<HTML
18 <html>
19 <head>
20 <script src="../../../../js-test-resources/js-test-pre.js"></script>
21 </head>
22 <body>
23 <p>Test WebSocket sends HttpOnly cookies.</p>
24 <p>On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".</p>
25 <div id="console"></div>
26 <script>
27 window.jsTestIsAsync = true;
28 if (window.layoutTestController)
29     layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
30
31 var cookie;
32
33 // Normalize a cookie string
34 function normalizeCookie(cookie)
35 {
36     // Split the cookie string, sort it and then put it back together.
37     return cookie.split('; ').sort().join('; ');
38 }
39
40 function clearCookies()
41 {
42     var xhr = new XMLHttpRequest();
43     xhr.open("GET", "httponly-cookie.pl?clear=1", false);
44     xhr.send(null);
45 }
46
47 var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/echo-cookie");
48 ws.onopen = function() {
49     debug("WebSocket open");
50 };
51 ws.onmessage = function(evt) {
52     cookie = evt.data;
53     ws.close();
54 };
55 ws.onclose = function() {
56     debug("WebSocket closed");
57     cookie = normalizeCookie(cookie);
58     shouldBe("cookie", '"WK-websocket-test-httponly=1; WK-websocket-test=1"');
59     clearCookies();
60     finishJSTest();
61 };
62
63 </script>
64 <script src="../../../../js-test-resources/js-test-post.js"></script>
65 </body>
66 </html>
67 HTML