idb-partitioned-persistence.sub.html (2239B)
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="iframe1"></iframe> 8 <iframe id="iframe2"></iframe> 9 <body> 10 <script> 11 // Here's the set-up for this test: 12 // Step 1. (window) set up listeners for main window. 13 // Step 2. (iframe1 & iframe2) loads and sends "iframe loaded" message. 14 // Step 3. (window) receives two "iframe loaded" message and sends "create database" message to iframe1. 15 // Step 4. (iframe1) receives "create database", creates database, and sends "database created" message. 16 // Step 5. (window) receives "database created" message and sends "check database" message to iframe2. 17 // Step 6. (iframe2) receives "check database" message, checks if database exists, sends "database checked" message. 18 // Step 7. (window) receives the "database checked" message, asserts database existed, and then exits. 19 20 async_test(t => { 21 const iframe1 = document.getElementById("iframe1"); 22 const iframe2 = document.getElementById("iframe2"); 23 let iframes_loaded = 0; 24 25 // Step 1 26 window.addEventListener("message", t.step_func(e => { 27 28 // Step 3 29 if (e.data.message === "iframe loaded") { 30 iframes_loaded++; 31 if (iframes_loaded === 2) { 32 iframe1.contentWindow.postMessage( 33 {message: "create database"}, 34 "*", 35 ); 36 } 37 } 38 39 // Step 5 40 if (e.data.message === "database created") { 41 iframe2.contentWindow.postMessage( 42 {message: "check database"}, 43 "*", 44 ); 45 } 46 47 // Step 7 48 if (e.data.message === "database checked") { 49 t.step(() => { 50 assert_true( 51 e.data.doesDatabaseExist, 52 "The same database should exist in both frames", 53 ); 54 }); 55 t.done(); 56 } 57 })); 58 59 iframe1.src = "http://{{hosts[alt][]}}:{{ports[http][0]}}/IndexedDB/resources/idb-partitioned-persistence-iframe.html"; 60 iframe2.src = "http://{{hosts[alt][]}}:{{ports[http][0]}}/IndexedDB/resources/idb-partitioned-persistence-iframe.html"; 61 }, "Persistence test for partitioned IndexedDB"); 62 </script> 63 </body>