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

Unified Diff: third_party/WebKit/LayoutTests/http/tests/security/suborigins/crossorigin/suborigin-cors-xhr-preflight.php

Issue 2370843003: Suborigin LayoutTest formatting and refactoring (Closed)
Patch Set: Created 4 years, 3 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: third_party/WebKit/LayoutTests/http/tests/security/suborigins/crossorigin/suborigin-cors-xhr-preflight.php
diff --git a/third_party/WebKit/LayoutTests/http/tests/security/suborigins/crossorigin/suborigin-cors-xhr-preflight.php b/third_party/WebKit/LayoutTests/http/tests/security/suborigins/crossorigin/suborigin-cors-xhr-preflight.php
index f1d6e80aa9c73b70cbc99db5f8dbc035d6f2ca2b..c7958f6d174c226dde9c01a4204be1b7ca98f3b3 100644
--- a/third_party/WebKit/LayoutTests/http/tests/security/suborigins/crossorigin/suborigin-cors-xhr-preflight.php
+++ b/third_party/WebKit/LayoutTests/http/tests/security/suborigins/crossorigin/suborigin-cors-xhr-preflight.php
@@ -4,6 +4,7 @@ header("Suborigin: foobar");
<!DOCTYPE html>
<html>
<head>
+<meta charset="utf-8">
<title>Allow suborigin in HTTP header</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
@@ -13,92 +14,92 @@ header("Suborigin: foobar");
<div id="container"></div>
<script>
// XMLHttpRequest tests
-var SuboriginXHRTest = function(pass, name, src, crossoriginValue) {
- SuboriginTest.call(this, pass, "XHR: " + name, src, crossoriginValue);
+var SuboriginXHRTest = function(pass, name, src, crossorigin_value) {
+ SuboriginTest.call(this, pass, 'XHR: ' + name, src, crossorigin_value);
}
SuboriginXHRTest.prototype.execute = function() {
- var test = async_test(this.name);
- var xhr = new XMLHttpRequest();
+ var settings = this;
+ async_test(test => {
+ var xhr = new XMLHttpRequest();
- if (this.crossoriginValue === 'use-credentials') {
- xhr.withCredentials = true;
- }
+ if (settings.crossorigin_value === 'use-credentials') {
+ xhr.withCredentials = true;
+ }
- if (this.pass) {
- xhr.onload = function() {
- test.done();
- };
- xhr.onerror = function() {
- test.step(function() { assert_unreached("Good XHR fired error handler."); });
- };
- } else {
- xhr.onload = function() {
- test.step(function() { assert_unreached("Bad XHR successful."); });
- };
- xhr.onerror = function() {
- test.done();
- };
- }
+ if (settings.pass) {
+ xhr.onload = test.step_func_done();
+ xhr.onerror = test.unreached_func('Good XHR fired error handler.');
+ } else {
+ xhr.onload = test.unreached_func('Bad XHR successful.');
+ xhr.onerror = test.step_func_done();
+ }
- xhr.open("GET", this.src);
- // Set a custom header to force a preflight. Even though the
- // scheme/host/port of the source and destination origins are the same, the
- // Suborigin should cause the request to be treated as cross-origin.
- xhr.setRequestHeader("x-custom-header", "foobar");
- xhr.send();
+ xhr.open('GET', settings.src);
+ // Set a custom header to force a preflight. Even though the
+ // scheme/host/port of the source and destination origins are the same, the
+ // Suborigin should cause the request to be treated as cross-origin.
+ xhr.setRequestHeader('x-custom-header', 'foobar');
+ xhr.send();
+ }, settings.name);
};
-var xorigin_preflight_script = "http://127.0.0.1:8000/security/resources/cors-script.php";
+var xorigin_preflight_script =
+ 'http://127.0.0.1:8000/security/resources/cors-script.php';
// XHR preflight tests
new SuboriginXHRTest(
- false,
- "Complex anonymous XHR preflight, no AC for custom header",
- xorigin_preflight_script + "?cors=http-so://foobar.127.0.0.1:8000",
- "anonymous").execute();
+ false,
+ 'Complex anonymous XHR preflight, no AC for custom header',
+ xorigin_preflight_script + '?cors=http-so://foobar.127.0.0.1:8000',
+ 'anonymous').execute();
new SuboriginXHRTest(
- true,
- "Complex anonymous XHR preflight, has AC for custom header",
- xorigin_preflight_script + "?cors=http-so://foobar.127.0.0.1:8000&custom=x-custom-header",
- "anonymous").execute();
+ true,
+ 'Complex anonymous XHR preflight, has AC for custom header',
+ xorigin_preflight_script + '?cors=http-so://foobar.127.0.0.1:8000&' +
+ 'custom=x-custom-header',
+ 'anonymous').execute();
new SuboriginXHRTest(
- false,
- "Complex anonymous XHR preflight with '*' ACAO, no AC for custom header",
- xorigin_preflight_script + "?cors=*",
- "anonymous").execute();
+ false,
+ 'Complex anonymous XHR preflight with \'*\' ACAO, no AC for custom header',
+ xorigin_preflight_script + '?cors=*',
+ 'anonymous').execute();
new SuboriginXHRTest(
- true,
- "Complex anonymous XHR preflight with '*' ACAO, has AC for custom header",
- xorigin_preflight_script + "?cors=*&custom=x-custom-header",
- "anonymous").execute();
+ true,
+ 'Complex anonymous XHR preflight with \'*\' ACAO, has AC for custom header',
+ xorigin_preflight_script + '?cors=*&custom=x-custom-header',
+ 'anonymous').execute();
new SuboriginXHRTest(
- false,
- "Complex XHR with credentials preflight, no AC for custom header",
- xorigin_preflight_script + "?cors=http-so://foobar.127.0.0.1:8000&credentials=true",
- "use-credentials").execute();
+ false,
+ 'Complex XHR with credentials preflight, no AC for custom header',
+ xorigin_preflight_script + '?cors=http-so://foobar.127.0.0.1:8000&' +
+ 'credentials=true',
+ 'use-credentials').execute();
new SuboriginXHRTest(
- true,
- "Complex XHR with credentials preflight, has AC for custom header",
- xorigin_preflight_script + "?cors=http-so://foobar.127.0.0.1:8000&credentials=true&custom=x-custom-header",
- "use-credentials").execute();
+ true,
+ 'Complex XHR with credentials preflight, has AC for custom header',
+ xorigin_preflight_script + '?cors=http-so://foobar.127.0.0.1:8000&' +
+ 'credentials=true&custom=x-custom-header',
+ 'use-credentials').execute();
new SuboriginXHRTest(
- false,
- "Complex XHR with credentials preflight with '*' ACAO, no AC for custom header",
- xorigin_preflight_script + "?cors=*&credentials=true",
- "use-credentials").execute();
+ false,
+ 'Complex XHR with credentials preflight with \'*\' ACAO, ' +
+ 'no AC for custom header',
+ xorigin_preflight_script + '?cors=*&credentials=true',
+ 'use-credentials').execute();
new SuboriginXHRTest(
- false,
- "Complex XHR with credentials preflight with '*' ACAO, has AC for custom header",
- xorigin_preflight_script + "?cors=*&credentials=true&custom=x-custom-header",
- "use-credentials").execute();
+ false,
+ 'Complex XHR with credentials preflight with \'*\' ACAO, ' +
+ 'has AC for custom header',
+ xorigin_preflight_script + '?cors=*&credentials=true&custom=x-custom-header',
+ 'use-credentials').execute();
</script>
</body>
</html>

Powered by Google App Engine
This is Rietveld 408576698