layout/base/tests/chrome/printpreview_bug396024_helper.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
michael@0 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
michael@0 4 type="text/css"?>
michael@0 5 <!--
michael@0 6 https://bugzilla.mozilla.org/show_bug.cgi?id=396024
michael@0 7 -->
michael@0 8 <window title="Mozilla Bug 396024" onload="run()"
michael@0 9 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 10 <iframe id="i" src="about:blank" type="content"></iframe>
michael@0 11 <iframe src="about:blank" type="content"></iframe>
michael@0 12 <script type="application/javascript">
michael@0 13 <![CDATA[
michael@0 14 var is = window.opener.wrappedJSObject.is;
michael@0 15 var ok = window.opener.wrappedJSObject.ok;
michael@0 16 var todo = window.opener.wrappedJSObject.todo;
michael@0 17 var SimpleTest = window.opener.wrappedJSObject.SimpleTest;
michael@0 18 var gWbp;
michael@0 19 function printpreview() {
michael@0 20 gWbp = window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor)
michael@0 21 .getInterface(Components.interfaces.nsIWebBrowserPrint);
michael@0 22 var listener = {
michael@0 23 onLocationChange: function(webProgress, request, location, flags) { },
michael@0 24 onProgressChange: function(webProgress, request, curSelfProgress,
michael@0 25 maxSelfProgress, curTotalProgress,
michael@0 26 maxTotalProgress) { },
michael@0 27 onSecurityChange: function(webProgress, request, state) { },
michael@0 28 onStateChange: function(webProgress, request, stateFlags, status) { },
michael@0 29 onStatusChange: function(webProgress, request, status, message) { },
michael@0 30 QueryInterface: function(iid) {
michael@0 31 if (iid.equals(Components.interfaces.nsIWebProgressListener) ||
michael@0 32 iid.equals(Components.interfaces.nsISupportsWeakReference))
michael@0 33 return this;
michael@0 34 throw Components.results.NS_NOINTERFACE;
michael@0 35 }
michael@0 36 }
michael@0 37 var prefs = Components.classes["@mozilla.org/preferences-service;1"]
michael@0 38 .getService(Components.interfaces.nsIPrefBranch);
michael@0 39 prefs.setBoolPref('print.show_print_progress', false);
michael@0 40 //XXX I would have thought this would work, instead I'm forced to use prefs service
michael@0 41 gWbp.globalPrintSettings.showPrintProgress = false;
michael@0 42 gWbp.printPreview(gWbp.globalPrintSettings, window.frames[0], listener);
michael@0 43 prefs.clearUserPref('print.show_print_progress');
michael@0 44 }
michael@0 45
michael@0 46 function exitprintpreview() {
michael@0 47 window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor)
michael@0 48 .getInterface(Components.interfaces.nsIWebBrowserPrint).exitPrintPreview();
michael@0 49 }
michael@0 50
michael@0 51 function finish() {
michael@0 52 SimpleTest.finish();
michael@0 53 window.close();
michael@0 54 }
michael@0 55
michael@0 56 function run()
michael@0 57 {
michael@0 58 /** Test for Bug 396024 **/
michael@0 59 var printService = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
michael@0 60 .getService(Components.interfaces.nsIPrintSettingsService);
michael@0 61
michael@0 62 try {
michael@0 63 Components.classes["@mozilla.org/gfx/printerenumerator;1"]
michael@0 64 .getService(Components.interfaces.nsIPrinterEnumerator);
michael@0 65 } catch(e) {
michael@0 66 todo(false, "Test skipped on MacOSX, as the print preview code doesn't work there");
michael@0 67 finish();
michael@0 68 return;
michael@0 69 }
michael@0 70
michael@0 71 if (printService.defaultPrinterName != '') {
michael@0 72 printpreview();
michael@0 73 ok(gWbp.doingPrintPreview, "Should be doing print preview");
michael@0 74 exitprintpreview();
michael@0 75 ok(!gWbp.doingPrintPreview, "Should not be doing print preview anymore1");
michael@0 76 printpreview();
michael@0 77 setTimeout(run2, 0)
michael@0 78 } else {
michael@0 79 todo(false, "No printer seems installed on this machine, that is necessary for this test");
michael@0 80 finish();
michael@0 81 }
michael@0 82 }
michael@0 83
michael@0 84 function run2() {
michael@0 85 var loadhandler = function() {
michael@0 86 document.getElementById("i").removeEventListener("load", arguments.callee, true);
michael@0 87 setTimeout(run3, 0);
michael@0 88 };
michael@0 89 document.getElementById("i").addEventListener("load", loadhandler, true);
michael@0 90 window.frames[0].location.reload();
michael@0 91 }
michael@0 92
michael@0 93 function run3() {
michael@0 94 gWbp = window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor)
michael@0 95 .getInterface(Components.interfaces.nsIWebBrowserPrint);
michael@0 96 ok(gWbp.doingPrintPreview, "Should be doing print preview");
michael@0 97 exitprintpreview();
michael@0 98 setTimeout(run4, 0);
michael@0 99 }
michael@0 100
michael@0 101 function run4() {
michael@0 102 var i = document.getElementById("i");
michael@0 103 var x = i.parentNode.removeChild(i);
michael@0 104 var loadhandler = function() {
michael@0 105 document.getElementById("i").removeEventListener("load", loadhandler, true);
michael@0 106 setTimeout(run5, 0);
michael@0 107 };
michael@0 108 x.addEventListener("load", loadhandler, true);
michael@0 109 document.documentElement.getBoundingClientRect();
michael@0 110 document.documentElement.appendChild(x);
michael@0 111 gWbp = window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor)
michael@0 112 .getInterface(Components.interfaces.nsIWebBrowserPrint);
michael@0 113 ok(!gWbp.doingPrintPreview, "Should not be doing print preview anymore2");
michael@0 114 }
michael@0 115
michael@0 116 function run5() {
michael@0 117 //XXX this shouldn't be necessary, see bug 405555
michael@0 118 printpreview();
michael@0 119 exitprintpreview();
michael@0 120 finish(); //should not have crashed after all of this
michael@0 121 }
michael@0 122 ]]></script>
michael@0 123 </window>

mercurial