https://github.com/mozilla/gecko-dev
Raw File
Tip revision: 30ce7b7e73de80444b4074c2384b406f5228b6e4 authored by Andrew Sutherland on 03 April 2020, 06:35:19 UTC
Bug 1626728 - Normalize shutdown. r=perry,jstutte, a=RyanVM
Tip revision: 30ce7b7
printpreview_bug482976_helper.xul
<?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=482976
-->
<window title="Mozilla Bug 482976" onload="run1()"
        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 SimpleTest = window.opener.wrappedJSObject.SimpleTest;
var gWbp;
function printpreview() {
  gWbp = window.frames[1].docShell.initOrReusePrintPreviewViewer();
  var listener = {
    onLocationChange: function(webProgress, request, location, flags) { },
    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) { },
    onContentBlockingEvent: function(webProgress, request, event) { },
    QueryInterface: function(iid) {
      if (iid.equals(Ci.nsIWebProgessListener) ||
          iid.equals(Ci.nsISupportsWeakReference))
            return this;
      throw Cr.NS_NOINTERFACE;
    }
  }
  var prefs = Cc["@mozilla.org/preferences-service;1"]
                .getService(Ci.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].docShell.exitPrintPreview();
}

function finish() {
  SimpleTest.finish();
  window.close();
}

function run1()
{
/** Test for Bug 482976 **/
  var printService = Cc["@mozilla.org/gfx/printsettings-service;1"]
                       .getService(Ci.nsIPrintSettingsService);

  try {
    Cc["@mozilla.org/gfx/printerenumerator;1"]
      .getService(Ci.nsIPrinterEnumerator);
  } catch(e) {
    todo(false, "Test skipped on MacOSX, as the print preview code doesn't work there");
    finish();
    return;
  }

  if (printService.defaultPrinterName != '') {
    printpreview();
    ok(gWbp.doingPrintPreview, "Should be doing print preview");
    exitprintpreview();
    ok(!gWbp.doingPrintPreview, "Should not be doing print preview anymore");
  } else {
    todo(false, "No printer seems installed on this machine, that is necessary for this test");
  }
  finish();
}
]]></script>
</window>
back to top