-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run Web Platform Tests against the polyfill. (#88)
* Throw TypeError if get is called without arguments See step 4 in "The get(options) method" section in the [CookieStore Spec][cookiestore]: >If options is empty, then return a promise rejected with a TypeError. [cookiestore]: https://wicg.github.io/cookie-store/#ref-for-dom-cookiestore-get-options%E2%91%A4 * Refactor sanitizeOptions to use TypeScript generics * Implement getting a cookie by URL * Add cookieStore get arguments WPT tests * Set `assert_equals` variable directly * Actually parse URL and check its origin
- Loading branch information
1 parent
dd52f45
commit 9f603bc
Showing
5 changed files
with
182 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* global assert */ | ||
|
||
window.promise_test = async (fn, name) => { | ||
const cleanups = []; | ||
const testCase = { | ||
name, | ||
add_cleanup(fn) { | ||
cleanups.push(fn); | ||
}, | ||
}; | ||
it(name, async () => { | ||
await fn(testCase); | ||
for (const cleanup of cleanups) { | ||
cleanup(); | ||
} | ||
}); | ||
}; | ||
|
||
window.promise_rejects_js = async (testCase, expectedError, promise) => { | ||
try { | ||
await promise; | ||
} catch (error) { | ||
if (error.name !== expectedError.name) { | ||
assert.fail( | ||
`${testCase.name}: Promise rejected with ${error.name}, expected ${expectedError.name}` | ||
); | ||
} | ||
return; | ||
} | ||
assert.fail(`${testCase.name}: Promise didn't reject when it should have.`); | ||
}; | ||
|
||
window.assert_equals = assert.equal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
self.GLOBAL = { | ||
isWindow: () => false, | ||
isWorker: () => false, | ||
}; | ||
|
||
self.addEventListener('message', async event => { | ||
if (event.data.op === 'get-cookies') { | ||
const workerCookies = await cookieStore.getAll(); | ||
event.ports[0].postMessage({ workerCookies }, { | ||
domain: event.origin, | ||
}); | ||
} | ||
}); |
107 changes: 107 additions & 0 deletions
107
test/wpt/cookieStore_get_arguments.tentative.https.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// META: title=Cookie Store API: cookieStore.get() arguments | ||
// META: global=window,serviceworker | ||
|
||
'use strict'; | ||
|
||
promise_test(async (testCase) => { | ||
await cookieStore.set('cookie-name', 'cookie-value'); | ||
testCase.add_cleanup(async () => { | ||
await cookieStore.delete('cookie-name'); | ||
}); | ||
|
||
await promise_rejects_js(testCase, TypeError, cookieStore.get()); | ||
}, 'cookieStore.get with no arguments returns TypeError'); | ||
|
||
promise_test(async (testCase) => { | ||
await cookieStore.set('cookie-name', 'cookie-value'); | ||
testCase.add_cleanup(async () => { | ||
await cookieStore.delete('cookie-name'); | ||
}); | ||
|
||
await promise_rejects_js(testCase, TypeError, cookieStore.get({})); | ||
}, 'cookieStore.get with empty options returns TypeError'); | ||
|
||
promise_test(async (testCase) => { | ||
await cookieStore.set('cookie-name', 'cookie-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, 'cookie-value'); | ||
}, 'cookieStore.get with positional name'); | ||
|
||
promise_test(async (testCase) => { | ||
await cookieStore.set('cookie-name', 'cookie-value'); | ||
testCase.add_cleanup(async () => { | ||
await cookieStore.delete('cookie-name'); | ||
}); | ||
|
||
const cookie = await cookieStore.get({ name: 'cookie-name' }); | ||
assert_equals(cookie.name, 'cookie-name'); | ||
assert_equals(cookie.value, 'cookie-value'); | ||
}, 'cookieStore.get with name in options'); | ||
|
||
promise_test(async (testCase) => { | ||
await cookieStore.set('cookie-name', 'cookie-value'); | ||
testCase.add_cleanup(async () => { | ||
await cookieStore.delete('cookie-name'); | ||
}); | ||
|
||
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) => { | ||
await cookieStore.set('cookie-name', 'cookie-value'); | ||
testCase.add_cleanup(async () => { | ||
await cookieStore.delete('cookie-name'); | ||
}); | ||
|
||
let target_url = self.location.href; | ||
if (self.GLOBAL.isWorker()) { | ||
target_url = target_url + '/path/within/scope'; | ||
} | ||
|
||
const cookie = await cookieStore.get({ url: target_url }); | ||
assert_equals(cookie.name, 'cookie-name'); | ||
assert_equals(cookie.value, 'cookie-value'); | ||
}, 'cookieStore.get with absolute url in options'); | ||
|
||
promise_test(async (testCase) => { | ||
await cookieStore.set('cookie-name', 'cookie-value'); | ||
testCase.add_cleanup(async () => { | ||
await cookieStore.delete('cookie-name'); | ||
}); | ||
|
||
let target_path = self.location.pathname; | ||
if (self.GLOBAL.isWorker()) { | ||
target_path = target_path + '/path/within/scope'; | ||
} | ||
|
||
const cookie = await cookieStore.get({ url: target_path }); | ||
assert_equals(cookie.name, 'cookie-name'); | ||
assert_equals(cookie.value, 'cookie-value'); | ||
}, 'cookieStore.get with relative url in options'); | ||
|
||
promise_test(async (testCase) => { | ||
const invalid_url = `${self.location.protocol}//${self.location.host}/different/path`; | ||
await promise_rejects_js( | ||
testCase, | ||
TypeError, | ||
cookieStore.get({ url: invalid_url }) | ||
); | ||
}, 'cookieStore.get with invalid url path in options'); | ||
|
||
promise_test(async (testCase) => { | ||
const invalid_url = `${self.location.protocol}//www.example.com${self.location.pathname}`; | ||
await promise_rejects_js( | ||
testCase, | ||
TypeError, | ||
cookieStore.get({ url: invalid_url }) | ||
); | ||
}, 'cookieStore.get with invalid url host in options'); |