Bug 671976 - Fix print preview asserts (r=smaug)
authorBill McCloskey <wmccloskey@mozilla.com>
Thu, 14 Mar 2013 12:02:28 -0700
changeset 124861 3df2b971c10611983cab157d35d48618eef4c5a0
parent 124860 133c7241391deca27d2dc660e41b2c87de12439f
child 124862 8c8789fb12a3e506f97f7ccab3ed83a71e566b51
child 127444 1821ba8e3afce73f9150a85cb833d1013f1fb4fc
push id24646
push userwmccloskey@mozilla.com
push dateFri, 15 Mar 2013 05:08:40 +0000
treeherdermozilla-inbound@3df2b971c106 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs671976
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 671976 - Fix print preview asserts (r=smaug)
layout/base/tests/chrome/printpreview_bug396024_helper.xul
layout/base/tests/chrome/printpreview_bug482976_helper.xul
layout/base/tests/chrome/printpreview_helper.xul
layout/base/tests/chrome/test_printpreview.xul
layout/base/tests/chrome/test_printpreview_bug396024.xul
layout/base/tests/chrome/test_printpreview_bug482976.xul
layout/forms/test/test_bug536567_perwindowpb.html
layout/printing/nsPrintEngine.cpp
--- a/layout/base/tests/chrome/printpreview_bug396024_helper.xul
+++ b/layout/base/tests/chrome/printpreview_bug396024_helper.xul
@@ -9,17 +9,17 @@ https://bugzilla.mozilla.org/show_bug.cg
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 <iframe id="i" src="about:blank" type="content"></iframe>
 <iframe src="about:blank" type="content"></iframe>
 <script type="application/javascript">
 <![CDATA[
 var is = window.opener.wrappedJSObject.is;
 var ok = window.opener.wrappedJSObject.ok;
 var todo = window.opener.wrappedJSObject.todo;
-var parentFinish = window.opener.wrappedJSObject.parentFinish;
+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, flags) { },
     onProgressChange: function(webProgress, request, curSelfProgress, 
                                maxSelfProgress, curTotalProgress,
@@ -44,17 +44,17 @@ function printpreview() {
 }
 
 function exitprintpreview() {
   window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor)
    .getInterface(Components.interfaces.nsIWebBrowserPrint).exitPrintPreview(); 
 }
 
 function finish() {
-  parentFinish();
+  SimpleTest.finish();
   window.close();
 }
 
 function run()
 {
 /** Test for Bug 396024 **/
   var printService = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
                                .getService(Components.interfaces.nsIPrintSettingsService);
--- a/layout/base/tests/chrome/printpreview_bug482976_helper.xul
+++ b/layout/base/tests/chrome/printpreview_bug482976_helper.xul
@@ -9,17 +9,17 @@ https://bugzilla.mozilla.org/show_bug.cg
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 <iframe src="about:blank" type="content"></iframe>
 <iframe src="about:blank" type="content"></iframe>
 <script type="application/javascript">
 <![CDATA[
 var is = window.opener.wrappedJSObject.is;
 var ok = window.opener.wrappedJSObject.ok;
 var todo = window.opener.wrappedJSObject.todo;
-var parentFinish = window.opener.wrappedJSObject.parentFinish;
+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, flags) { },
     onProgressChange: function(webProgress, request, curSelfProgress, 
                                maxSelfProgress, curTotalProgress,
@@ -44,17 +44,17 @@ function printpreview() {
 }
 
 function exitprintpreview() {
   window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor)
    .getInterface(Components.interfaces.nsIWebBrowserPrint).exitPrintPreview(); 
 }
 
 function finish() {
-  parentFinish();
+  SimpleTest.finish();
   window.close();
 }
 
 function run1()
 {
 /** Test for Bug 482976 **/
   var printService = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
                                .getService(Components.interfaces.nsIPrintSettingsService);
--- a/layout/base/tests/chrome/printpreview_helper.xul
+++ b/layout/base/tests/chrome/printpreview_helper.xul
@@ -7,17 +7,17 @@
 <iframe height="200" width="600" type="content"></iframe>
 <iframe height="200" width="600" type="content"></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 todo = window.opener.wrappedJSObject.todo;
-var parentFinish = window.opener.wrappedJSObject.parentFinish;
+var SimpleTest = window.opener.wrappedJSObject.SimpleTest;
 var gWbp;
 var ctx1;
 var ctx2;
 var counter = 0;
 
 var file = Components.classes["@mozilla.org/file/directory_service;1"]
              .getService(Components.interfaces.nsIProperties)
              .get("TmpD", Components.interfaces.nsILocalFile);
@@ -61,17 +61,17 @@ function printpreview() {
 }
 
 function exitprintpreview() {
   window.frames[1].QueryInterface(Components.interfaces.nsIInterfaceRequestor)
    .getInterface(Components.interfaces.nsIWebBrowserPrint).exitPrintPreview(); 
 }
 
 function finish() {
-  parentFinish();
+  SimpleTest.finish();
   window.close();
 }
 
 function runTests()
 {
   var printService = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
                                .getService(Components.interfaces.nsIPrintSettingsService);
 
--- a/layout/base/tests/chrome/test_printpreview.xul
+++ b/layout/base/tests/chrome/test_printpreview.xul
@@ -5,34 +5,12 @@
 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
 <body xmlns="http://www.w3.org/1999/xhtml">
 </body>
   <!-- test code goes here -->
 <script type="application/javascript">
 <![CDATA[
-if (navigator.platform.startsWith("Linux")) {
-  SimpleTest.expectAssertions(1); // bug 671976
-} else if (navigator.platform.startsWith("Win")) {
-  // reliable 1 on Win7, but not on XP
-  SimpleTest.expectAssertions(0, 1); // bug 671976
-}
-
-function parentFinish() {
-  // This is called while the helper window is still open.  Call
-  // doGC after it closes.
-  setTimeout(doGC, 0);
-}
-function doGC() {
-  // Garbage collecting the windows created in this test can cause
-  // assertions, so GC now to blame those assertions to this test.
-  // ("Destroying a currently-showing document", bug 671976)
-  SpecialPowers.gc();
-  setTimeout(doFinish, 0);
-}
-function doFinish() {
-  SimpleTest.finish();
-}
 SimpleTest.waitForExplicitFinish();
 window.open("printpreview_helper.xul", "printpreview", "chrome,width=100,height=100");
 ]]></script>
 </window>
--- a/layout/base/tests/chrome/test_printpreview_bug396024.xul
+++ b/layout/base/tests/chrome/test_printpreview_bug396024.xul
@@ -11,34 +11,12 @@ https://bugzilla.mozilla.org/show_bug.cg
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
 <body xmlns="http://www.w3.org/1999/xhtml">
 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=396024"
    target="_blank">Mozilla Bug 396024</a>
 </body>
   <!-- test code goes here -->
 <script type="application/javascript">
 <![CDATA[
-if (navigator.platform.startsWith("Linux")) {
-  SimpleTest.expectAssertions(2); // bug 671976
-} else if (navigator.platform.startsWith("Win")) {
-  // reliable 2 on Win7, but not on XP
-  SimpleTest.expectAssertions(0, 2); // bug 671976
-}
-
-function parentFinish() {
-  // This is called while the helper window is still open.  Call
-  // doGC after it closes.
-  setTimeout(doGC, 0);
-}
-function doGC() {
-  // Garbage collecting the windows created in this test can cause
-  // assertions, so GC now to blame those assertions to this test.
-  // ("Destroying a currently-showing document", bug 671976)
-  SpecialPowers.gc();
-  setTimeout(doFinish, 0);
-}
-function doFinish() {
-  SimpleTest.finish();
-}
 SimpleTest.waitForExplicitFinish();
 window.open("printpreview_bug396024_helper.xul", "bug396024", "chrome,width=100,height=100");
 ]]></script>
 </window>
--- a/layout/base/tests/chrome/test_printpreview_bug482976.xul
+++ b/layout/base/tests/chrome/test_printpreview_bug482976.xul
@@ -11,33 +11,12 @@ https://bugzilla.mozilla.org/show_bug.cg
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
 <body xmlns="http://www.w3.org/1999/xhtml">
 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=482976"
    target="_blank">Mozilla Bug 482976</a>
 </body>
   <!-- test code goes here -->
 <script type="application/javascript">
 <![CDATA[
-if (navigator.platform.startsWith("Linux")) {
-  SimpleTest.expectAssertions(1); // bug 671976
-} else if (navigator.platform.startsWith("Win")) {
-  SimpleTest.expectAssertions(0, 2); // bug 671976
-}
-
 SimpleTest.waitForExplicitFinish();
-function parentFinish() {
-  // This is called while the helper window is still open.  Call
-  // doGC after it closes.
-  setTimeout(doGC, 0);
-}
-function doGC() {
-  // Garbage collecting the windows created in this test can cause
-  // assertions, so GC now to blame those assertions to this test.
-  // ("Destroying a currently-showing document", bug 671976)
-  SpecialPowers.gc();
-  setTimeout(doFinish, 0);
-}
-function doFinish() {
-  SimpleTest.finish();
-}
 window.open("printpreview_bug482976_helper.xul", "bug482976", "chrome,width=100,height=100");
 ]]></script>
 </window>
--- a/layout/forms/test/test_bug536567_perwindowpb.html
+++ b/layout/forms/test/test_bug536567_perwindowpb.html
@@ -9,21 +9,16 @@ https://bugzilla.mozilla.org/show_bug.cg
   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=536567">Mozilla Bug 536567</a>
 <p id="display"></p>
 <pre id="test">
 <script type="application/javascript">
-
-if (navigator.platform.startsWith("Win")) {
-  SimpleTest.expectAssertions(0, 1); // bug 671976 assertions leak to this test on Windows
-}
-
 /** Test for Bug 536567 **/
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 const Cm = Components.manager;
 
 Cu.import("resource://gre/modules/Services.jsm");
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -525,16 +525,22 @@ nsPrintEngine::DoCommonPrint(bool       
   // Check to see if there is a "regular" selection
   bool isSelection = IsThereARangeSelection(mPrt->mCurrentFocusWin);
 
   // Get the docshell for this documentviewer
   nsCOMPtr<nsIDocShell> webContainer(do_QueryReferent(mContainer, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   {
+    nsCOMPtr<nsIContentViewer> viewer;
+    webContainer->GetContentViewer(getter_AddRefs(viewer));
+    if (viewer && viewer->GetDocument() && viewer->GetDocument()->IsShowing()) {
+      viewer->GetDocument()->OnPageHide(false, nullptr);
+    }
+
     nsAutoScriptBlocker scriptBlocker;
     mPrt->mPrintObject = new nsPrintObject();
     NS_ENSURE_TRUE(mPrt->mPrintObject, NS_ERROR_OUT_OF_MEMORY);
     rv = mPrt->mPrintObject->Init(webContainer, aDoc, aIsPrintPreview);
     NS_ENSURE_SUCCESS(rv, rv);
 
     NS_ENSURE_TRUE(mPrt->mPrintDocList.AppendElement(mPrt->mPrintObject),
                    NS_ERROR_OUT_OF_MEMORY);