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

Unified Diff: chrome/test/data/extensions/api_test/webrequest/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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/webrequest/websocket.js
diff --git a/chrome/test/data/extensions/api_test/webrequest/websocket.js b/chrome/test/data/extensions/api_test/webrequest/websocket.js
new file mode 100644
index 0000000000000000000000000000000000000000..e9414faf1359d0fbda772efbbc40173f5678501c
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/webrequest/websocket.js
@@ -0,0 +1,40 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+function getWSTestURL(port) {
+ return 'ws://localhost:' + port + '/echo-with-no-extension';
+}
+
+// Tries to: open a WebSocket, write a test message to it, close it. Verifies
+// that all the necessary events are triggered if |expectedToConnect|, otherwise
+// makes sure WebSocket terminates with an error.
+function testWebSocketConnection(url, expectedToConnect) {
+ var ws = new WebSocket(url);
+ var kMessage = 'test message';
+
+ var keepAlive = chrome.test.callbackAdded();
+
+ ws.onerror = function(error) {
+ chrome.test.log('WebSocket error: ' + error);
+ chrome.test.assertFalse(expectedToConnect);
+ keepAlive();
+ };
+ ws.onmessage = function(messageEvent) {
+ chrome.test.log('Message received: ' + messageEvent.data);
+ chrome.test.assertTrue(expectedToConnect);
+ chrome.test.assertEq(kMessage, messageEvent.data);
+ ws.close();
+ };
+ ws.onclose = function(event) {
+ chrome.test.log('WebSocket closed.');
+ chrome.test.assertEq(expectedToConnect, event.wasClean);
+ }
+
+ ws.onopen = function() {
+ chrome.test.log('WebSocket opened.');
+ chrome.test.assertTrue(expectedToConnect);
+ keepAlive();
+ ws.send(kMessage);
+ };
+}

Powered by Google App Engine
This is Rietveld 408576698