summaryrefslogtreecommitdiffstats
path: root/layout/generic/test/test_plugin_position.xhtml
blob: f2e099628701d63d1434e8ccb5831b9a989bba2b (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
<?xml version="1.0"?>
<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
<html xmlns="http://www.w3.org/1999/xhtml" title="Test Plugin Positioning">
<head>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>

<!-- Use a XUL element here so we can get its screenX/Y -->
<hbox style="height:10px; position:absolute; left:0; top:0; z-index:-100;" id="h1"
      xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <hbox style="width:100px;"></hbox><hbox id="h2"/>
</hbox>

<embed id="p" type="application/x-test" width="200" height="200" wmode="window"></embed>
<embed id="p2" type="application/x-test" wmode="window"
       style="outline:5px solid blue; width:200px; height:200px;
              border:solid black; border-width:4px 8px 4px 8px;
              padding:3px 1px;">
</embed>

<script class="testbody" type="application/javascript">
<![CDATA[

var windowFrameX, windowFrameY;

function checkGeometry(id, x, y, w, h) {
  var p = document.getElementById(id);
  var bounds = p.getBoundingClientRect();
  var pX = p.getEdge(0);
  var pY = p.getEdge(1);
  var pWidth = p.getEdge(2) - pX;
  var pHeight = p.getEdge(3) - pY;

  is(pX, windowFrameX + bounds.left + x, id + " plugin X");
  is(pY, windowFrameY + bounds.top + y, id + " plugin Y");
  is(pWidth, w, id + " plugin width");
  is(pHeight, h, id + " plugin height");
}

function runTests() {
  var h1 = document.getElementById("h1");
  var h2 = document.getElementById("h2");
  var hwidth = h2.screenX - h1.screenX;
  if (hwidth != 100) {
    // Maybe it's a DPI issue
    todo(false, "Unexpected DPI?");
    SimpleTest.finish();
    return;
  }

  if (!document.getElementById("p").identifierToStringTest) {
    todo(false, "Test plugin not available");
    SimpleTest.finish();
    return;
  }

  var bounds = h1.getBoundingClientRect();
  windowFrameX = h1.screenX - bounds.left - window.screenX;
  windowFrameY = h1.screenY - bounds.top - window.screenY;

  checkGeometry("p", 0, 0, 200, 200);
  // This one tests widget positioning in the presence of borders and padding
  checkGeometry("p2", 9, 7, 182, 186);

  SimpleTest.finish();
}

// When load events run, painting may still be suppressed for the window.
// While painting is suppressed, plugins are hidden so won't be positioned
// or sized as expected.
// So call runTests after the load event has finished, when painting will
// be unsuppressed.
addLoadEvent(function() { setTimeout(runTests, 1000); });
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout("untriaged");

]]>
</script>

</body>
</html>