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

Unified Diff: chrome/test/data/predictor/fetch_cross_site.js

Issue 1881463003: Add a browsertest suite for net predictor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: EXPECT that we get the right number of accepted connections after waiting Created 4 years, 7 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/predictor/fetch_cross_site.js
diff --git a/chrome/test/data/predictor/fetch_cross_site.js b/chrome/test/data/predictor/fetch_cross_site.js
new file mode 100644
index 0000000000000000000000000000000000000000..976eacddad1d69066ce3a47d88529b6d00a327e6
--- /dev/null
+++ b/chrome/test/data/predictor/fetch_cross_site.js
@@ -0,0 +1,48 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This script file should be requested with the following query params:
+// subresourceHost: The base url of the embedded test server to request
+// subresources from.
+// numCORSResources: The number of resources to request (between 0 and 3).
+var queryString = window.location.search.substring(1);
+var vars = queryString.split("&");
+var parsedParams = {};
+vars.forEach(function(v) {
+ var key_value = v.split('=');
+ parsedParams[key_value[0]] = key_value[1];
+});
+var subresourceHost = parsedParams['subresourceHost'];
+var numCORSResources = parseInt(parsedParams['numCORSResources'], 10);
+var sendImmediately = parseInt(parsedParams['sendImmediately'], 10);
+var subresourceList = [
+ 'predictor/empty.js',
+ 'predictor/empty1.js',
+ 'predictor/empty2.js',
+];
+var CORSSubresources = subresourceList.slice(0, numCORSResources);
+
+var numOK = 0;
+function logResponse(r) {
+ // Opaque responses are not necessarily network errors. We get them when we
+ // make cross origin requests with no-cors.
+ if (r.status == 200 || r.type == "opaque") {
+ numOK++;
+ if (numOK == numCORSResources) {
+ window.domAutomationController.send(true);
+ }
+ } else {
+ window.domAutomationController.send(false);
+ }
+}
+
+function startFetchesAndWaitForReply() {
+ CORSSubresources.forEach(function(r) {
+ fetch(subresourceHost + r, {mode: 'cors', method: 'get'}).then(logResponse);
+ });
+}
+
+if (sendImmediately) {
+ startFetchesAndWaitForReply();
+}
« no previous file with comments | « chrome/test/data/predictor/empty2.js.mock-http-headers ('k') | chrome/test/data/predictor/predictor_cross_site.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698