| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import base64 | 5 import base64 |
| 6 import BaseHTTPServer | 6 import BaseHTTPServer |
| 7 import hashlib | 7 import hashlib |
| 8 import socket | 8 import socket |
| 9 import threading | 9 import threading |
| 10 import unittest | 10 import unittest |
| 11 | 11 |
| 12 | |
| 13 from telemetry.core.backends.chrome import websocket | 12 from telemetry.core.backends.chrome import websocket |
| 14 | 13 |
| 15 | 14 |
| 16 # Minimal handler for a local websocket server. | 15 # Minimal handler for a local websocket server. |
| 17 class _FakeWebSocketHandler(BaseHTTPServer.BaseHTTPRequestHandler): | 16 class _FakeWebSocketHandler(BaseHTTPServer.BaseHTTPRequestHandler): |
| 18 def do_GET(self): | 17 def do_GET(self): |
| 19 key = self.headers.getheader('Sec-WebSocket-Key') | 18 key = self.headers.getheader('Sec-WebSocket-Key') |
| 20 | 19 |
| 21 value = key + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11' | 20 value = key + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11' |
| 22 hashed = base64.encodestring(hashlib.sha1(value).digest()).strip().lower() | 21 hashed = base64.encodestring(hashlib.sha1(value).digest()).strip().lower() |
| (...skipping 23 matching lines...) Expand all Loading... |
| 46 ws.sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR), 0) | 45 ws.sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR), 0) |
| 47 | 46 |
| 48 threading.Thread(target=httpd.handle_request).start() | 47 threading.Thread(target=httpd.handle_request).start() |
| 49 ws = websocket.create_connection( | 48 ws = websocket.create_connection( |
| 50 ws_url, | 49 ws_url, |
| 51 sockopt=[(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)]) | 50 sockopt=[(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)]) |
| 52 self.assertNotEquals( | 51 self.assertNotEquals( |
| 53 ws.sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR), 0) | 52 ws.sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR), 0) |
| 54 self.assertNotEquals( | 53 self.assertNotEquals( |
| 55 ws.sock.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY), 0) | 54 ws.sock.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY), 0) |
| OLD | NEW |