OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 function getEchoTestURL(port) { | |
6 return "ws://localhost:" + port + "/echo-with-no-extension"; | |
7 } | |
8 | |
9 function openAndCloseWebSocket(port) { | |
10 var url = getEchoTestURL(port); | |
11 var ws = new WebSocket(url); | |
12 | |
13 ws.onclose = function() { | |
14 chrome.test.log("WebSocket closed."); | |
15 } | |
16 ws.onopen = function() { | |
17 chrome.test.log("WebSocket opened."); | |
18 }; | |
19 } | |
20 | |
21 function openWebSocketThenWriteAndClose(port) { | |
22 var url = getEchoTestURL(port); | |
23 var ws = new WebSocket(url); | |
24 var MESSAGE = "test message"; | |
25 | |
26 ws.onmessage = function(messageEvent) { | |
27 chrome.test.log("Message received: " + messageEvent.data); | |
28 chrome.test.assertEq(MESSAGE, messageEvent.data); | |
29 ws.close(); | |
30 }; | |
31 ws.onclose = function() { | |
32 chrome.test.log("WebSocket closed."); | |
33 } | |
34 ws.onopen = function() { | |
35 chrome.test.log("WebSocket opened."); | |
36 ws.send(MESSAGE); | |
37 }; | |
38 } | |
39 | |
40 function webSocketEchoTestImpl(testBody) { | |
41 var webSocketUrl = getEchoTestURL(testWebSocketPort); | |
42 expect( | |
43 [ //events | |
44 { label: "onBeforeRequest", | |
45 event: "onBeforeRequest", | |
46 details: { | |
47 url: webSocketUrl, | |
48 type: "other", | |
49 // Note: The tab is different from the one where navigation happened. | |
50 tabId: 1, | |
battre
2017/02/07 15:03:02
Hm, do you think this can be fixed?
pkalinnikov
2017/02/09 18:15:05
TL;DR: This is not a bug. See chrome/test/data/ext
| |
51 frameUrl: "unknown frame URL", | |
52 }, | |
53 }, | |
54 { label: "onBeforeSendHeaders", | |
55 event: "onBeforeSendHeaders", | |
56 details: { | |
57 url: webSocketUrl, | |
58 type: "other", | |
59 tabId: 1, | |
60 }, | |
61 }, | |
62 { label: "onSendHeaders", | |
63 event: "onSendHeaders", | |
64 details: { | |
65 url: webSocketUrl, | |
66 type: "other", | |
67 tabId: 1, | |
68 }, | |
69 }, | |
70 { label: "onHeadersReceived", | |
71 event: "onHeadersReceived", | |
72 details: { | |
73 url: webSocketUrl, | |
74 type: "other", | |
75 tabId: 1, | |
76 statusCode: 101, | |
77 statusLine: "HTTP/1.1 101 Switching Protocols", | |
78 }, | |
79 }, | |
80 { label: "onResponseStarted", | |
81 event: "onResponseStarted", | |
82 details: { | |
83 url: webSocketUrl, | |
84 type: "other", | |
85 tabId: 1, | |
86 ip: "127.0.0.1", | |
87 fromCache: false, | |
88 statusCode: 101, | |
89 statusLine: "HTTP/1.1 101 Switching Protocols", | |
90 }, | |
91 }, | |
92 { label: "onCompleted", | |
93 event: "onCompleted", | |
94 details: { | |
95 url: webSocketUrl, | |
96 type: "other", | |
97 tabId: 1, | |
98 fromCache: false, | |
99 statusCode: 101, | |
100 statusLine: "HTTP/1.1 101 Switching Protocols", | |
101 } | |
102 }, | |
103 ], | |
104 [ // event order | |
105 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", | |
106 "onHeadersReceived", "onResponseStarted", "onCompleted"] | |
107 ], | |
108 {urls: ["<all_urls>"]}, // filter | |
109 ["blocking"] // extraInfoSpec | |
110 ); | |
111 | |
112 testBody(testWebSocketPort); | |
113 } | |
114 | |
115 runTests([ | |
116 // TODO(pkalinnikov): Add tests exercising redirects and blocking. | |
battre
2017/02/07 15:03:02
yes, please.
pkalinnikov
2017/02/09 18:15:04
Added a test with blocking.
I also tried adding a
| |
117 | |
118 // Opens a WebSocket connection and closes it. WebRequest API should observe | |
119 // only the handshake. | |
120 function openAndCloseWebSocketTest() { | |
121 webSocketEchoTestImpl(openAndCloseWebSocket); | |
122 }, | |
123 | |
124 // Opens a WebSocket connection, writes a message to it, and closes the | |
125 // connection. WebRequest API should observe only the handshake. | |
126 function openWebSocketThenWriteAndCloseTest() { | |
127 webSocketEchoTestImpl(openWebSocketThenWriteAndClose); | |
128 }, | |
129 ]); | |
OLD | NEW |