forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookieStore_get_arguments.tentative.https.window.js
105 lines (76 loc) · 3.71 KB
/
cookieStore_get_arguments.tentative.https.window.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
'use strict';
// Workaround because add_cleanup doesn't support async functions yet.
// See https://github.com/web-platform-tests/wpt/issues/6075
async function async_cleanup(cleanup_function) {
try {
await cleanup_function();
} catch (e) {
// Errors in cleanup functions shouldn't result in test failures.
}
}
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
const cookie = await cookieStore.get();
assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'cookie-value');
await async_cleanup(() => cookieStore.delete('cookie-name'));
}, 'cookieStore.get with no arguments');
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
const cookie = await cookieStore.get('cookie-name');
assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'cookie-value');
await async_cleanup(() => cookieStore.delete('cookie-name'));
}, 'cookieStore.get with positional name');
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
const cookie = await cookieStore.get({ name: 'cookie-name' });
assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'cookie-value');
await async_cleanup(() => cookieStore.delete('cookie-name'));
}, 'cookieStore.get with name in options');
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
const cookie = await cookieStore.get('cookie-name',
{ name: 'wrong-cookie-name' });
await async_cleanup(() => cookieStore.delete('cookie-name'));
}, 'cookieStore.get with name in both positional arguments and options');
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
const cookie = await cookieStore.get(
'cookie-name', { matchType: 'equals' });
assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'cookie-value');
const no_cookie = await cookieStore.get({ name: 'cookie-na',
matchType: 'equals' });
assert_equals(no_cookie, null);
await async_cleanup(() => cookieStore.delete('cookie-name'));
}, 'cookieStore.get with matchType explicitly set to equals');
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
const cookie = await cookieStore.get({ name: 'cookie-na',
matchType: 'starts-with' });
assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'cookie-value');
async_cleanup(() => cookieStore.delete('cookie-name'));
}, 'cookieStore.get with matchType set to starts-with');
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
await promise_rejects(testCase, new TypeError(), cookieStore.get(
{ name: 'cookie-name', matchType: 'invalid' }));
await async_cleanup(() => cookieStore.delete('cookie-name'));
}, 'cookieStore.get with invalid matchType');
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
const cookie = await cookieStore.get({ matchType: 'equals' });
assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'cookie-value');
async_cleanup(() => cookieStore.delete('cookie-name'));
}, 'cookieStore.get with matchType set to equals and missing name');
promise_test(async testCase => {
await cookieStore.set('cookie-name', 'cookie-value');
const cookie = await cookieStore.get({ matchType: 'starts-with' });
assert_equals(cookie.name, 'cookie-name');
assert_equals(cookie.value, 'cookie-value');
async_cleanup(() => cookieStore.delete('cookie-name'));
}, 'cookieStore.get with matchType set to starts-with and missing name');