test_report_font_cache.html (2047B)
1 <!DOCTYPE html> 2 <script src="/tests/SimpleTest/SimpleTest.js"></script> 3 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"> 4 <iframe id="f"></iframe> 5 6 <script> 7 var chromeScriptUrl = SimpleTest.getTestFileURL("file_report_chromescript.js"); 8 var script = SpecialPowers.loadChromeScript(chromeScriptUrl); 9 10 var reportedFont1 = false; 11 var reportedFont3 = false; 12 13 function reportListener(msg) { 14 if (!msg.error) { 15 // Step 3: Check the specific blocked URLs from the CSP reports. 16 let blocked = JSON.parse(msg.report)["csp-report"]["blocked-uri"] 17 .replace(/^.*\//, ""); 18 switch (blocked) { 19 case "Ahem.ttf?report_font_cache-1": 20 ok(!reportedFont1, "should not have already reported Test Font 1"); 21 ok(!reportedFont3, "should not have reported Test Font 3 before Test Font 1"); 22 reportedFont1 = true; 23 break; 24 case "Ahem.ttf?report_font_cache-2": 25 ok(false, "should not have reported Test Font 2"); 26 break; 27 case "Ahem.ttf?report_font_cache-3": 28 ok(!reportedFont3, "should not have already reported Test Font 3"); 29 reportedFont3 = true; 30 break; 31 } 32 if (reportedFont1 && reportedFont3) { 33 script.removeMessageListener("opening-request-completed", reportListener); 34 script.sendAsyncMessage("finish"); 35 SimpleTest.finish(); 36 } 37 } 38 } 39 40 SimpleTest.waitForExplicitFinish(); 41 42 script.addMessageListener("opening-request-completed", reportListener); 43 44 window.onmessage = function(message) { 45 // Step 2: Navigate to the second document, which will attempt to use the 46 // cached "Test Font 1" and then a new "Test Font 3", both of which will 47 // generate CSP reports. The "Test Font 2" entry in the user font cache 48 // should not cause a CSP report from this document. 49 is(message.data, "first-doc-ready"); 50 f.src = "file_report_font_cache-2.html"; 51 }; 52 53 // Step 1: Prime the user font cache with entries for "Test Font 1", 54 // "Test Font 2" and "Test Font 3". 55 f.src = "file_report_font_cache-1.html"; 56 </script>