test_allow_opening_data_pdf.html (1680B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Bug 1398692: Allow toplevel navigation to a data:application/pdf</title> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 8 </head> 9 <body> 10 <script class="testbody" type="text/javascript"> 11 12 SimpleTest.waitForExplicitFinish(); 13 14 function test_toplevel_data_pdf() { 15 // The PDF contains one page and it is a 3/72" square, the minimum allowed by the spec 16 const DATA_PDF = 17 "data:application/pdf;base64,JVBERi0xLjANCjEgMCBvYmo8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFI+PmVuZG9iaiAyIDAgb2JqPDwvVHlwZS9QYWdlcy9LaWRzWzMgMCBSXS9Db3VudCAxPj5lbmRvYmogMyAwIG9iajw8L1R5cGUvUGFnZS9NZWRpYUJveFswIDAgMyAzXT4+ZW5kb2JqDQp4cmVmDQowIDQNCjAwMDAwMDAwMDAgNjU1MzUgZg0KMDAwMDAwMDAxMCAwMDAwMCBuDQowMDAwMDAwMDUzIDAwMDAwIG4NCjAwMDAwMDAxMDIgMDAwMDAgbg0KdHJhaWxlcjw8L1NpemUgNC9Sb290IDEgMCBSPj4NCnN0YXJ0eHJlZg0KMTQ5DQolRU9G"; 18 19 let win = window.open(DATA_PDF); 20 let wrappedWin = SpecialPowers.wrap(win); 21 22 // Unfortunately we can't detect whether the PDF has loaded or not using some 23 // event, hence we are constantly polling location.href till we see that 24 // the data: URI appears. Test times out on failure. 25 var pdfLoaded = setInterval(function() { 26 if (wrappedWin.document.location.href.startsWith("data:application/pdf")) { 27 clearInterval(pdfLoaded); 28 ok(true, "navigating to data:application/pdf allowed"); 29 wrappedWin.close(); 30 SimpleTest.finish(); 31 } 32 }, 200); 33 } 34 35 SpecialPowers.pushPrefEnv({ 36 set: [["security.data_uri.block_toplevel_data_uri_navigations", true]] 37 }, test_toplevel_data_pdf); 38 39 </script> 40 </body> 41 </html>