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

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

Issue 2449913002: Support WebSocket in WebRequest API. (Closed)
Patch Set: git cl format 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 // TODO(pkalinnikov): Figure out why the frame URL is unknown.
19 frameUrl: 'unknown frame URL',
20 },
21 },
22 { label: 'onBeforeSendHeaders',
23 event: 'onBeforeSendHeaders',
24 details: {
25 url: url,
26 type: 'websocket',
27 },
28 },
29 { label: 'onSendHeaders',
30 event: 'onSendHeaders',
31 details: {
32 url: url,
33 type: 'websocket',
34 },
35 },
36 { label: 'onHeadersReceived',
37 event: 'onHeadersReceived',
38 details: {
39 url: url,
40 type: 'websocket',
41 statusCode: 101,
42 statusLine: 'HTTP/1.1 101 Switching Protocols',
43 },
44 },
45 { label: 'onResponseStarted',
46 event: 'onResponseStarted',
47 details: {
48 url: url,
49 type: 'websocket',
50 ip: '127.0.0.1',
51 fromCache: false,
52 statusCode: 101,
53 statusLine: 'HTTP/1.1 101 Switching Protocols',
54 },
55 },
56 { label: 'onCompleted',
57 event: 'onCompleted',
58 details: {
59 url: url,
60 type: 'websocket',
61 fromCache: false,
62 statusCode: 101,
63 statusLine: 'HTTP/1.1 101 Switching Protocols',
64 }
65 },
66 ],
67 [ // event order
68 ['onBeforeRequest', 'onBeforeSendHeaders', 'onSendHeaders',
69 'onHeadersReceived', 'onResponseStarted', 'onCompleted']
70 ],
71 {urls: ['<all_urls>']}, // filter
72 ['blocking'] // extraInfoSpec
73 );
74 testWebSocketConnection(url, true /* expectedToConnect*/);
75 },
76
77 // Tries to open a WebSocket connection, with a blocking handler that
78 // cancels the request. The connection will not be established.
79 function handshakeRequestCancelled() {
80 var url = getWSTestURL(testWebSocketPort);
81 expect(
82 [ // events
83 { label: 'onBeforeRequest',
84 event: 'onBeforeRequest',
85 details: {
86 url: url,
87 type: 'websocket',
88 frameUrl: 'unknown frame URL',
89 },
90 retval: {cancel: true}
91 },
92 // Cancelling is considered an error.
93 { label: 'onErrorOccurred',
94 event: 'onErrorOccurred',
95 details: {
96 url: url,
97 type: 'websocket',
98 fromCache: false,
99 error: 'net::ERR_BLOCKED_BY_CLIENT'
100 }
101 },
102 ],
103 [ // event order
104 ['onBeforeRequest', 'onErrorOccurred']
105 ],
106 {urls: ['<all_urls>']}, // filter
107 ['blocking'] // extraInfoSpec
108 );
109 testWebSocketConnection(url, false /* expectedToConnect*/);
110 },
111
112 // Opens a WebSocket connection, with a blocking handler that tries to
113 // redirect the request. The redirect will be ignored.
114 function redirectIsIgnoredAndHandshakeSucceeds() {
115 var url = getWSTestURL(testWebSocketPort);
116 var redirectedUrl1 = getWSTestURL(testWebSocketPort) + '?redirected1';
117 var redirectedUrl2 = getWSTestURL(testWebSocketPort) + '?redirected2';
118 expect(
119 [ // events
120 { label: 'onBeforeRequest',
121 event: 'onBeforeRequest',
122 details: {
123 url: url,
124 type: 'websocket',
125 frameUrl: 'unknown frame URL',
126 },
127 retval: {redirectUrl: redirectedUrl1}
128 },
129 { label: 'onBeforeSendHeaders',
130 event: 'onBeforeSendHeaders',
131 details: {
132 url: url,
133 type: 'websocket',
134 },
135 },
136 { label: 'onSendHeaders',
137 event: 'onSendHeaders',
138 details: {
139 url: url,
140 type: 'websocket',
141 },
142 },
143 { label: 'onHeadersReceived',
144 event: 'onHeadersReceived',
145 details: {
146 url: url,
147 type: 'websocket',
148 statusCode: 101,
149 statusLine: 'HTTP/1.1 101 Switching Protocols',
150 },
151 retval: {redirectUrl: redirectedUrl2}
152 },
153 { label: 'onResponseStarted',
154 event: 'onResponseStarted',
155 details: {
156 url: url,
157 type: 'websocket',
158 ip: '127.0.0.1',
159 fromCache: false,
160 statusCode: 101,
161 statusLine: 'HTTP/1.1 101 Switching Protocols',
162 },
163 },
164 { label: 'onCompleted',
165 event: 'onCompleted',
166 details: {
167 url: url,
168 type: 'websocket',
169 fromCache: false,
170 statusCode: 101,
171 statusLine: 'HTTP/1.1 101 Switching Protocols',
172 }
173 },
174 ],
175 [ // event order
176 ['onBeforeRequest', 'onBeforeSendHeaders', 'onHeadersReceived',
177 'onResponseStarted', 'onCompleted']
178 ],
179 {urls: ['<all_urls>']}, // filter
180 ['blocking'] // extraInfoSpec
181 );
182 testWebSocketConnection(url, true /* expectedToConnect*/);
183 },
184 ], tab);
185 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698