document-cookie.non-secure.html (2465B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="/cookies/resources/cookie-helper.sub.js"></script> 5 <script> 6 let counter = 0; 7 function create_test(prefix, params, shouldExistInDOM, shouldExistViaHTTP, title) { 8 promise_test(t => { 9 var name = prefix + "prefixtestcookie"; 10 erase_cookie_from_js(name, params); 11 t.add_cleanup(() => erase_cookie_from_js(name, params)); 12 var value = "foo" + ++counter; 13 document.cookie = name + "=" + value + ";" + params; 14 15 assert_dom_cookie(name, value, shouldExistInDOM); 16 17 return credFetch("/cookies/resources/list.py") 18 .then(r => r.json()) 19 .then(cookies => assert_equals(cookies[name], shouldExistViaHTTP ? value : undefined)); 20 }, title); 21 } 22 23 // No prefix 24 create_test("", "path=/", true, true, "No prefix, root path, no special behavior"); 25 create_test("", "path=/;domain=" + document.location.hostname, true, true, "No prefix, domain, no special behavior"); 26 27 // `__Secure-` Prefix 28 ["", "domain="+document.location.hostname, "MaxAge=10", "HttpOnly"].forEach(params => { 29 create_test("__Secure-", "Path=/;" + params, false, false, "__Secure: Non-secure origin: 'Path=/;" + params + "'"); 30 create_test("__SeCuRe-", "Path=/;" + params, false, false, "__SeCuRe: Non-secure origin: 'Path=/;" + params + "'"); 31 create_test("__Secure-", "Secure; Path=/;" + params, false, false, "__Secure: Non-secure origin: 'Secure; Path=/;" + params + "'"); 32 create_test("__SeCuRe-", "Secure; Path=/;" + params, false, false, "__SeCuRe: Non-secure origin: 'Secure; Path=/;" + params + "'"); 33 }); 34 35 // `__Host-` Prefix 36 ["", "domain="+document.location.hostname, "MaxAge=10", "HttpOnly"].forEach(params => { 37 create_test("__Host-", "Path=/;" + params, false, false, "__Host: Non-secure origin: 'Path=/; " + params + "'"); 38 create_test("__HoSt-", "Path=/;" + params, false, false, "__HoSt: Non-secure origin: 'Path=/; " + params + "'"); 39 create_test("__Host-", "Secure; Path=/;" + params, false, false, "__Host: Non-secure origin: 'Secure; Path=/; " + params + "'"); 40 create_test("__HoSt-", "Secure; Path=/;" + params, false, false, "__HoSt: Non-secure origin: 'Secure; Path=/; " + params + "'"); 41 }); 42 create_test("__Secure-", "Path=/cookies/resources/list.py;Secure", false, false, "__Host: Non-secure origin: 'Path=/cookies/resources/list.py;Secure'"); 43 </script>