forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cookie-store: add tests for cross-origin
Ensure cookieStore changes propogate across origins Bug: 729800 Change-Id: Ife37521a548fc35711e5925621ea27ca44036559 Reviewed-on: https://chromium-review.googlesource.com/1212147 Commit-Queue: Jarryd Goodman <[email protected]> Reviewed-by: Victor Costan <[email protected]> Cr-Commit-Position: refs/heads/master@{#590847}
- Loading branch information
Showing
4 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...outTests/external/wpt/cookie-store/cookieStore_get_set_across_frames.tentative.https.html
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,40 @@ | ||
<!doctype html> | ||
<meta charset='utf-8'> | ||
<title>Async Cookies: cookieStore basic API across frames</title> | ||
<link rel='help' href='https://github.com/WICG/cookie-store'> | ||
<link rel='author' href='[email protected]' title='Jarryd Goodman'> | ||
<script src='/resources/testharness.js'></script> | ||
<script src='/resources/testharnessreport.js'></script> | ||
<style>iframe { display: none; }</style> | ||
<iframe id='iframe'></iframe> | ||
<script> | ||
'use strict'; | ||
|
||
promise_test(async t => { | ||
const iframe = document.getElementById('iframe'); | ||
const frameCookieStore = iframe.contentWindow.cookieStore; | ||
|
||
const oldCookie = await frameCookieStore.get('cookie-name'); | ||
assert_equals(oldCookie, null); | ||
|
||
await cookieStore.set('cookie-name', 'cookie-value'); | ||
t.add_cleanup(() => cookieStore.delete('cookie-name')); | ||
|
||
const frameCookie = await frameCookieStore.get('cookie-name'); | ||
assert_equals(frameCookie.value, 'cookie-value'); | ||
}, 'cookieStore.get() sees cookieStore.set() in frame'); | ||
|
||
promise_test(async t => { | ||
const iframe = document.getElementById('iframe'); | ||
const frameCookieStore = iframe.contentWindow.cookieStore; | ||
|
||
const oldCookie = await frameCookieStore.get('cookie-name'); | ||
assert_equals(oldCookie, null); | ||
|
||
await frameCookieStore.set('cookie-name', 'cookie-value'); | ||
t.add_cleanup(() => frameCookieStore.delete('cookie-name')); | ||
|
||
const cookie = await cookieStore.get('cookie-name'); | ||
assert_equals(cookie.value, 'cookie-value'); | ||
}, 'cookieStore.get() in frame sees cookieStore.set()') | ||
</script> |
63 changes: 63 additions & 0 deletions
63
...sts/external/wpt/cookie-store/cookieStore_get_set_across_origins.tentative.sub.https.html
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,63 @@ | ||
<!doctype html> | ||
<meta charset='utf-8'> | ||
<title>Async Cookies: cookieStore basic API across origins</title> | ||
<link rel='help' href='https://github.com/WICG/cookie-store'> | ||
<link rel='author' href='[email protected]' title='Jarryd Goodman'> | ||
<script src='/resources/testharness.js'></script> | ||
<script src='/resources/testharnessreport.js'></script> | ||
<script src='resources/helpers.js'></script> | ||
<style>iframe { display: none; }</style> | ||
|
||
<script> | ||
'use strict'; | ||
|
||
const kPath = '/cookie-store/resources/helper_iframe.sub.html'; | ||
const kCorsBase = `https://{{domains[www1]}}:{{ports[https][0]}}`; | ||
const kCorsUrl = `${kCorsBase}${kPath}`; | ||
|
||
promise_test(async t => { | ||
const iframe = await createIframe(kCorsUrl, t); | ||
assert_true(iframe != null); | ||
|
||
iframe.contentWindow.postMessage({ | ||
opname: 'set-cookie', | ||
name: 'cookie-name', | ||
value: 'cookie-value', | ||
}, kCorsBase); | ||
t.add_cleanup(() => { | ||
cookieStore.delete('cookie-name'); | ||
}); | ||
|
||
await waitForMessage(); | ||
|
||
const cookies = await cookieStore.getAll(); | ||
assert_equals(cookies.length, 1); | ||
assert_equals(cookies[0].name, 'cookie-name'); | ||
assert_equals(cookies[0].value, 'cookie-value'); | ||
}, 'cookieStore.get() sees cookieStore.set() in cross-origin frame'); | ||
|
||
promise_test(async t => { | ||
const iframe = await createIframe(kCorsUrl, t); | ||
assert_true(iframe != null); | ||
|
||
await cookieStore.set('cookie-name', 'cookie-value'); | ||
|
||
const cookie = await cookieStore.get('cookie-name'); | ||
assert_equals(cookie.value, 'cookie-value'); | ||
|
||
iframe.contentWindow.postMessage({ | ||
opname: 'get-cookie', | ||
name: 'cookie-name', | ||
}, kCorsBase); | ||
t.add_cleanup(() => { | ||
cookieStore.delete('cookie-name'); | ||
}) | ||
|
||
const message = await waitForMessage(); | ||
|
||
const { frameCookie } = message; | ||
assert_not_equals(frameCookie, null); | ||
assert_equals(frameCookie.name, 'cookie-name'); | ||
assert_equals(frameCookie.value, 'cookie-value'); | ||
}, 'cookieStore.get() in cross-origin frame sees cookieStore.set()'); | ||
</script> |
31 changes: 31 additions & 0 deletions
31
third_party/WebKit/LayoutTests/external/wpt/cookie-store/resources/helper_iframe.sub.html
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,31 @@ | ||
<!doctype html> | ||
<meta charset='utf-8'> | ||
<link rel='author' href='[email protected]' title='Jarryd Goodman'> | ||
<script> | ||
'use strict'; | ||
|
||
// Writing a cookie: | ||
// Input: { cookieToSet: { name: 'cookie-name', value: 'cookie-value' } } | ||
// Response: "Cookie has been set" | ||
// | ||
// Read a cookie. | ||
// Command: { existingCookieName: 'cookie-name' } | ||
// Response: Result of cookieStore.get(): | ||
// { frameCookie: { name: 'cookie-name', value: 'cookie-value' } } | ||
window.addEventListener('message', async function (event) { | ||
const { opname } = event.data; | ||
if (opname === 'set-cookie') { | ||
const { name, value } = event.data | ||
await cookieStore.set({ | ||
name, | ||
value, | ||
domain: '{{host}}', | ||
}); | ||
event.source.postMessage('Cookie has been set', event.origin); | ||
} else if (opname === 'get-cookie') { | ||
const { name } = event.data | ||
const frameCookie = await cookieStore.get(name); | ||
event.source.postMessage({frameCookie}, event.origin); | ||
} | ||
}); | ||
</script> |
24 changes: 24 additions & 0 deletions
24
third_party/WebKit/LayoutTests/external/wpt/cookie-store/resources/helpers.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,24 @@ | ||
/** | ||
* Promise based helper function who's return promise will resolve | ||
* once the iframe src has been loaded | ||
* @param {string} url the url to set the iframe src | ||
* @param {test} t a test object to add a cleanup function to | ||
* @return {Promise} when resolved, will return the iframe | ||
*/ | ||
self.createIframe = (url, t) => new Promise(resolve => { | ||
const iframe = document.createElement('iframe'); | ||
iframe.addEventListener('load', () => {resolve(iframe);}, {once: true}); | ||
iframe.src = url; | ||
document.documentElement.appendChild(iframe); | ||
t.add_cleanup(() => iframe.remove()); | ||
}); | ||
|
||
/** | ||
* Function that will return a promise that resolves when a message event | ||
* is fired. Returns a promise that resolves to the message that was received | ||
*/ | ||
self.waitForMessage = () => new Promise(resolve => { | ||
window.addEventListener('message', event => { | ||
resolve(event.data); | ||
}, {once: true}); | ||
}); |