Bug 164250 Instrument the PrintEngine for print testing

r=dcone sr=kin
This commit is contained in:
rods@netscape.com
2002-09-03 23:21:15 +00:00
parent 3290bb5354
commit 900a497693
9 changed files with 299 additions and 13 deletions

View File

@@ -278,6 +278,10 @@ nsPrintEngine::nsPrintEngine() :
//-------------------------------------------------------
nsPrintEngine::~nsPrintEngine()
{
#ifdef MOZ_LAYOUTDEBUG
nsPrintEngine::mLayoutDebugObj = nsnull;
#endif
Destroy(); // for insurance
}
@@ -592,6 +596,8 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
NS_ASSERTION(mPrt->mPrintSettings, "You can't Print without a PrintSettings!");
rv = NS_ERROR_FAILURE;
}
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_CHECKFORPRINTERS, rv, NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE);
if (NS_FAILED(rv)) {
PR_PL(("NS_ERROR_FAILURE - CheckForPrinters for Printers failed"));
return CleanupOnFailure(rv, PR_FALSE);
@@ -604,6 +610,7 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
// The print settings hold an nsWeakPtr to the session so it does not
// need to be cleared from the settings at the end of the job.
mPrt->mPrintSession = do_CreateInstance("@mozilla.org/gfx/printsession;1", &rv);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_CREATEPRTSESSION, rv, NS_ERROR_FAILURE);
if (NS_FAILED(rv)) {
PR_PL(("NS_ERROR_FAILURE - do_CreateInstance for printsession failed"));
return CleanupOnFailure(rv, PR_TRUE);
@@ -648,9 +655,12 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
// Add Root Doc to Tree and List
mPrt->mPrintObject = new nsPrintObject();
if (NS_FAILED(mPrt->mPrintObject->Init(webContainer))) {
rv = mPrt->mPrintObject->Init(webContainer);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_INITPRTOBJ, rv, NS_ERROR_FAILURE);
if (NS_FAILED(rv)) {
PR_PL(("NS_ERROR_FAILURE - Failed on Init of PrintObject"));
return NS_ERROR_FAILURE;
ShowPrintErrorDialog(NS_ERROR_FAILURE);
return rv;
}
mPrt->mPrintDocList->AppendElement(mPrt->mPrintObject);
@@ -709,6 +719,7 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
nsCOMPtr<nsIDeviceContextSpecFactory> factory =
do_CreateInstance(kDeviceContextSpecFactoryCID, &rv);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_CREATESPECFACTORY, rv, NS_ERROR_FAILURE);
if (NS_SUCCEEDED(rv)) {
#ifdef DEBUG_dcone
printf("PRINT JOB STARTING\n");
@@ -769,6 +780,7 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
}
}
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_NOPROMPTSERVICE, rv, NS_ERROR_GFX_NO_PRINTROMPTSERVICE);
if (NS_FAILED(rv)) {
PR_PL(("**** Printing Stopped before CreateDeviceContextSpec"));
return CleanupOnFailure(rv, PR_TRUE);
@@ -792,6 +804,7 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
return NS_ERROR_ABORT;
}
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_NODEVSPEC, rv, NS_ERROR_FAILURE);
if (NS_SUCCEEDED(rv)) {
rv = mPresContext->GetDeviceContext(getter_AddRefs(dx));
if (NS_SUCCEEDED(rv)) {
@@ -902,7 +915,37 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
mPrt->mPrintSettings->GetPrintFrameType(&mPrt->mPrintFrameType);
}
// Get the Needed info for Calling PrepareDocument
#ifdef MOZ_LAYOUTDEBUG
{
// This is a special debugging regression tool section
PRUnichar* tempFileName = nsnull;
if (nsPrintEngine::IsDoingRuntimeTesting()) {
// Here we check for a special filename (the destination for the print job)
// and sets into the print settings if there is a name then we want to
// print to a file. if not, let it print normally.
if (NS_SUCCEEDED(mLayoutDebugObj->GetPrintFileName(&tempFileName)) && tempFileName) {
if (*tempFileName) {
mPrt->mPrintSettings->SetPrintToFile(PR_TRUE);
mPrt->mPrintSettings->SetToFileName(tempFileName);
}
nsMemory::Free(tempFileName);
}
// Here we check to see how we should print a frameset (if there is one)
PRBool asIs = PR_FALSE;
if (NS_SUCCEEDED(mLayoutDebugObj->GetPrintAsIs(&asIs))) {
PRInt16 howToEnableFrameUI;
mPrt->mPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI);
if (howToEnableFrameUI != nsIPrintSettings::kFrameEnableNone) {
mPrt->mPrintFrameType = asIs?nsIPrintSettings::kFramesAsIs:nsIPrintSettings::kEachFrameSep;
mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType);
}
}
}
}
#endif
// Get the Needed info for Calling PrepareDocument
PRUnichar* fileName = nsnull;
// check to see if we are printing to a file
PRBool isPrintToFile = PR_FALSE;
@@ -924,7 +967,11 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
if (docTitleStr) nsMemory::Free(docTitleStr);
if (docURLStr) nsMemory::Free(docURLStr);
NS_ENSURE_SUCCESS(rv, rv);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_PREPAREDOC, rv, NS_ERROR_FAILURE);
if (NS_FAILED(rv)) {
return CleanupOnFailure(rv, PR_TRUE);
}
PRBool doNotify;
ShowPrintProgress(PR_TRUE, doNotify);
@@ -2347,7 +2394,9 @@ nsPrintEngine::SetupToPrintContent(nsIWebShell* aParent,
}
// Here we reflow all the PrintObjects
if (NS_FAILED(ReflowDocList(mPrt->mPrintObject, doSetPixelScale, mPrt->mShrinkToFit))) {
nsresult rv = ReflowDocList(mPrt->mPrintObject, doSetPixelScale, mPrt->mShrinkToFit);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_REFLOWDOCLIST, rv, NS_ERROR_FAILURE);
if (NS_FAILED(rv)) {
return NS_ERROR_FAILURE;
}
@@ -2479,7 +2528,7 @@ nsPrintEngine::SetupToPrintContent(nsIWebShell* aParent,
}
}
nsresult rv = NS_OK;
rv = NS_OK;
// BeginDocument may pass back a FAILURE code
// i.e. On Windows, if you are printing to a file and hit "Cancel"
// to the "File Name" dialog, this comes back as an error
@@ -2493,6 +2542,7 @@ nsPrintEngine::SetupToPrintContent(nsIWebShell* aParent,
if (docTitleStr) nsMemory::Free(docTitleStr);
if (docURLStr) nsMemory::Free(docURLStr);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_BEGINDOC, rv, NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(rv, rv);
// This will print the webshell document
@@ -3596,6 +3646,7 @@ nsPrintEngine::PrintPage(nsIPresContext* aPresContext,
// When rv == NS_ERROR_ABORT, it means we want out of the
// print job without displaying any error messages
nsresult rv = mPageSeqFrame->PrintNextPage(aPresContext);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_NEXTPAGE, rv, NS_ERROR_FAILURE);
if (NS_FAILED(rv)) {
if (rv != NS_ERROR_ABORT) {
ShowPrintErrorDialog(rv);
@@ -5115,12 +5166,58 @@ static void DumpPrintObjectsListStart(char * aStr, nsVoidArray * aDocList)
#define DUMP_DOC_LIST(_title) DumpPrintObjectsListStart((_title), mPrt->mPrintDocList);
#define DUMP_DOC_TREE DumpPrintObjectsTree(mPrt->mPrintObject);
#define DUMP_DOC_TREELAYOUT DumpPrintObjectsTreeLayout(mPrt->mPrintObject, mPrt->mPrintDC);
#else
#define DUMP_DOC_LIST(_title)
#define DUMP_DOC_TREE
#define DUMP_DOC_TREELAYOUT
#endif
#ifdef MOZ_LAYOUTDEBUG
nsCOMPtr<nsIDebugObject> nsPrintEngine::mLayoutDebugObj;
PRBool nsPrintEngine::mIsDoingRuntimeTesting = PR_FALSE;
void
nsPrintEngine::InitializeTestRuntimeError()
{
nsCOMPtr<nsIPref> prefs (do_GetService(NS_PREF_CONTRACTID));
if (prefs) {
mIsDoingRuntimeTesting = PR_FALSE;
prefs->GetBoolPref("print.doing_runtime_error_checking", &mIsDoingRuntimeTesting);
}
mLayoutDebugObj = do_GetService("@mozilla.org/debug/debugobject;1");
}
PRBool
nsPrintEngine::IsDoingRuntimeTesting()
{
PRBool isDoingTests = PR_FALSE;
if (mLayoutDebugObj) {
mLayoutDebugObj->GetDoRuntimeTests(&isDoingTests);
}
return isDoingTests;
}
nsresult
nsPrintEngine::TestRuntimeErrorCondition(PRInt16 aRuntimeID,
nsresult aCurrentErrorCode,
nsresult aNewErrorCode)
{
PRInt16 id;
if (mLayoutDebugObj) {
if (NS_SUCCEEDED(mLayoutDebugObj->GetTestId(&id))) {
if (id == aRuntimeID) {
return aNewErrorCode;
}
}
}
return aCurrentErrorCode;
}
#endif
//---------------------------------------------------------------
//---------------------------------------------------------------
//-- End of debug helper routines