summaryrefslogtreecommitdiffstats
path: root/widget/tests/test_bug444800.xhtml
blob: f6d3535d722139a9fdc02b0d203ae2bc2a7a0741 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin"
                 type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
                 type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=444800
-->
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        title="Mozilla Bug 444800" onload="initAndRunTests()">
  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>

  <body xmlns="http://www.w3.org/1999/xhtml">
  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=444800"
     target="_blank">Mozilla Bug 444800</a>
  <p/>
  <img id="bitmapImage" src="data:image/bmp;base64,Qk2KAwAAAAAAAIoAAAB8AAAADwAAABAAAAABABgAAAAAAAADAAASCwAAEgsAAAAAAAAAAAAAAAD%2FAAD%2FAAD%2FAAAAAAAA%2FwEAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FAAAA%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F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F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FAAAA"/>
  <p/>
  <pre id="test">
  </pre>
  </body>

  <script class="testbody" type="application/javascript">
  <![CDATA[
const knsIClipboard = Ci.nsIClipboard;

function copyImageToClipboard()
{
  SpecialPowers.setCommandNode(window, document.getElementById("bitmapImage"));

  const kCmd = "cmd_copyImageContents";
  var controller = top.document.commandDispatcher
                   .getControllerForCommand(kCmd);
  ok((controller && controller.isCommandEnabled(kCmd)), "have copy command");
  controller.doCommand(kCmd);

  SpecialPowers.setCommandNode(window, null);
}

function getLoadContext() {
  return window.docShell.QueryInterface(Ci.nsILoadContext);
}

function runImageClipboardTests(aCBSvc, aImageType)
{
  // Verify that hasDataMatchingFlavors() is working correctly.
  var typeArray = [ aImageType ];
  var hasImage = aCBSvc.hasDataMatchingFlavors(typeArray,
                                               knsIClipboard.kGlobalClipboard);
  ok(hasImage, aImageType + " - hasDataMatchingFlavors()");

  // Verify that getData() is working correctly.
  var xfer = Cc["@mozilla.org/widget/transferable;1"]
               .createInstance(Ci.nsITransferable);
  xfer.init(getLoadContext());
  xfer.addDataFlavor(aImageType);
  aCBSvc.getData(xfer, knsIClipboard.kGlobalClipboard, SpecialPowers.wrap(window).browsingContext.currentWindowContext);

  var typeObj = {}, dataObj = {};
  xfer.getAnyTransferData(typeObj, dataObj);
  var gotValue = (null != dataObj.value);
  ok(gotValue, aImageType + " - getData() returned a value");
  if (gotValue)
  {
    const knsIInputStream = Ci.nsIInputStream;
    var imgStream = dataObj.value.QueryInterface(knsIInputStream);
    ok((null != imgStream), aImageType + " - got an nsIInputStream");
    var bytesAvailable = imgStream.available();
    ok((bytesAvailable > 10), aImageType + " - got some data");
  }
}

function initAndRunTests()
{
  SimpleTest.waitForExplicitFinish();

  copyImageToClipboard();

  var cbSvc = Cc["@mozilla.org/widget/clipboard;1"]
                .getService(knsIClipboard);

  // Work around a problem on Windows where clipboard is not ready after copy.
  setTimeout(function() { runTests(cbSvc); }, 0);
}

function runTests(aCBSvc)
{
  runImageClipboardTests(aCBSvc, "image/png");
  runImageClipboardTests(aCBSvc, "image/jpg");
  runImageClipboardTests(aCBSvc, "image/jpeg");

  SimpleTest.finish();
}

]]>
</script>
</window>