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

Side by Side Diff: chrome/test/data/extensions/api_test/webrequest/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 function getWSTestURL(port) {
6 return 'ws://localhost:' + port + '/echo-with-no-extension';
7 }
8
9 // Tries to: open a WebSocket, write a test message to it, close it. Verifies
10 // that all the necessary events are triggered if |expectedToConnect|, otherwise
11 // makes sure WebSocket terminates with an error.
12 function testWebSocketConnection(url, expectedToConnect) {
13 var ws = new WebSocket(url);
14 var kMessage = 'test message';
15
16 var keepAlive = chrome.test.callbackAdded();
17
18 ws.onerror = function(error) {
19 chrome.test.log('WebSocket error: ' + error);
20 chrome.test.assertFalse(expectedToConnect);
21 keepAlive();
22 };
23 ws.onmessage = function(messageEvent) {
24 chrome.test.log('Message received: ' + messageEvent.data);
25 chrome.test.assertTrue(expectedToConnect);
26 chrome.test.assertEq(kMessage, messageEvent.data);
27 ws.close();
28 };
29 ws.onclose = function(event) {
30 chrome.test.log('WebSocket closed.');
31 chrome.test.assertEq(expectedToConnect, event.wasClean);
32 }
33
34 ws.onopen = function() {
35 chrome.test.log('WebSocket opened.');
36 chrome.test.assertTrue(expectedToConnect);
37 keepAlive();
38 ws.send(kMessage);
39 };
40 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698