Commit 37f165b7 authored by Ayu Ishii's avatar Ayu Ishii Committed by Commit Bot

CookieStore: Additional wpt tests + cleanup

This chance adds some minor cleanup and a few additional test cases.

Change-Id: I938afe6d596bdbe4c6a520ab76622dfc3f6f3f99
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2137486
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759605}
parent 0e29f057
......@@ -6,10 +6,11 @@
cookie_test(async t => {
let eventPromise = observeNextCookieChangeEvent();
await cookieStore.set('', 'first-value');
assert_equals(
(await cookieStore.getAll('')).map(({ value }) => value).join(';'),
'first-value',
'Cookie with no name and normal value should have been set');
const initialCookies = await cookieStore.getAll('');
assert_equals(initialCookies.length, 1);
assert_equals(initialCookies[0].name, '');
assert_equals(initialCookies[0].value, 'first-value');
await verifyCookieChangeEvent(
eventPromise, {changed: [{name: '', value: 'first-value'}]},
'Observed no-name change');
......@@ -29,10 +30,11 @@ cookie_test(async t => {
'Expected promise rejection when setting a cookie with' +
' no name and "=" in value (via options)');
assert_equals(
(await cookieStore.getAll('')).map(({ value }) => value).join(';'),
'first-value',
'Cookie with no name should still have previous value');
const cookies = await cookieStore.getAll('');
assert_equals(cookies.length, 1);
assert_equals(cookies[0].name, '');
assert_equals(cookies[0].value, 'first-value',
'Cookie with no name should still have previous value.');
eventPromise = observeNextCookieChangeEvent();
await cookieStore.delete('');
......
......@@ -14,6 +14,21 @@ promise_test(async testCase => {
assert_equals(cookie.value, 'cookie-value');
}, 'cookieStore.get with no arguments');
promise_test(async testCase => {
await cookieStore.set('cookie-name-1', 'cookie-value-1');
testCase.add_cleanup(async () => {
await cookieStore.delete('cookie-name-1');
});
await cookieStore.set('cookie-name-2', 'cookie-value-2');
testCase.add_cleanup(async () => {
await cookieStore.delete('cookie-name-2');
});
const cookie = await cookieStore.get();
assert_equals(cookie.name, 'cookie-name-1');
assert_equals(cookie.value, 'cookie-value-1');
},'cookieStore.get with no args and multiple matches');
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
testCase.add_cleanup(async () => {
......@@ -44,6 +59,8 @@ promise_test(async testCase => {
const cookie = await cookieStore.get('cookie-name',
{ name: 'wrong-cookie-name' });
assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'cookie-value');
}, 'cookieStore.get with name in both positional arguments and options');
promise_test(async testCase => {
......
......@@ -40,6 +40,22 @@ promise_test(async testCase => {
assert_equals(cookie.value, 'cookie-value');
}, 'cookieStore.set with name in both positional arguments and options');
promise_test(async testCase => {
await promise_rejects_js(testCase, TypeError,
cookieStore.set('', 'suspicious-value=resembles-name-and-value'));
}, "cookieStore.set with empty name and an '=' in value");
promise_test(async testCase => {
await cookieStore.delete('cookie-name');
cookieStore.set('cookie-name', 'suspicious-value=resembles-name-and-value');
testCase.add_cleanup(async () => {
await cookieStore.delete('cookie-name');
});
const cookie = await cookieStore.get('cookie-name');
assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'suspicious-value=resembles-name-and-value');
}, "cookieStore.set with normal name and an '=' in value");
promise_test(async testCase => {
await cookieStore.delete('cookie-name');
......
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