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

Unified Diff: LayoutTests/http/tests/serviceworker/resources/fetch-cors-xhr-iframe.html

Issue 600393004: [ServiceWorker] Set FetchRequestMode and handle wasFetchedViaServiceWorker. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add comment Created 6 years, 2 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: LayoutTests/http/tests/serviceworker/resources/fetch-cors-xhr-iframe.html
diff --git a/LayoutTests/http/tests/serviceworker/resources/fetch-cors-xhr-iframe.html b/LayoutTests/http/tests/serviceworker/resources/fetch-cors-xhr-iframe.html
index f9c2e184f4d8146cd65c4861504b9e92706857a9..9cfde1a2f014e0d664a77ec716a8f083d9ee2c83 100644
--- a/LayoutTests/http/tests/serviceworker/resources/fetch-cors-xhr-iframe.html
+++ b/LayoutTests/http/tests/serviceworker/resources/fetch-cors-xhr-iframe.html
@@ -2,13 +2,21 @@
<script>
var path = base_path() + 'fetch-access-control.php';
var host_info = get_host_info();
+var SUCCESS = 'SUCCESS';
+var FAIL = 'FAIL';
-function create_success_test_promise(url, with_credentials) {
- return new Promise(function(resolve, reject) {
+function create_test_case_promise(url, with_credentials) {
+ return new Promise(function(resolve) {
var xhr = new XMLHttpRequest();
- xhr.onload = resolve;
+ xhr.onload = function() {
+ if (xhr.status == 200) {
+ resolve(SUCCESS);
+ } else {
+ resolve("STATUS" + xhr.status);
+ }
+ }
xhr.onerror = function() {
- reject('XHR to ' + url + ' should succeed.');
+ resolve(FAIL);
}
xhr.responseType = 'text';
xhr.withCredentials = with_credentials;
@@ -17,70 +25,171 @@ function create_success_test_promise(url, with_credentials) {
});
}
-function create_failure_test_promise(url, with_credentials) {
+
+function create_test_promise(url, with_credentials, expected_result) {
return new Promise(function(resolve, reject) {
- var xhr = new XMLHttpRequest();
- xhr.onload = function() {
- reject('XHR to ' + url + ' should fail.');
- }
- xhr.onerror = function() {
- resolve();
+ create_test_case_promise(url, with_credentials)
+ .then(function(result) {
+ if (result == expected_result) {
+ resolve();
+ } else {
+ reject('Result of url:' + url + ' ' +
+ ' with_credentials: ' + with_credentials + ' must be ' +
+ expected_result + ' but ' + result);
+ }
+ })
+ });
+}
+
+function create_serial_promise(test_case) {
+ return new Promise(function(resolve, reject) {
yhirano 2014/10/08 09:31:39 You can write like this: function create_serial_p
horo 2014/10/08 10:02:46 Done.
+ var func = function(i) {
+ if (i == test_case.length) {
+ resolve();
+ return;
+ }
+ create_test_promise(test_case[i][0],
+ test_case[i][1],
+ test_case[i][2])
+ .then(function() {
+ func(i + 1);
+ })
+ .catch(function(e) {
+ reject(e);
+ });
}
- xhr.responseType = 'text';
- xhr.withCredentials = with_credentials;
- xhr.open('GET', url, true);
- xhr.send();
+ func(0);
});
}
window.addEventListener('message', function(evt) {
var port = evt.ports[0];
- create_success_test_promise(host_info['HTTP_ORIGIN'] + path, false)
- .then(function() {
- return create_failure_test_promise(
- host_info['HTTP_REMOTE_ORIGIN'] + path,
- false);
- })
- .then(function() {
- return create_failure_test_promise('./dummy?reject', false);
- })
- .then(function() {
- return create_failure_test_promise('./dummy?resolve-null', false);
- })
- .then(function() {
- return create_success_test_promise(
- './dummy?url=' +
- encodeURIComponent(host_info['HTTP_ORIGIN'] + path),
- false);
- })
- .then(function() {
- return create_failure_test_promise(
- './dummy?mode=no-cors&url=' +
- encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path),
- false);
- })
- .then(function() {
- return create_success_test_promise(
- './dummy?url=' +
- encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path +
- '?ACAOrigin=' + host_info['HTTP_ORIGIN']),
- false);
- })
- .then(function() {
- return create_failure_test_promise(
- './dummy?url=' +
- encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path +
- '?ACAOrigin=' + host_info['HTTP_ORIGIN']),
- true);
- })
- .then(function() {
- return create_success_test_promise(
- './dummy?url=' +
- encodeURIComponent(
- host_info['HTTP_REMOTE_ORIGIN'] + path +
- '?ACACredentials=true&ACAOrigin=' + host_info['HTTP_ORIGIN']),
- true);
- })
+ var url = host_info['HTTP_ORIGIN'] + path;
+ var remote_url = host_info['HTTP_REMOTE_ORIGIN'] + path;
+ // If the 4th value of the item of TEST_CASES is true, the test case outputs
+ // warning messages. So such tests must be executed in serial to match the
+ // expected output text.
+ var TEST_CASES = [
+ // Reject tests
+ [url + '?reject', false, FAIL],
+ [url + '?reject', true, FAIL],
+ [remote_url + '?reject', false, FAIL],
+ [remote_url + '?reject', true, FAIL],
+ // Reject(resolve-null) tests
+ [url + '?resolve-null', false, FAIL],
+ [url + '?resolve-null', true, FAIL],
+ [remote_url + '?resolve-null', false, FAIL],
+ [remote_url + '?resolve-null', true, FAIL],
+ // Fallback tests
+ [url + '?ignore', false, SUCCESS],
+ [url + '?ignore', true, SUCCESS],
+ [remote_url + '?ignore', false, FAIL, true], // Executed in serial.
+ [remote_url + '?ignore', true, FAIL, true], // Executed in serial.
+ [
+ remote_url + '?ACAOrigin=' + host_info['HTTP_ORIGIN'] + '&ignore',
+ false, SUCCESS
+ ],
+ [
+ remote_url + '?ACAOrigin=' + host_info['HTTP_ORIGIN'] + '&ignore',
+ true, FAIL, true // Executed in serial.
+ ],
+ [
+ remote_url + '?ACAOrigin=' + host_info['HTTP_ORIGIN'] +
+ '&ACACredentials=true&ignore',
+ true, SUCCESS
+ ],
+ // Credential test (fallback)
+ [url + '?Auth&ignore', false, SUCCESS],
+ [url + '?Auth&ignore', true, SUCCESS],
+ [remote_url + '?Auth&ignore', false, FAIL, true], // Executed in serial.
+ [remote_url + '?Auth&ignore', true, FAIL, true], // Executed in serial.
+ [
+ remote_url + '?Auth&ACAOrigin=' + host_info['HTTP_ORIGIN'] + '&ignore',
+ false, 'STATUS401'
+ ],
+ [
+ remote_url + '?Auth&ACAOrigin=' + host_info['HTTP_ORIGIN'] + '&ignore',
+ true, FAIL, true // Executed in serial.
+ ],
+ [
+ remote_url + '?Auth&ACAOrigin=' + host_info['HTTP_ORIGIN'] +
+ '&ACACredentials=true&ignore',
+ true, SUCCESS
+ ],
+ // Basic response
+ [
+ url + '?mode=same-origin&url=' + encodeURIComponent(url),
+ false, SUCCESS
+ ],
+ [
+ url + '?mode=same-origin&url=' + encodeURIComponent(url),
+ false, SUCCESS
+ ],
+ [
+ remote_url + '?mode=same-origin&url=' + encodeURIComponent(url),
+ false, SUCCESS
+ ],
+ [
+ remote_url + '?mode=same-origin&url=' + encodeURIComponent(url),
+ false, SUCCESS
+ ],
+ // Opaque response
+ [
+ url + '?mode=no-cors&url=' + encodeURIComponent(remote_url),
+ false, FAIL
+ ],
+ [
+ url + '?mode=no-cors&url=' + encodeURIComponent(remote_url),
+ false, FAIL
+ ],
+ [
+ remote_url + '?mode=no-cors&url=' + encodeURIComponent(remote_url),
+ false, FAIL
+ ],
+ [
+ remote_url + '?mode=no-cors&url=' + encodeURIComponent(remote_url),
+ false, FAIL
+ ],
+ // CORS response
+ [
+ url + '?mode=cors&url=' +
+ encodeURIComponent(remote_url + '?ACAOrigin=' +
+ host_info['HTTP_ORIGIN']),
+ false, SUCCESS
+ ],
+ [
+ url + '?mode=cors&url=' +
+ encodeURIComponent(remote_url + '?ACAOrigin=' +
+ host_info['HTTP_ORIGIN']),
+ true, SUCCESS
+ ],
+ [
+ remote_url + '?mode=cors&url=' +
+ encodeURIComponent(remote_url + '?ACAOrigin=' +
+ host_info['HTTP_ORIGIN']),
+ false, SUCCESS
+ ],
+ [
+ remote_url +
+ '?mode=cors&url=' +
+ encodeURIComponent(remote_url + '?ACAOrigin=' +
+ host_info['HTTP_ORIGIN']),
+ true, SUCCESS
+ ]
+ ];
+ var promises = [];
+ var serial_tests = [];
+ for (var i = 0; i < TEST_CASES.length ; ++i) {
+ if (!TEST_CASES[i][3]) {
yhirano 2014/10/08 09:31:39 Why don't you run all test cases serially?
horo 2014/10/08 10:02:46 To reduce the execution time.
+ promises.push(create_test_promise(TEST_CASES[i][0],
+ TEST_CASES[i][1],
+ TEST_CASES[i][2]));
+ } else {
+ serial_tests.push(TEST_CASES[i]);
+ }
+ }
+ promises.push(create_serial_promise(serial_tests));
+ Promise.all(promises)
.then(function() {
port.postMessage({results: 'finish'});
})

Powered by Google App Engine
This is Rietveld 408576698