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

Unified Diff: chrome/test/data/subresource_filter/websocket_connection.js

Issue 2714573002: Enable websocket filtering via SubresourceFilter (Closed)
Patch Set: OWNERS 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/subresource_filter/websocket_connection.js
diff --git a/chrome/test/data/subresource_filter/websocket_connection.js b/chrome/test/data/subresource_filter/websocket_connection.js
new file mode 100644
index 0000000000000000000000000000000000000000..4b94c8dd0f43541e70da06f9139335c91ecb2015
--- /dev/null
+++ b/chrome/test/data/subresource_filter/websocket_connection.js
@@ -0,0 +1,32 @@
+// Note: This JS can run either in a worker or as a script in the main document
+// context.
+function connectWebSocket(url, inWorker) {
+ function messageMainContext(data) {
+ if (inWorker)
+ self.postMessage(data);
+ else
+ self.postMessage(data, location);
+ }
+ var ws = new WebSocket(url);
+
+ ws.onopen = function() {
+ ws.send('hello world');
+ };
+
+ ws.onclose = function() {
+ messageMainContext('onclose');
+ };
+
+ ws.onmessage = function() {
+ messageMainContext('onmessage');
+ };
+}
+
+self.addEventListener('message', function(e) {
+ // Will only receive a message with a URL in it if this JS is executing in a
engedy 2017/03/06 16:31:01 To make this a bit cleaner, what do you think of:
Charlie Harrison 2017/03/06 19:22:11 SGTM. Done
+ // worker.
+ if (e.data.url) {
+ connectWebSocket(e.data.url, true /* inWorker */);
+ }
+});
+

Powered by Google App Engine
This is Rietveld 408576698