delayed_window_print.html (1089B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>Test for delaying window.print() before load</title> 4 <script src=/resources/testharness.js></script> 5 <script src=/resources/testharnessreport.js></script> 6 <body> 7 <script> 8 let t = async_test("Delayed print before load"); 9 let beforePrintCalled = false; 10 window.addEventListener("beforeprint", t.step_func(function() { 11 assert_false(beforePrintCalled, "Should only call beforeprint once"); 12 beforePrintCalled = true; 13 assert_true( 14 !!document.getElementById("before-load"), 15 "Should show contents that get added before load" 16 ); 17 assert_true( 18 !!document.getElementById("during-load"), 19 "Should show contents that get added during load" 20 ); 21 setTimeout(function() { t.done(); }, 0); 22 })); 23 24 t.step(function() { 25 window.print(); 26 27 let div = document.createElement("div"); 28 div.id = "before-load"; 29 document.body.appendChild(div); 30 }); 31 32 window.addEventListener("load", t.step_func(function() { 33 window.print(); 34 35 let div = document.createElement("div"); 36 div.id = "during-load"; 37 document.body.appendChild(div); 38 })); 39 </script>