Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions cookiestore/cookieStore_set_path.https.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// META: title=Cookie Store API: set()'s path option
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js

promise_test(async testCase => {
const currentUrl = new URL(self.location.href);
const currentPath = currentUrl.pathname;
const currentDirectory = currentPath.substr(0, currentPath.lastIndexOf('/'));

await cookieStore.set({ name: 'cookie-name', value: 'cookie-value', path: '' });
testCase.add_cleanup(async () => {
await cookieStore.delete({ name: 'cookie-name', path: currentDirectory });
});

const internalCookie = await test_driver.get_named_cookie('cookie-name');
assert_equals(internalCookie.path, currentDirectory);
}, 'CookieListItem - cookieStore.set with empty string path defaults to current URL');

promise_test(async testCase => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this one, why is the cookie rejected? Doesn't this pose some back-compat risk?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It rejects in Chrome today. The reason is that the path becomes /cookiestore and it has to be / for a __host--prefixed cookie.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Optionally, it might be worthwhile to add a comment to that effect.

const currentUrl = new URL(self.location.href);
const currentPath = currentUrl.pathname;
return promise_rejects_js(testCase, TypeError, cookieStore.set({ name: '__host-cookie-name', value: 'cookie-value', path: '' }));
}, 'CookieListItem - cookieStore.set with empty string path defaults to current URL with __host- prefix');