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

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

Issue 2449913002: Support WebSocket in WebRequest API. (Closed)
Patch Set: Remove FIXME because the test works. Add TODO for more tests. Created 4 years, 1 month 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 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 webSocketUrl = getEchoTestURL(testWebSocketPort);
tyoshino (SeeGerritForStatus) 2016/12/06 08:05:06 var
pkalinnikov 2016/12/13 21:15:59 Done.
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,
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 // FIXME(pkalinnikov): Switch to onCompleted once crbug/663672 is fixed.
93 { label: "onErrorOccurred",
94 event: "onErrorOccurred",
95 details: {
96 url: webSocketUrl,
97 type: "other",
98 tabId: 1,
99 fromCache: false,
100 error: "net::ERR_ABORTED",
101 },
102 },
103 ],
104 [ // event order
105 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
106 "onHeadersReceived", "onResponseStarted", "onErrorOccurred"]
107 ],
108 {urls: ["<all_urls>"]}, // filter
109 ["blocking"] // extraInfoSpec
110 );
111
112 testBody(testWebSocketPort);
113 }
114
115 runTests([
116 // TODO(pkalinnikov): Add tests excercising redirects and blocking.
tyoshino (SeeGerritForStatus) 2016/12/06 08:05:06 exercise
pkalinnikov 2016/12/13 21:15:59 Done.
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 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698