gecko/layout/base/tests/chrome/bug396024_helper.xul
Olli Pettay 2f4c5ea761 Bug 487667 - Clone documents for printing, r=roc+jst+joe+dbaron
--HG--
extra : rebase_source : dbab242066ba97c0d7f34a2fb701a1c465f26ec4
2009-12-10 20:02:13 -08:00

111 lines
4.3 KiB
XML

<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=396024
-->
<window title="Mozilla Bug 396024" onload="run()"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<iframe src="data:text/html;charset=utf-8,&lt;body onload='window.parent.loadedChild()'&gt;"></iframe>
<iframe src="about:blank"/>
<script type="application/javascript">
<![CDATA[
var is = window.opener.wrappedJSObject.is;
var ok = window.opener.wrappedJSObject.ok;
var SimpleTest = window.opener.wrappedJSObject.SimpleTest;
var gWbp;
function printpreview() {
gWbp = window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebBrowserPrint);
var listener = {
onLocationChange: function(webProgress, request, location) { },
onProgressChange: function(webProgress, request, curSelfProgress,
maxSelfProgress, curTotalProgress,
maxTotalProgress) { },
onSecurityChange: function(webProgress, request, state) { },
onStateChange: function(webProgress, request, stateFlags, status) { },
onStatusChange: function(webProgress, request, status, message) { },
QueryInterface: function(iid) {
if (iid.equals(Components.interfaces.nsIWebProgressListener) ||
iid.equals(Components.interfaces.nsISupportsWeakReference))
return this;
throw Components.results.NS_NOINTERFACE;
}
}
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
prefs.setBoolPref('print.show_print_progress', false);
//XXX I would have thought this would work, instead I'm forced to use prefs service
gWbp.globalPrintSettings.showPrintProgress = false;
gWbp.printPreview(gWbp.globalPrintSettings, window.frames[0], listener);
prefs.clearUserPref('print.show_print_progress');
}
function exitprintpreview() {
window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebBrowserPrint).exitPrintPreview();
}
function run()
{
/** Test for Bug 396024 **/
var printService = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
.getService(Components.interfaces.nsIPrintSettingsService);
try {
var printerEnumerator = Components.classes["@mozilla.org/gfx/printerenumerator;1"]
.getService(Components.interfaces.nsIPrinterEnumerator);
} catch(e) {
//don't try to test on Mac, since the print preview code doesn't work there
SimpleTest.finish();
return;
}
if (printService.defaultPrinterName != '') {
printpreview();
ok(gWbp.doingPrintPreview, "Should be doing print preview");
exitprintpreview();
ok(!gWbp.doingPrintPreview, "Should not be doing print preview anymore1");
printpreview();
setTimeout(run2, 0)
} else {
todo(false, "No printer seems installed on this machine, that is necessary for this test");
SimpleTest.finish();
}
}
function run2() {
window.loadedChild = function() { setTimeout(run3, 0); };
window.frames[0].location.reload();
}
function run3() {
gWbp = window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebBrowserPrint);
ok(gWbp.doingPrintPreview, "Should be doing print preview");
window.loadedChild = null;
exitprintpreview();
setTimeout(run4, 0);
}
function run4() {
var x = window.frames[0].frameElement.parentNode.removeChild(window.frames[0].frameElement);
window.loadedChild = function() { setTimeout(run5, 0); };
document.documentElement.getBoundingClientRect();
document.documentElement.appendChild(x);
gWbp = window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebBrowserPrint);
ok(!gWbp.doingPrintPreview, "Should not be doing print preview anymore2");
}
function run5() {
//XXX this shouldn't be necessary, see bug 405555
printpreview();
exitprintpreview();
SimpleTest.finish(); //should not have crashed after all of this
window.close();
}
]]></script>
</window>