Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / inspector / websocket / websocket-handshake.html
1 <html>
2 <head>
3 <script src="/inspector/inspector-test.js"></script>
4 <script src="/js-test-resources/js-test.js"></script>
5 <script>
6 var ws;
7 function sendMessages() {
8     ws = new WebSocket('ws://localhost:8880/duplicated-headers');
9     ws.onopen = function() {
10         debug('onopen');
11     };
12 }
13
14 function test() {
15     function outputHeaders(name, headers) {
16         var headersToOutput = [];
17         for (var i = 0; i < headers.length; ++i) {
18             if (headers[i].name === 'Sec-WebSocket-Key' ||
19                 headers[i].name == 'Sec-WebSocket-Accept' ||
20                 headers[i].name == 'User-Agent') {
21                 // We hide the header value of these headers because
22                 // they can be flaky or platform dependent.
23                 headersToOutput.push({name: headers[i].name, value: '***'});
24             } else {
25                 headersToOutput.push(headers[i]);
26             }
27         }
28         headersToOutput.sort(function(x, y) {
29             function compare(x, y) {
30                 if (x < y) {
31                     return -1;
32                 } else if (x === y) {
33                     return 0;
34                 } else {
35                     return 1;
36                 }
37             }
38             return x.name === y.name ? compare(x.value, y.value) : compare(x.name, y.name);
39         });
40         console.log(name);
41         for (var i = 0; i < headersToOutput.length; ++i) {
42             console.log('    ' + headersToOutput[i].name + ': ' + headersToOutput[i].value);
43         }
44     }
45     function onRequest(event) {
46         if (event.data.statusCode === 101) {
47             console.log('requestMethod: ' + event.data.requestMethod);
48             outputHeaders('requestHeaders', event.data.requestHeaders());
49             console.log('statusCode: ' + event.data.statusCode);
50             console.log('statusText: ' + event.data.statusText);
51             outputHeaders('responseHeaders', event.data.responseHeaders);
52             InspectorTest.completeTest();
53         }
54     }
55     console.log(WebInspector.Network);
56     WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestUpdated, onRequest);
57     InspectorTest.evaluateInPage('sendMessages()');
58 }
59 </script>
60 </head>
61 <body onload="runTest()">
62 <p>Tests that WebSocket handshake information is passed to Web Inspector.</p>
63 </body>
64 </html>