credentials.sub.html (3932B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 6 <script> 7 document.cookie = 'same=1'; 8 9 const setCookiePromise = fetch( 10 'http://{{domains[www2]}}:{{ports[http][0]}}/cookies/resources/set-cookie.py?name=cross&path=/html/semantics/scripting-1/the-script-element/module/', 11 { 12 mode: 'no-cors', 13 credentials: 'include', 14 }); 15 16 const windowLoadPromise = new Promise(resolve => { 17 window.addEventListener('load', () => { 18 resolve(); 19 }); 20 }); 21 22 promise_test(t => { 23 const iframe = document.createElement('iframe'); 24 25 return Promise.all([setCookiePromise, windowLoadPromise]).then(() => { 26 const messagePromise = new Promise(resolve => { 27 window.addEventListener('message', event => { 28 resolve(); 29 }); 30 }); 31 32 iframe.src = 'resources/credentials-iframe.sub.html'; 33 document.body.appendChild(iframe); 34 35 return messagePromise; 36 }).then(() => { 37 const w = iframe.contentWindow; 38 39 assert_equals(w.sameOriginNone, 'found', 40 'Modules should be loaded with the credentials when the crossOrigin attribute is not specified and the target is same-origin'); 41 assert_equals(w.sameOriginAnonymous, 'found', 42 'Modules should be loaded with the credentials when the crossOrigin attribute is specified with "anonymous" as its value and the target is same-origin'); 43 assert_equals(w.sameOriginUseCredentials, 'found', 44 'Modules should be loaded with the credentials when the crossOrigin attribute is specified with "use-credentials" as its value and the target is same-origin'); 45 assert_equals(w.crossOriginNone, 'not found', 46 'Modules should not be loaded with the credentials when the crossOrigin attribute is not specified and the target is cross-origin'); 47 assert_equals(w.crossOriginAnonymous, 'not found', 48 'Modules should not be loaded with the credentials when the crossOrigin attribute is specified with "anonymous" as its value and the target is cross-origin'); 49 assert_equals(w.crossOriginUseCredentials, 'found', 50 'Modules should be loaded with the credentials when the crossOrigin attribute is specified with "use-credentials" as its value and the target is cross-origin'); 51 52 assert_equals(w.sameOriginNoneDescendant, 'found', 53 'Descendant modules should be loaded with the credentials when the crossOrigin attribute is not specified and the target is same-origin'); 54 assert_equals(w.sameOriginAnonymousDescendant, 'found', 55 'Descendant modules should be loaded with the credentials when the crossOrigin attribute is specified with "anonymous" as its value and the target is same-origin'); 56 assert_equals(w.sameOriginUseCredentialsDescendant, 'found', 57 'Descendant modules should be loaded with the credentials when the crossOrigin attribute is specified with "use-credentials" as its value and the target is same-origin'); 58 assert_equals(w.crossOriginNoneDescendant, 'not found', 59 'Descendant modules should not be loaded with the credentials when the crossOrigin attribute is not specified and the target is cross-origin'); 60 assert_equals(w.crossOriginAnonymousDescendant, 'not found', 61 'Descendant modules should not be loaded with the credentials when the crossOrigin attribute is specified with "anonymous" as its value and the target is cross-origin'); 62 assert_equals(w.crossOriginUseCredentialsDescendant, 'found', 63 'Descendant modules should be loaded with the credentials when the crossOrigin attribute is specified with "use-credentials" as its value and the target is cross-origin'); 64 }); 65 }, 'Modules should be loaded with or without the credentials based on the same-origin-ness and the crossOrigin attribute'); 66 </script> 67 <body> 68 </body>