summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/cookies/path
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/cookies/path
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/cookies/path')
-rw-r--r--testing/web-platform/tests/cookies/path/default.html51
-rw-r--r--testing/web-platform/tests/cookies/path/match.html113
2 files changed, 164 insertions, 0 deletions
diff --git a/testing/web-platform/tests/cookies/path/default.html b/testing/web-platform/tests/cookies/path/default.html
new file mode 100644
index 0000000000..dbe99a7ee5
--- /dev/null
+++ b/testing/web-platform/tests/cookies/path/default.html
@@ -0,0 +1,51 @@
+<!doctype html>
+<html>
+<head>
+ <meta charset=utf-8>
+ <title>Test for default cookie path</title>
+ <meta name=help href="http://tools.ietf.org/html/rfc6265#section-5.1.4">
+
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/resources/testdriver.js"></script>
+ <script src="/resources/testdriver-vendor.js"></script>
+</head>
+<body>
+<div id=log></div>
+
+<script>
+var body = document.getElementsByTagName('body')[0];
+var createIframe = function (src, done) {
+ var iframe = document.createElement('iframe');
+ iframe.src = src;
+ body.appendChild(iframe);
+ iframe.onload = function () {
+ done(iframe);
+ };
+};
+
+async_test(function (t) {
+ var iframe;
+ var verify = t.step_func(function () {
+ assert_true(
+ !!iframe.contentWindow.isCookieSet('cookies-path-default'),
+ 'cookie can be retrieved from expected path'
+ );
+ iframe.contentWindow.expireCookies().then(t.step_func(function () {
+ assert_false(
+ !!iframe.contentWindow.isCookieSet('cookies-path-default'),
+ 'cookie can be referenced using the expected path'
+ );
+ t.done();
+ }));
+ });
+
+ createIframe('/cookies/resources/echo-cookie.html', t.step_func(function (_iframe) {
+ iframe = _iframe;
+
+ createIframe('/cookies/resources/set.py?cookies-path-default=1', verify);
+ }));
+});
+</script>
+</body>
+</html>
diff --git a/testing/web-platform/tests/cookies/path/match.html b/testing/web-platform/tests/cookies/path/match.html
new file mode 100644
index 0000000000..d517836e4d
--- /dev/null
+++ b/testing/web-platform/tests/cookies/path/match.html
@@ -0,0 +1,113 @@
+<!doctype html>
+<html>
+<head>
+ <meta charset=utf-8>
+ <title>tests for matching cookie paths</title>
+ <meta name="timeout" content="long">
+ <meta name=help href="http://tools.ietf.org/html/rfc6265#section-5.1.4">
+
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/resources/testdriver.js"></script>
+ <script src="/resources/testdriver-vendor.js"></script>
+ <script src="/cookies/resources/testharness-helpers.js"></script>
+</head>
+<body>
+<div id=log></div>
+
+<script>
+var body = document.getElementsByTagName('body')[0];
+var createIframeThen = function (callback) {
+ var iframe = document.createElement('iframe');
+ iframe.src = "/cookies/resources/echo-cookie.html";
+ body.appendChild(iframe);
+ iframe.onload = callback;
+ return iframe;
+};
+var testCookiePathFromDOM = function (testCase, test) {
+ var iframe = createIframeThen(test.step_func(function () {
+ iframe.contentWindow.setCookie('dom-' + testCase.name, testCase.path);
+ var cookieSet = iframe.contentWindow.isCookieSet('dom-' + testCase.name, testCase.path);
+ if (testCase.match === false) {
+ assert_equals(cookieSet, null);
+ } else {
+ assert_not_equals(cookieSet, null, "Cookie path from DOM should not be `null`");
+ }
+ iframe.contentWindow.expireCookies().then(() => test.done());
+ }));
+};
+var testCookiePathFromHeader = function (testCase, test) {
+ var iframe = createIframeThen(test.step_func(function () {
+ iframe.contentWindow.fetchCookieThen('header-' + testCase.name, testCase.path).then(test.step_func(function (response) {
+ assert_true(response.ok);
+ var cookieSet = iframe.contentWindow.isCookieSet('header-' + testCase.name, testCase.path);
+ iframe.contentWindow.expireCookies().then(test.step_func(function () {
+ if (testCase.match === false) {
+ assert_equals(cookieSet, null);
+ } else {
+ assert_not_equals(cookieSet, null, "Cookie path from header should not be `null`");
+ }
+ test.done();
+ }));
+ })).catch(test.unreached_func());
+ }));
+};
+
+var tests = [{
+ "name": "match-slash",
+ "path": "/",
+}, {
+ "name": "match-page",
+ "path": "match.html",
+}, {
+ "name": "match-prefix",
+ "path": "cookies",
+}, {
+ "name": "match-slash-prefix",
+ "path": "/cookies",
+}, {
+ "name": "match-slash-prefix-slash",
+ "path": "/cookies/",
+}, {
+ "name": "match-exact-page",
+ "path": "/cookies/resources/echo-cookie.html",
+}, {
+ "name": "no-match",
+ "path": "/cook",
+ "match": false
+}, {
+ "name": "no-match-subpath",
+ "path": "/w/",
+ "match": false
+}];
+
+var domTests = tests.map(function (testCase) {
+ var testName = "`document.cookie` on /cookies/resources/echo-cookie.html sets cookie with path: " + testCase.path;
+ if (testCase.match === false) {
+ testName = "`document.cookie` on /cookies/resources/echo-cookie.html DOES NOT set cookie for path: " + testCase.path;
+ }
+ return [
+ testName,
+ function () {
+ testCookiePathFromDOM(testCase, this);
+ }
+ ];
+});
+
+var headerTests = tests.map(function (testCase) {
+ var testName = "`Set-Cookie` on /cookies/resources/echo-cookie.html sets cookie with path: " + testCase.path;
+ if (testCase.match === false) {
+ testName = "`Set-Cookie` on /cookies/resources/echo-cookie.html DOES NOT set cookie for path: " + testCase.path;
+ }
+ return [
+ testName,
+ function () {
+ testCookiePathFromHeader(testCase, this);
+ }
+ ];
+});
+
+executeTestsSerially(domTests.concat(headerTests));
+</script>
+</body>
+</html>