summaryrefslogtreecommitdiffstats
path: root/layout/base/tests/chrome/printpreview_bug482976_helper.xhtml
blob: cd23c90d7b5450db0f707dca48c3f6492c2894f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?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[
// Note: We can't use window.frames directly here because the type="content"
// attributes isolate the frames into their own BrowsingContext hierarchies.
let frameElts = document.getElementsByTagName("iframe");

var is = window.arguments[0].is;
var ok = window.arguments[0].ok;
var todo = window.arguments[0].todo;
var SimpleTest = window.arguments[0].SimpleTest;
var gWbp;
var gPrintPreviewWin;
function printpreview() {
  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.nsIWebProgressListener) ||
          iid.equals(Ci.nsISupportsWeakReference))
            return this;
      throw Components.Exception("", Cr.NS_NOINTERFACE);
    }
  }

  let settings = Cc["@mozilla.org/gfx/printsettings-service;1"]
                       .getService(Ci.nsIPrintSettingsService).createNewPrintSettings();

  gPrintPreviewWin = frameElts[0].contentWindow.printPreview(settings, listener);
  gWbp = gPrintPreviewWin.docShell.contentViewer;
  gWbp.QueryInterface(Ci.nsIWebBrowserPrint);
}

function exitprintpreview() {
  gPrintPreviewWin.docShell.exitPrintPreview();
  gPrintPreviewWin.close();
}

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

async function run1() {
  printpreview();
  ok(gWbp.doingPrintPreview, "Should be doing print preview");
  exitprintpreview();
  ok(!gWbp.doingPrintPreview, "Should not be doing print preview anymore");
  finish();
}
]]></script>
</window>