| OLD | NEW |
| 1 <title>Test whether a WebSocket connection triggers a SafeBrowsing interstitial<
/title> | 1 <title>Test whether a WebSocket connection triggers a SafeBrowsing interstitial<
/title> |
| 2 <script> | 2 <script> |
| 3 const url = new URL(document.location.href); |
| 4 const type = url.searchParams.get('type'); |
| 3 // Construct the WebSocket URL from the page URL. The server should not be | 5 // Construct the WebSocket URL from the page URL. The server should not be |
| 4 // configured to accept a WebSocket handshake at this endpoint, or the "not | 6 // configured to accept a WebSocket handshake at this endpoint, or the "not |
| 5 // blocked" test will fail. A 404 error is perfect. | 7 // blocked" test will fail. A 404 error is perfect. |
| 6 const wsUrl = new URL('/safe_browsing/malware-ws', document.location.href); | 8 const wsUrl = new URL('/safe_browsing/malware-ws', url); |
| 7 wsUrl.protocol = 'ws'; | 9 wsUrl.protocol = 'ws'; |
| 8 const ws = new WebSocket(wsUrl.href); | 10 |
| 9 // The "not blocked" test looks for this title change to verify that the request | 11 function workerTest() { |
| 10 // has not been blocked. | 12 const src = ` |
| 11 ws.onerror = () => { document.title = 'COMPLETED'; }; | 13 const ws = new WebSocket('${wsUrl}'); |
| 14 ws.onerror = () => { |
| 15 postMessage('COMPLETED'); |
| 16 }; |
| 17 `; |
| 18 const blob = new Blob([src]); |
| 19 const srcUrl = URL.createObjectURL(blob); |
| 20 const worker = new Worker(srcUrl); |
| 21 worker.onmessage = signalComplete; |
| 22 } |
| 23 |
| 24 switch (type) { |
| 25 case 'worker': |
| 26 workerTest(); |
| 27 break; |
| 28 |
| 29 default: |
| 30 windowTest(); |
| 31 break; |
| 32 } |
| 33 |
| 34 function windowTest() { |
| 35 const ws = new WebSocket(wsUrl.href); |
| 36 ws.onerror = signalComplete; |
| 37 } |
| 38 |
| 39 function signalComplete() { |
| 40 // The "not blocked" test looks for this title change to verify that the |
| 41 // request has not been blocked. |
| 42 document.title = 'COMPLETED'; |
| 43 } |
| 12 </script> | 44 </script> |
| OLD | NEW |