idb-partitioned-basic.sub.html (2189B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>IndexedDB: partitioned storage test</title> 4 <meta name=help href="https://privacycg.github.io/storage-partitioning/"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <iframe id="shared-iframe" src="http://{{host}}:{{ports[http][0]}}/IndexedDB/resources/idb-partitioned-basic-iframe.html"></iframe> 8 <body> 9 <script> 10 // Here's the set-up for this test: 11 // Step 1. (window) set up listeners for main window. 12 // Step 2. (same-site iframe) loads, creates a database, and sends "same-site iframe loaded" message. 13 // Step 3. (window) receives "same-site iframe loaded" message and opens cross-site window. 14 // Step 4. (cross-site iframe) loads, checks if database exists, and sends "cross-site iframe loaded" message. 15 // Step 5. (window) receives "cross-site iframe loaded" message, asserts that database should not exist, sends "delete database" message. 16 // Step 6. (same-site iframe) receives "delete database" message, deletes the database, sends "database deleted" message. 17 // Step 7. (window) receives the "database deleted" and then exits. 18 const altOrigin = "http://{{hosts[alt][]}}:{{ports[http][0]}}"; 19 20 async_test(t => { 21 const iframe = document.getElementById("shared-iframe"); 22 23 // Step 1 24 window.addEventListener("message", t.step_func(e => { 25 26 // Step 3 27 if (e.data.message === "same-site iframe loaded") { 28 if (location.origin !== altOrigin) { 29 const crossSiteWindow = window.open(`${altOrigin}/IndexedDB/idb-partitioned-basic.sub.html`, "", "noopener=false"); 30 t.add_cleanup(() => crossSiteWindow.close()); 31 } 32 } 33 34 // Step 5 35 if (e.data.message === "cross-site iframe loaded") { 36 t.step(() => { 37 assert_false( 38 e.data.doesDatabaseExist, 39 "The cross-site iframe should not see the same-site database", 40 ); 41 }); 42 iframe.contentWindow.postMessage( 43 {message: "delete database"}, 44 iframe.contentWindow.origin, 45 ); 46 }; 47 48 // Step 7 49 if (e.data.message === "database deleted") { 50 t.done(); 51 }; 52 })); 53 }, "Simple test for partitioned IndexedDB"); 54 </script> 55 </body>