| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 // This script file should be requested with the following query params: |
| 6 // subresourceHost: The base url of the embedded test server to request |
| 7 // subresources from. |
| 8 // numCORSResources: The number of resources to request (between 0 and 3). |
| 9 var queryString = window.location.search.substring(1); |
| 10 var vars = queryString.split("&"); |
| 11 var parsedParams = {}; |
| 12 vars.forEach(function(v) { |
| 13 var key_value = v.split('='); |
| 14 parsedParams[key_value[0]] = key_value[1]; |
| 15 }); |
| 16 var subresourceHost = parsedParams['subresourceHost']; |
| 17 var numCORSResources = parseInt(parsedParams['numCORSResources'], 10); |
| 18 var sendImmediately = parseInt(parsedParams['sendImmediately'], 10); |
| 19 var subresourceList = [ |
| 20 'predictor/empty.js', |
| 21 'predictor/empty1.js', |
| 22 'predictor/empty2.js', |
| 23 ]; |
| 24 var CORSSubresources = subresourceList.slice(0, numCORSResources); |
| 25 |
| 26 var numOK = 0; |
| 27 function logResponse(r) { |
| 28 // Opaque responses are not necessarily network errors. We get them when we |
| 29 // make cross origin requests with no-cors. |
| 30 if (r.status == 200 || r.type == "opaque") { |
| 31 numOK++; |
| 32 if (numOK == numCORSResources) { |
| 33 window.domAutomationController.send(true); |
| 34 } |
| 35 } else { |
| 36 window.domAutomationController.send(false); |
| 37 } |
| 38 } |
| 39 |
| 40 function startFetchesAndWaitForReply() { |
| 41 CORSSubresources.forEach(function(r) { |
| 42 fetch(subresourceHost + r, {mode: 'cors', method: 'get'}).then(logResponse); |
| 43 }); |
| 44 } |
| 45 |
| 46 if (sendImmediately) { |
| 47 startFetchesAndWaitForReply(); |
| 48 } |
| OLD | NEW |