mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
56699ae2e0
--HG-- rename : layout/base/tests/test_bug396024.html => layout/base/tests/chrome/bug396024_helper.xul rename : layout/base/tests/test_bug482976.html => layout/base/tests/chrome/bug482976_helper.xul rename : layout/base/tests/test_printpreview.html => layout/base/tests/chrome/printpreview_helper.xul
217 lines
8.4 KiB
XML
217 lines
8.4 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"?>
|
|
<window onload="runTests()"
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
|
<iframe height="200" width="600"></iframe>
|
|
<script type="application/javascript">
|
|
<![CDATA[
|
|
var is = window.opener.wrappedJSObject.is;
|
|
var isnot = window.opener.wrappedJSObject.isnot;
|
|
var ok = window.opener.wrappedJSObject.ok;
|
|
var SimpleTest = window.opener.wrappedJSObject.SimpleTest;
|
|
var gWbp;
|
|
var ctx1;
|
|
var ctx2;
|
|
var counter = 0;
|
|
|
|
function printpreview() {
|
|
gWbp = window.frames[0].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, null, listener);
|
|
prefs.clearUserPref('print.show_print_progress');
|
|
}
|
|
|
|
function exitprintpreview() {
|
|
window.frames[0].QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
.getInterface(Components.interfaces.nsIWebBrowserPrint).exitPrintPreview();
|
|
}
|
|
|
|
function runTests()
|
|
{
|
|
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 != '') {
|
|
startTest1();
|
|
} else {
|
|
todo(false, "No printer seems installed on this machine, that is necessary for this test");
|
|
SimpleTest.finish();
|
|
}
|
|
}
|
|
|
|
function compareCanvases() {
|
|
return window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
.getInterface(Components.interfaces.nsIDOMWindowUtils)
|
|
.compareCanvases(document.getElementsByTagName("canvas")[0],
|
|
document.getElementsByTagName("canvas")[1],
|
|
{}) == 0;
|
|
}
|
|
|
|
function addHTMLContent(parent) {
|
|
var n = parent.ownerDocument.createElement("div");
|
|
parent.appendChild(n);
|
|
var s = "<iframe width='500' height='40' src='data:text/plain,ThisIsAnIframeCreatedDuringPrintPreview'></iframe>";
|
|
s += "<table>";
|
|
for (var i = 1; i < 501; ++i) {
|
|
s += "<tr><td>Cell A" + i + "</td><td>Cell B" + i + "</td><td>Cell C" + i + "</td></tr>";
|
|
}
|
|
s += "</table>";
|
|
n.innerHTML = s;
|
|
}
|
|
|
|
function startTest1() {
|
|
ctx1 = document.getElementsByTagName("canvas")[0].getContext("2d");
|
|
ctx2 = document.getElementsByTagName("canvas")[1].getContext("2d");
|
|
window.frames[0].document.body.innerHTML = "<div> </div><div>" + counter + " timers</div><div> </div>";
|
|
|
|
// Note this timeout is needed so that we can check that timers run
|
|
// after print preview, but not during it.
|
|
window.frames[0].counter = counter;
|
|
window.frames[0].counterTimeout = "document.body.firstChild.nextSibling.innerHTML = ++counter + ' timers';" +
|
|
"window.setTimeout(counterTimeout, 0);";
|
|
window.frames[0].setTimeout(window.frames[0].counterTimeout, 0);
|
|
window.frames[0].document.body.firstChild.innerHTML = "Print preview";
|
|
|
|
printpreview();
|
|
ctx1.drawWindow(window.frames[0], 0, 0, 300, 300, "rgb(256,256,256)");
|
|
window.frames[0].document.body.firstChild.innerHTML = "Galley presentation";
|
|
window.frames[0].document.body.firstChild.innerHTML +=
|
|
"<div style='color: red;'>This is not for print preview!</div>";
|
|
window.frames[0].document.body.firstChild.lastChild.firstChild.data += " Really!";
|
|
|
|
// Add some elements.
|
|
addHTMLContent(window.frames[0].document.body.lastChild);
|
|
// Delete them.
|
|
window.frames[0].document.body.lastChild.innerHTML = "";
|
|
// And readd.
|
|
addHTMLContent(window.frames[0].document.body.lastChild);
|
|
|
|
setTimeout(finalizeTest1, 1000);
|
|
}
|
|
|
|
function finalizeTest1() {
|
|
ctx2.drawWindow(window.frames[0], 0, 0, 300, 300, "rgb(256,256,256)");
|
|
exitprintpreview();
|
|
ok(compareCanvases(), "Canvas should be the same!");
|
|
is(window.frames[0].document.body.firstChild.nextSibling.textContent, "0 timers", "Timers shouldn't have run yet!");
|
|
is(window.frames[0].counter, 0, "Timers shouldn't have run yet!");
|
|
counter = window.frames[0].counter;
|
|
// This timeout is needed so that we can check that timers do run after
|
|
// print preview.
|
|
setTimeout(runTest2, 1000);
|
|
}
|
|
|
|
function runTest2() {
|
|
isnot(window.frames[0].document.body.firstChild.nextSibling.textContent, "0 timers", "Timers should have run!");
|
|
isnot(window.frames[0].counter, 0, "Timers should have run!");
|
|
counter = window.frames[0].counter;
|
|
window.frames[0].counterTimeout = "";
|
|
setTimeout(runTest3, 0);
|
|
}
|
|
|
|
var elementIndex = 0;
|
|
var compareEmptyElement = true;
|
|
var emptyFormElements =
|
|
["<input type='text'>",
|
|
"<input type='password'>",
|
|
"<input type='file'>",
|
|
"<input type='button'>",
|
|
"<input type='submit'>",
|
|
"<input type='reset'>",
|
|
"<input type='checkbox'>",
|
|
"<input type='radio'>",
|
|
"<select></select>",
|
|
"<select size='5'></select>",
|
|
"<textarea></textarea>"];
|
|
|
|
var formElements =
|
|
["<input type='text' value='text'>",
|
|
"<input type='password' value='password'>",
|
|
"<input type='file' value='file'>",
|
|
"<input type='button' value='button'>",
|
|
"<input type='submit' value='submit button'>",
|
|
"<input type='reset' value='reset button'>",
|
|
"<input type='checkbox' checked>",
|
|
"<input type='radio' checked>",
|
|
"<select><option>option1</option></select>",
|
|
"<select size='5'><option>1</option><option>2</option><option>3</option></select>",
|
|
"<textarea value='textarea'>textarea</textarea>"];
|
|
|
|
function runTest3() {
|
|
if (compareEmptyElement) {
|
|
var currentIndex = elementIndex;
|
|
++elementIndex;
|
|
if (elementIndex >= emptyFormElements.length) {
|
|
elementIndex = 0;
|
|
compareEmptyElement = false;
|
|
}
|
|
compareFormElementPrint(emptyFormElements[currentIndex], emptyFormElements[currentIndex], true);
|
|
return;
|
|
} else if (elementIndex < emptyFormElements.length) {
|
|
var currentIndex = elementIndex;
|
|
++elementIndex;
|
|
compareFormElementPrint(emptyFormElements[currentIndex], formElements[currentIndex], false);
|
|
return;
|
|
}
|
|
|
|
SimpleTest.finish();
|
|
window.close();
|
|
}
|
|
|
|
function compareFormElementPrint(el1, el2, equals) {
|
|
window.frames[0].document.body.innerHTML = el1;
|
|
window.frames[0].document.body.firstChild.value =
|
|
window.frames[0].document.body.firstChild.getAttribute('value');
|
|
printpreview();
|
|
ctx1.drawWindow(window.frames[0], 0, 0, 300, 300, "rgb(256,256,256)");
|
|
exitprintpreview();
|
|
window.frames[0].document.body.innerHTML = el2;
|
|
window.frames[0].document.body.firstChild.value =
|
|
window.frames[0].document.body.firstChild.getAttribute('value');
|
|
printpreview();
|
|
ctx2.drawWindow(window.frames[0], 0, 0, 300, 300, "rgb(256,256,256)");
|
|
exitprintpreview();
|
|
is(compareCanvases(), equals,
|
|
"Comparing print preview didn't succeed [" + el1 + " : " + el2 + "]");
|
|
setTimeout(runTest3, 100);
|
|
}
|
|
]]></script>
|
|
<table style="border: 1px solid black;" xmlns="http://www.w3.org/1999/xhtml">
|
|
<tr><th>Print preview canvas 1</th><th>Print preview canvas 2</th></tr>
|
|
<tr>
|
|
<td><canvas height="300" width="300"></canvas></td>
|
|
<td><canvas height="300" width="300"></canvas></td>
|
|
</tr></table>
|
|
</window>
|