summaryrefslogtreecommitdiffstats
path: root/dom/plugins/test/mochitest/test_convertpoint.xul
blob: 5db01a253eeae1c0459c7fd6dfb370fd20c4f597 (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
<?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"?>
<window title="Basic Plugin Tests"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
  <script type="application/javascript" src="plugin-utils.js"></script>
  <script type="application/javascript">
    setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
  </script>
<body xmlns="http://www.w3.org/1999/xhtml" onload="runTests()">
<embed id="plugin1" type="application/x-test" width="200" height="200"></embed>
</body>
<script class="testbody" type="application/javascript">
<![CDATA[
SimpleTest.waitForExplicitFinish();

function runTests() {
  var pluginElement = document.getElementById("plugin1");
  // Poll to see if the plugin is in the right place yet.
  // Check if x-coordinate 0 in plugin space is 0 in window space. If it is,
  // the plugin hasn't been placed yet.
  if (pluginElement.convertPointX(1, 0, 0, 2) == 0) {
    setTimeout(runTests, 0);
    return;
  }

  var domWindowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                             .getInterface(Components.interfaces.nsIDOMWindowUtils);

  var pluginRect = pluginElement.getBoundingClientRect();
  var pluginX = pluginRect.left + (window.mozInnerScreenX - window.screenX);
  var pluginY = pluginRect.top + (window.mozInnerScreenY - window.screenY);

  var windowX = window.screenX;
  var windowY = window.screenY;
  var windowHeight = window.outerHeight;

  var screenHeight = window.screen.height;

  // arbitrary coordinates of test point in plugin top-left origin terms
  var xOffset = 5;
  var yOffset = 5;

  var NPCoordinateSpacePluginX = 0 + xOffset;
  var NPCoordinateSpacePluginY = 0 + yOffset;

  var NPCoordinateSpaceWindowX = pluginX + xOffset;
  var NPCoordinateSpaceWindowY = (windowHeight - pluginY) - yOffset;

  var NPCoordinateSpaceFlippedWindowX = pluginX + xOffset;
  var NPCoordinateSpaceFlippedWindowY = pluginY + yOffset;

  var NPCoordinateSpaceScreenX = windowX + pluginX + xOffset;
  var NPCoordinateSpaceScreenY = ((screenHeight - windowY) - pluginY) - yOffset;

  var NPCoordinateSpaceFlippedScreenX = windowX + pluginX + xOffset;
  var NPCoordinateSpaceFlippedScreenY = windowY + pluginY + yOffset;

  // these are in coordinate space enumeration order
  var xValues = new Array(NPCoordinateSpacePluginX, NPCoordinateSpaceWindowX, NPCoordinateSpaceFlippedWindowX, NPCoordinateSpaceScreenX, NPCoordinateSpaceFlippedScreenX);
  var yValues = new Array(NPCoordinateSpacePluginY, NPCoordinateSpaceWindowY, NPCoordinateSpaceFlippedWindowY, NPCoordinateSpaceScreenY, NPCoordinateSpaceFlippedScreenY);

  var i;
  for (i = 0; i < 5; i = i + 1) {
    var sourceCoordSpaceValue = i + 1;
    var j;
    for (j = 0; j < 5; j = j + 1) {
      var destCoordSpaceValue = j + 1;
      xResult = pluginElement.convertPointX(sourceCoordSpaceValue, xValues[i], yValues[i], destCoordSpaceValue);
      yResult = pluginElement.convertPointY(sourceCoordSpaceValue, xValues[i], yValues[i], destCoordSpaceValue);
      is(xResult, xValues[j], "convertPointX: space " + sourceCoordSpaceValue + " to space " + destCoordSpaceValue + " mismatch");
      is(yResult, yValues[j], "convertPointY: space " + sourceCoordSpaceValue + " to space " + destCoordSpaceValue + " mismatch");
    }
  }

  SimpleTest.finish();
}
]]>
</script>
</window>