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

Unified Diff: chrome/test/data/safe_browsing/malware_websocket.html

Issue 2971333002: SafeBrowsing test for WebSocket connection from worker (Closed)
Patch Set: Created 3 years, 5 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
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_service_browsertest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/safe_browsing/malware_websocket.html
diff --git a/chrome/test/data/safe_browsing/malware_websocket.html b/chrome/test/data/safe_browsing/malware_websocket.html
index df66c39c641cb4957d10dbe85f674a6a9c4918d7..deb0a007ab2f7a7f6716453c458844cba81720b5 100644
--- a/chrome/test/data/safe_browsing/malware_websocket.html
+++ b/chrome/test/data/safe_browsing/malware_websocket.html
@@ -1,12 +1,44 @@
<title>Test whether a WebSocket connection triggers a SafeBrowsing interstitial</title>
<script>
+const url = new URL(document.location.href);
+const type = url.searchParams.get('type');
// Construct the WebSocket URL from the page URL. The server should not be
// configured to accept a WebSocket handshake at this endpoint, or the "not
// blocked" test will fail. A 404 error is perfect.
-const wsUrl = new URL('/safe_browsing/malware-ws', document.location.href);
+const wsUrl = new URL('/safe_browsing/malware-ws', url);
wsUrl.protocol = 'ws';
-const ws = new WebSocket(wsUrl.href);
-// The "not blocked" test looks for this title change to verify that the request
-// has not been blocked.
-ws.onerror = () => { document.title = 'COMPLETED'; };
+
+function workerTest() {
+ const src = `
+const ws = new WebSocket('${wsUrl}');
+ws.onerror = () => {
+ postMessage('COMPLETED');
+};
+`;
+ const blob = new Blob([src]);
+ const srcUrl = URL.createObjectURL(blob);
+ const worker = new Worker(srcUrl);
+ worker.onmessage = signalComplete;
+}
+
+switch (type) {
+ case 'worker':
+ workerTest();
+ break;
+
+ default:
+ windowTest();
+ break;
+}
+
+function windowTest() {
+ const ws = new WebSocket(wsUrl.href);
+ ws.onerror = signalComplete;
+}
+
+function signalComplete() {
+ // The "not blocked" test looks for this title change to verify that the
+ // request has not been blocked.
+ document.title = 'COMPLETED';
+}
</script>
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_service_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698