| 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 // numResources: 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 numNonCORSResources = parseInt(parsedParams['numNonCORSResources'], 10); |
| 18 var numCORSResources = parseInt(parsedParams['numCORSResources'], 10); |
| 19 var subresourceList = [ |
| 20 'predictor/empty.js', |
| 21 'predictor/empty1.js', |
| 22 'predictor/empty2.js', |
| 23 ]; |
| 24 var nonCORSSubresources = subresourceList.slice(0, numNonCORSResources); |
| 25 var CORSSubresources = subresourceList.slice(0, numCORSResources); |
| 26 |
| 27 var numOK = 0; |
| 28 function logResponse(r) { |
| 29 // Opaque responses are not necessarily network errors. We get them when we |
| 30 // make cross origin requests with no-cors. |
| 31 if (r.status == 200 || r.type == "opaque") { |
| 32 numOK++; |
| 33 if (numOK == numNonCORSResources + numCORSResources) { |
| 34 window.domAutomationController.send(true); |
| 35 } |
| 36 } else { |
| 37 window.domAutomationController.send(false); |
| 38 } |
| 39 } |
| 40 |
| 41 function sendFetches() { |
| 42 nonCORSSubresources.forEach(function(r) { |
| 43 fetch(subresourceHost + r, {mode: 'no-cors', method: 'get'}) |
| 44 .then(logResponse); |
| 45 }); |
| 46 CORSSubresources.forEach(function(r) { |
| 47 fetch(subresourceHost + r, {mode: 'cors', method: 'get'}).then(logResponse); |
| 48 }); |
| 49 } |
| OLD | NEW |