printpreview_bug396024_helper.xhtml (3184B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" 4 type="text/css"?> 5 <!-- 6 https://bugzilla.mozilla.org/show_bug.cgi?id=396024 7 --> 8 <window title="Mozilla Bug 396024" onload="run()" 9 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 10 <iframe id="i" src="about:blank" type="content"></iframe> 11 <iframe src="about:blank" type="content"></iframe> 12 <script type="application/javascript"> 13 <![CDATA[ 14 // Note: We can't use window.frames directly here because the type="content" 15 // attributes isolate the frames into their own BrowsingContext hierarchies. 16 let frameElts = document.getElementsByTagName("iframe"); 17 18 var is = window.arguments[0].is; 19 var ok = window.arguments[0].ok; 20 var todo = window.arguments[0].todo; 21 var SimpleTest = window.arguments[0].SimpleTest; 22 var gWbp; 23 function printpreview() { 24 gWbp = frameElts[1].contentWindow.docShell.initOrReusePrintPreviewViewer(); 25 let settings = Cc["@mozilla.org/gfx/printsettings-service;1"] 26 .getService(Ci.nsIPrintSettingsService).createNewPrintSettings(); 27 gWbp.printPreview(settings, frameElts[0].contentWindow); 28 } 29 30 function exitprintpreview() { 31 frameElts[1].contentWindow.docShell.exitPrintPreview(); 32 } 33 34 function finish() { 35 SimpleTest.finish(); 36 window.close(); 37 } 38 39 function run() 40 { 41 /** Test for Bug 396024 */ 42 var printService = Cc["@mozilla.org/gfx/printsettings-service;1"] 43 .getService(Ci.nsIPrintSettingsService); 44 45 if (printService.lastUsedPrinterName != '') { 46 printpreview(); 47 ok(gWbp.doingPrintPreview, "Should be doing print preview"); 48 exitprintpreview(); 49 ok(!gWbp.doingPrintPreview, "Should not be doing print preview anymore1"); 50 printpreview(); 51 setTimeout(run2, 0) 52 } else { 53 todo(false, "No printer seems installed on this machine, that is necessary for this test"); 54 finish(); 55 } 56 } 57 58 function run2() { 59 var loadhandler = function() { 60 document.getElementById("i").removeEventListener("load", arguments.callee, true); 61 setTimeout(run3, 0); 62 }; 63 document.getElementById("i").addEventListener("load", loadhandler, true); 64 frameElts[0].contentWindow.location.reload(); 65 } 66 67 function run3() { 68 gWbp = frameElts[1].contentWindow.docShell.initOrReusePrintPreviewViewer(); 69 ok(gWbp.doingPrintPreview, "Should be doing print preview"); 70 exitprintpreview(); 71 setTimeout(run4, 0); 72 } 73 74 function run4() { 75 var i = document.getElementById("i"); 76 i.remove(); 77 var loadhandler = function() { 78 document.getElementById("i").removeEventListener("load", loadhandler, true); 79 setTimeout(run5, 0); 80 }; 81 i.addEventListener("load", loadhandler, true); 82 document.documentElement.getBoundingClientRect(); 83 document.documentElement.prepend(i); 84 } 85 86 function run5() { 87 gWbp = frameElts[1].contentWindow.docShell.initOrReusePrintPreviewViewer(); 88 ok(!gWbp.doingPrintPreview, "Should not be doing print preview anymore2"); 89 90 //XXX this shouldn't be necessary, see bug 405555 91 printpreview(); 92 exitprintpreview(); 93 finish(); //should not have crashed after all of this 94 } 95 ]]></script> 96 </window>