resource.html (2756B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="support/test_utils.sub.js"></script> 7 </head> 8 9 <body> 10 <script> 11 /** 12 * @typedef{TestCase} 13 * @type{object} 14 * @property{string} frame The scheme of the url of the iframe. 15 * @property{string} resource The scheme of the resource in the iframe. 16 * @property{boolean} deleted Whether it is expected that Clear-Site-Data 17 * will be respected when loading |resource| in |frame|. 18 */ 19 var TestCase; 20 21 /** Array<TestCase> Test cases. */ 22 var test_cases = [ 23 { "frame": "https", "resource": "https", "deleted": true }, 24 { "frame": "http", "resource": "https", "deleted": true }, 25 { "frame": "https", "resource": "http", "deleted": false }, 26 { "frame": "http", "resource": "http", "deleted": false }, 27 ]; 28 29 /** 30 * @param TestCase test_case The test case that is tested. 31 * @param Dict.<string, boolean> report A map between a datatype name and 32 * whether it is empty. 33 */ 34 function verifyDatatypes(test_case, report) { 35 if (test_case.deleted) { 36 assert_true( 37 report["storage"], 38 "Storage should have been cleared."); 39 } else { 40 assert_false( 41 report["storage"], 42 "Storage should NOT have been cleared."); 43 } 44 } 45 46 test_cases.forEach(function(test_case) { 47 var test_name = 48 test_case.resource + " resource on a " + test_case.frame + " page"; 49 50 promise_test(function(test) { 51 return new Promise(function(resolve_test, reject_test) { 52 TestUtils.populateDatatypes() 53 .then(function() { 54 // Navigate to a page with a resource that is loaded with 55 // the Clear-Site-Data header, then verify that storage 56 // has been deleted if and only if the resource was loaded 57 // via HTTPS. 58 return new Promise(function(resolve, reject) { 59 window.addEventListener("message", resolve); 60 var iframe = document.createElement("iframe"); 61 iframe.src = TestUtils.getPageWithResourceUrl( 62 test_case.frame, test_case.resource); 63 document.body.appendChild(iframe); 64 }).then(function(messageEvent) { 65 verifyDatatypes(test_case, messageEvent.data); 66 resolve_test(); 67 }); 68 }); 69 }); 70 }, test_name); 71 }); 72 </script> 73 </body> 74 </html>