From b3ae9277a20d2d43dd5aa620d25911074e6f77d3 Mon Sep 17 00:00:00 2001 From: Bob Owen Date: Thu, 8 Feb 2018 08:59:20 +0000 Subject: [PATCH] Bug 1379117 Part 1: MOZ_ASSERT when not retrieving nsIWebBrowserPrint through docshell for Print Preview. r=jwatt Changing the last retrieval of the nsIWebBrowserPrint in printpreview_bug396024_helper.xul caused problems because doing it via the docshell interrupts the load that triggers run5. So, I moved the test to run5, which is more consistent with run2 and run3. I then realised that the frames would have switched anyway, so I changed it to retrieve frame[0] for the last test, which I think makes more sense. It's not totally clear to me what this was testing originally or whether it continued to do so after the addition of the second iframe a long time ago. --- layout/base/nsDocumentViewer.cpp | 5 ++--- .../chrome/printpreview_bug396024_helper.xul | 15 ++++++--------- .../chrome/printpreview_bug482976_helper.xul | 6 ++---- layout/base/tests/chrome/printpreview_helper.xul | 6 ++---- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index d5965dc6f700..cab74daa2d91 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -3946,9 +3946,8 @@ nsDocumentViewer::PrintPreview(nsIPrintSettings* aPrintSettings, nsIWebProgressListener* aWebProgressListener) { #if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW) - NS_WARNING_ASSERTION( - IsInitializedForPrintPreview(), - "Using docshell.printPreview is the preferred way for print previewing!"); + MOZ_ASSERT(IsInitializedForPrintPreview(), + "For print preview nsIWebBrowserPrint must be from docshell.printPreview!"); NS_ENSURE_ARG_POINTER(aChildDOMWin); nsresult rv = NS_OK; diff --git a/layout/base/tests/chrome/printpreview_bug396024_helper.xul b/layout/base/tests/chrome/printpreview_bug396024_helper.xul index 262bb3469e2a..ce1d6179f2e3 100644 --- a/layout/base/tests/chrome/printpreview_bug396024_helper.xul +++ b/layout/base/tests/chrome/printpreview_bug396024_helper.xul @@ -17,8 +17,7 @@ var todo = window.opener.wrappedJSObject.todo; var SimpleTest = window.opener.wrappedJSObject.SimpleTest; var gWbp; function printpreview() { - gWbp = window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor) - .getInterface(Components.interfaces.nsIWebBrowserPrint); + gWbp = window.frames[1].document.docShell.printPreview; var listener = { onLocationChange: function(webProgress, request, location, flags) { }, onProgressChange: function(webProgress, request, curSelfProgress, @@ -44,8 +43,7 @@ function printpreview() { } function exitprintpreview() { - window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor) - .getInterface(Components.interfaces.nsIWebBrowserPrint).exitPrintPreview(); + window.frames[1].document.docShell.printPreview.exitPrintPreview(); } function finish() { @@ -91,8 +89,7 @@ function run2() { } function run3() { - gWbp = window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor) - .getInterface(Components.interfaces.nsIWebBrowserPrint); + gWbp = window.frames[1].document.docShell.printPreview; ok(gWbp.doingPrintPreview, "Should be doing print preview"); exitprintpreview(); setTimeout(run4, 0); @@ -108,12 +105,12 @@ function run4() { i.addEventListener("load", loadhandler, true); document.documentElement.getBoundingClientRect(); document.documentElement.appendChild(i); - gWbp = window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor) - .getInterface(Components.interfaces.nsIWebBrowserPrint); - ok(!gWbp.doingPrintPreview, "Should not be doing print preview anymore2"); } function run5() { + gWbp = window.frames[0].document.docShell.printPreview; + ok(!gWbp.doingPrintPreview, "Should not be doing print preview anymore2"); + //XXX this shouldn't be necessary, see bug 405555 printpreview(); exitprintpreview(); diff --git a/layout/base/tests/chrome/printpreview_bug482976_helper.xul b/layout/base/tests/chrome/printpreview_bug482976_helper.xul index 34c2d658ec74..9a64888d5c2f 100644 --- a/layout/base/tests/chrome/printpreview_bug482976_helper.xul +++ b/layout/base/tests/chrome/printpreview_bug482976_helper.xul @@ -17,8 +17,7 @@ var todo = window.opener.wrappedJSObject.todo; var SimpleTest = window.opener.wrappedJSObject.SimpleTest; var gWbp; function printpreview() { - gWbp = window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor) - .getInterface(Components.interfaces.nsIWebBrowserPrint); + gWbp = window.frames[1].document.docShell.printPreview; var listener = { onLocationChange: function(webProgress, request, location, flags) { }, onProgressChange: function(webProgress, request, curSelfProgress, @@ -44,8 +43,7 @@ function printpreview() { } function exitprintpreview() { - window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor) - .getInterface(Components.interfaces.nsIWebBrowserPrint).exitPrintPreview(); + window.frames[1].document.docShell.printPreview.exitPrintPreview(); } function finish() { diff --git a/layout/base/tests/chrome/printpreview_helper.xul b/layout/base/tests/chrome/printpreview_helper.xul index d0bef8fb047c..72b24530970c 100644 --- a/layout/base/tests/chrome/printpreview_helper.xul +++ b/layout/base/tests/chrome/printpreview_helper.xul @@ -24,8 +24,7 @@ var file = Components.classes["@mozilla.org/file/directory_service;1"] filePath = file.path; function printpreview() { - gWbp = window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor) - .getInterface(Components.interfaces.nsIWebBrowserPrint); + gWbp = window.frames[1].document.docShell.printPreview; var listener = { onLocationChange: function(webProgress, request, location, flags) { }, onProgressChange: function(webProgress, request, curSelfProgress, @@ -61,8 +60,7 @@ function printpreview() { } function exitprintpreview() { - window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor) - .getInterface(Components.interfaces.nsIWebBrowserPrint).exitPrintPreview(); + window.frames[1].document.docShell.printPreview.exitPrintPreview(); } function finish() {