Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(887)

Side by Side Diff: chrome/test/data/extensions/api_test/webrequest/test_websocket.js

Issue 2449913002: Support WebSocket in WebRequest API. (Closed)
Patch Set: Add tests for onAuthRequired path for WS handshake. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 chrome.tabs.getCurrent(function(tab) {
6 runTestsForTab([
7 // Opens a WebSocket connection, writes a message to it, and closes the
8 // connection. WebRequest API should observe the entire handshake.
9 function handshakeSucceeds() {
10 var url = getWSTestURL(testWebSocketPort);
11 expect(
12 [ //events
13 { label: 'onBeforeRequest',
14 event: 'onBeforeRequest',
15 details: {
16 url: url,
17 type: 'websocket',
18 frameUrl: 'unknown frame URL',
Devlin 2017/02/21 16:10:44 Can we not determine the url that initiated the re
pkalinnikov 2017/02/21 19:18:16 This field is not the API's thing, it is added by
Devlin 2017/02/21 20:34:11 Whoops, mistook this for url from the API. Not an
19 },
20 },
21 { label: 'onBeforeSendHeaders',
22 event: 'onBeforeSendHeaders',
23 details: {
24 url: url,
25 type: 'websocket',
26 },
27 },
28 { label: 'onSendHeaders',
29 event: 'onSendHeaders',
30 details: {
31 url: url,
32 type: 'websocket',
33 },
34 },
35 { label: 'onHeadersReceived',
36 event: 'onHeadersReceived',
37 details: {
38 url: url,
39 type: 'websocket',
40 statusCode: 101,
41 statusLine: 'HTTP/1.1 101 Switching Protocols',
42 },
43 },
44 { label: 'onResponseStarted',
45 event: 'onResponseStarted',
46 details: {
47 url: url,
48 type: 'websocket',
49 ip: '127.0.0.1',
50 fromCache: false,
51 statusCode: 101,
52 statusLine: 'HTTP/1.1 101 Switching Protocols',
53 },
54 },
55 { label: 'onCompleted',
56 event: 'onCompleted',
57 details: {
58 url: url,
59 type: 'websocket',
60 fromCache: false,
61 statusCode: 101,
62 statusLine: 'HTTP/1.1 101 Switching Protocols',
63 }
64 },
65 ],
66 [ // event order
67 ['onBeforeRequest', 'onBeforeSendHeaders', 'onSendHeaders',
68 'onHeadersReceived', 'onResponseStarted', 'onCompleted']
69 ],
70 {urls: ['<all_urls>']}, // filter
71 ['blocking'] // extraInfoSpec
72 );
73 testWebSocketConnection(url, true);
Devlin 2017/02/21 16:10:44 document what 'true' is (same for line 108, 181)
pkalinnikov 2017/02/21 19:18:16 Done.
74 },
75
76 // Tries to open a WebSocket connection, with a blocking handler that
77 // cancels the request. The connection will not be established.
78 function handshakeRequestCancelled() {
79 var url = getWSTestURL(testWebSocketPort);
80 expect(
81 [ // events
82 { label: 'onBeforeRequest',
83 event: 'onBeforeRequest',
84 details: {
85 url: url,
86 type: 'websocket',
87 frameUrl: 'unknown frame URL',
88 },
89 retval: {cancel: true}
90 },
91 // Cancelling is considered an error.
92 { label: 'onErrorOccurred',
93 event: 'onErrorOccurred',
94 details: {
95 url: url,
96 type: 'websocket',
97 fromCache: false,
98 error: 'net::ERR_BLOCKED_BY_CLIENT'
99 }
100 },
101 ],
102 [ // event order
103 ['onBeforeRequest', 'onErrorOccurred']
104 ],
105 {urls: ['<all_urls>']}, // filter
106 ['blocking'] // extraInfoSpec
107 );
108 testWebSocketConnection(url, false);
109 },
110
111 // Opens a WebSocket connection, with a blocking handler that tries to
112 // redirect the request. The redirect will be ignored.
113 function redirectIsIgnoredAndHandshakeSucceeds() {
114 var url = getWSTestURL(testWebSocketPort);
115 var redirectedUrl1 = getWSTestURL(testWebSocketPort) + '?redirected1';
116 var redirectedUrl2 = getWSTestURL(testWebSocketPort) + '?redirected2';
117 expect(
118 [ // events
119 { label: 'onBeforeRequest',
120 event: 'onBeforeRequest',
121 details: {
122 url: url,
123 type: 'websocket',
124 frameUrl: 'unknown frame URL',
125 },
126 retval: {redirectUrl: redirectedUrl1}
127 },
128 { label: 'onBeforeSendHeaders',
129 event: 'onBeforeSendHeaders',
130 details: {
131 url: url,
132 type: 'websocket',
133 },
134 },
135 { label: 'onSendHeaders',
136 event: 'onSendHeaders',
137 details: {
138 url: url,
139 type: 'websocket',
140 },
141 },
142 { label: 'onHeadersReceived',
143 event: 'onHeadersReceived',
144 details: {
145 url: url,
146 type: 'websocket',
147 statusCode: 101,
148 statusLine: 'HTTP/1.1 101 Switching Protocols',
149 },
150 retval: {redirectUrl: redirectedUrl2}
151 },
152 { label: 'onResponseStarted',
153 event: 'onResponseStarted',
154 details: {
155 url: url,
156 type: 'websocket',
157 ip: '127.0.0.1',
158 fromCache: false,
159 statusCode: 101,
160 statusLine: 'HTTP/1.1 101 Switching Protocols',
161 },
162 },
163 { label: 'onCompleted',
164 event: 'onCompleted',
165 details: {
166 url: url,
167 type: 'websocket',
168 fromCache: false,
169 statusCode: 101,
170 statusLine: 'HTTP/1.1 101 Switching Protocols',
171 }
172 },
173 ],
174 [ // event order
175 ['onBeforeRequest', 'onBeforeSendHeaders', 'onHeadersReceived',
176 'onResponseStarted', 'onCompleted']
177 ],
178 {urls: ['<all_urls>']}, // filter
179 ['blocking'] // extraInfoSpec
180 );
181 testWebSocketConnection(url, true);
182 },
183 ], tab);
184 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698