|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <meta name="viewport" content="width=device-width"> |
| 6 | + <title>Modify Cookies</title> |
| 7 | + <link rel="stylesheet" href="../../shared/style.css"> |
| 8 | + <script> |
| 9 | + // Current file path |
| 10 | + let path = '/webcompat/pages/' |
| 11 | + document.cookie = 'keyToBeDeleted="valueToBeDeleted"' |
| 12 | + document.cookie = 'pathCookie="valueToBeDeleted"; path=' + path |
| 13 | + document.cookie = 'pathCookieWithPath="valueToBeDeleted"; path=' + path |
| 14 | + document.cookie = 'otherKey="valueToRemain"' |
| 15 | + </script> |
| 16 | +</head> |
| 17 | +<body> |
| 18 | + <script src="../../shared/utils.js"></script> |
| 19 | + <p><a href="../index.html">[WebCompat]</a></p> |
| 20 | + |
| 21 | + <p>This page verifies that cookie modifications work properly given the <a href="../config/modify-cookies.json">config</a>. At this time, only deletion is supported.</p> |
| 22 | + |
| 23 | + <script> |
| 24 | + // Copy from: https://stackoverflow.com/a/2144404 |
| 25 | + function hasCookie(name){ |
| 26 | + return document.cookie.split(';').some(c => { |
| 27 | + return c.trim().startsWith(name + '='); |
| 28 | + }); |
| 29 | + } |
| 30 | + |
| 31 | + // eslint-disable-next-line no-undef |
| 32 | + test('Only specified cookies should be removed', async () => { |
| 33 | + const specifiedKey = hasCookie('keyToBeDeleted') |
| 34 | + const pathKey = hasCookie('pathCookie') |
| 35 | + const pathKey2 = hasCookie('pathCookie2') |
| 36 | + const pathKey3 = hasCookie('pathCookieWithPath') |
| 37 | + const nonexistentKey = hasCookie('nonexistentKey') |
| 38 | + const otherKey = hasCookie('otherKey') |
| 39 | + |
| 40 | + return [ |
| 41 | + { name: 'specified cookie entry deleted', result: specifiedKey, expected: false }, |
| 42 | + { name: 'specified cookie entry with path not deleted', result: pathKey, expected: true }, |
| 43 | + { name: `specified cookie entry with correct path (${path}) deleted`, result: pathKey3, expected: false }, |
| 44 | + { name: 'specified cookie entry that is not present on page load', result: nonexistentKey, expected: false }, |
| 45 | + { name: 'other cookie entry untouched', result: otherKey, expected: true } |
| 46 | + ]; |
| 47 | + }); |
| 48 | + |
| 49 | + // eslint-disable-next-line no-undef |
| 50 | + renderResults(); |
| 51 | + </script> |
| 52 | +</body> |
| 53 | +</html> |
0 commit comments