Commit 1ffd9219 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

Worklet: Add tests for WorkletOptions

Bug: 738769
Change-Id: I8e15f7c05d64a98e6fdd7e3b69e2047902e04aad
Reviewed-on: https://chromium-review.googlesource.com/694723Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512768}
parent 950b1bca
<!DOCTYPE html>
<html>
<head>
<script src="/common/get-host-info.sub.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/worklet-test-utils.js"></script>
<script src="resources/credentials-tests.js"></script>
</head>
<body>
<script>
runCredentialsTests("animation");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script src="/common/get-host-info.sub.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/worklet-test-utils.js"></script>
<script src="resources/credentials-tests.js"></script>
</head>
<body>
<script>
runCredentialsTests("paint");
</script>
</body>
</html>
// Runs a series of tests related to credentials on a worklet.
//
// Usage:
// runCredentialsTests("paint");
function runCredentialsTests(worklet_type) {
const worklet = get_worklet(worklet_type);
promise_test(() => {
document.cookie = 'cookieName=default';
const kScriptURL = 'resources/credentials.py?mode=default';
return worklet.addModule(kScriptURL).then(undefined_arg => {
assert_equals(undefined_arg, undefined);
});
}, 'Importing a same-origin script with the default WorkletOptions should ' +
'omit the credentials');
promise_test(() => {
const kSetCookieURL =
get_host_info().HTTP_REMOTE_ORIGIN +
'/worklets/resources/set-cookie.py?name=cookieName';
const kScriptURL = get_host_info().HTTP_REMOTE_ORIGIN +
'/worklets/resources/credentials.py?mode=default';
const kOptions = { credentials: 'same-origin' };
// Set a cookie in the remote origin and then start a worklet.
return fetch(kSetCookieURL, { mode: 'cors' })
.then(() => worklet.addModule(kScriptURL, kOptions))
.then(undefined_arg => assert_equals(undefined_arg, undefined));
}, 'Importing a remote-origin script with the default WorkletOptions ' +
'should not include the credentials');
promise_test(() => {
document.cookie = 'cookieName=omit';
const kScriptURL = 'resources/credentials.py?mode=omit';
const kOptions = { credentials: 'omit' };
return worklet.addModule(kScriptURL, kOptions).then(undefined_arg => {
assert_equals(undefined_arg, undefined);
});
}, 'Importing a same-origin script with credentials=omit should omit the ' +
'credentials');
promise_test(() => {
const kSetCookieURL =
get_host_info().HTTP_REMOTE_ORIGIN +
'/worklets/resources/set-cookie.py?name=cookieName';
const kScriptURL = get_host_info().HTTP_REMOTE_ORIGIN +
'/worklets/resources/credentials.py?mode=omit';
const kOptions = { credentials: 'omit' };
// Set a cookie in the remote origin and then start a worklet.
return fetch(kSetCookieURL, { mode: 'cors' })
.then(() => worklet.addModule(kScriptURL, kOptions))
.then(undefined_arg => assert_equals(undefined_arg, undefined));
}, 'Importing a remote-origin script with credentials=omit should omit the ' +
'credentials');
promise_test(() => {
document.cookie = 'cookieName=same-origin';
const kScriptURL = 'resources/credentials.py?mode=same-origin';
const kOptions = { credentials: 'same-origin' };
return worklet.addModule(kScriptURL, kOptions).then(undefined_arg => {
assert_equals(undefined_arg, undefined);
});
}, 'Importing a same-origin script with credentials=same-origin should ' +
'include the credentials');
promise_test(() => {
const kSetCookieURL =
get_host_info().HTTP_REMOTE_ORIGIN +
'/worklets/resources/set-cookie.py?name=cookieName';
const kScriptURL = get_host_info().HTTP_REMOTE_ORIGIN +
'/worklets/resources/credentials.py?mode=same-origin';
const kOptions = { credentials: 'same-origin' };
// Set a cookie in the remote origin and then start a worklet.
return fetch(kSetCookieURL, { mode: 'cors' })
.then(() => worklet.addModule(kScriptURL, kOptions))
.then(undefined_arg => assert_equals(undefined_arg, undefined));
}, 'Importing a remote-origin script with credentials=same-origin should ' +
'not include the credentials');
promise_test(() => {
document.cookie = 'cookieName=include';
const kScriptURL = 'resources/credentials.py?mode=include';
const kOptions = { credentials: 'include' };
return worklet.addModule(kScriptURL, kOptions).then(undefined_arg => {
assert_equals(undefined_arg, undefined);
});
}, 'Importing a same-origin script with credentials=include should include ' +
'the credentials');
promise_test(() => {
const kSetCookieURL =
get_host_info().HTTP_REMOTE_ORIGIN +
'/worklets/resources/set-cookie.py?name=cookieName';
const kScriptURL = get_host_info().HTTP_REMOTE_ORIGIN +
'/worklets/resources/credentials.py?mode=include';
const kOptions = { credentials: 'include' };
// Set a cookie in the remote origin and then start a worklet.
return fetch(kSetCookieURL, { mode: 'cors' })
.then(() => worklet.addModule(kScriptURL, kOptions))
.then(undefined_arg => assert_equals(undefined_arg, undefined));
}, 'Importing a remote-origin script with credentials=include should ' +
'include the credentials');
}
# Returns a valid response when a request has appropriate credentials.
def main(request, response):
credentials_mode = request.GET.first("mode")
cookie = request.cookies.first("cookieName", None)
source_origin = request.headers.get("origin", None);
is_cross_origin = request.GET.first("is_cross_origin", False)
# The request with the default WorkletOptions should not include the cookie.
if credentials_mode is "default" and cookie is not None:
return (404)
# The request with "credentials=omit" should not include the cookie.
if credentials_mode is "omit" and cookie is not None:
return (404)
if credentials_mode is "same-origin":
# The cross-origin request with "credentials=same-origin" should not
# include the cookie.
if is_cross_origin and cookie is not None:
return (404)
# The same-origin request with "credentials=same-origin" should include
# the cookie.
if not is_cross_origin and cookie is None:
return (404)
# The request with "credentials=include" should include the cookie.
if credentials_mode is "include" and cookie is None:
return (404)
return (200, [("Content-Type", "text/javascript"),
("Access-Control-Allow-Origin", source_origin),
("Access-Control-Allow-Credentials", "true")], "")
def main(request, response):
name = request.GET.first("name")
source_origin = request.headers.get("origin", None);
response.headers.set("Set-Cookie", name + "=value")
response.headers.set("Access-Control-Allow-Origin", source_origin)
response.headers.set("Access-Control-Allow-Credentials", "true")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment