summaryrefslogtreecommitdiffstats
path: root/dom/plugins/test/mochitest/test_visibility.html
blob: 943fddaf4ec98522c4ada6bd682d19c08d93ca24 (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
98
99
100
<!DOCTYPE html>
<html>
<head>
  <title>Test whether windowless plugins receive correct visible/invisible notifications.</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />

  <style>
    .hidden { visibility: hidden; }
  </style>

<body onload="startTest()">
  <p id="display"></p>

  <script type="application/javascript" src="plugin-utils.js"></script>
  <script type="application/javascript">
  SimpleTest.waitForExplicitFinish();
  SimpleTest.requestFlakyTimeout("untriaged");
  setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);

  var didPaint = function() {};

  function startTest() {
    if (p.getPaintCount() < 1) {
      setTimeout(startTest, 0);
      return;
    }

    didPaint = function() {
      ok(false, "Plugin should not paint until it is visible!");
    };

    ok(!p.isVisible(), "Plugin should not be visible.");
    paintCountIs(p, 0, "Plugin should not have painted.");

    didPaint = part2;

    p.style.visibility = 'visible';
  }

  function part2() {
    ok(p.isVisible(), "Plugin should now be visible.");
    paintCountIs(p, 1, "Plugin should have painted once.");

    didPaint = part3;

    p.setColor('FF0000FF'); // this causes an invalidate/repaint
  }

  const kTimeout = 5000; // 5 seconds
  var part4GiveUp;
  var part4Interval;

  function part3() {
    ok(p.isVisible(), "Plugin should still be visible.");
    paintCountIs(p, 2, "Plugin should have painted twice.");

    didPaint = function() {
      ok(false, "Plugin should not paint when it is invisible.");
    };

    p.style.visibility = 'hidden';

    part4GiveUp = Date.now() + kTimeout;
    part4Interval = setInterval(part4, 100);
  }

  function part4() {
    if (p.isVisible()) {
      if (Date.now() < part4GiveUp)
        return;

      ok(false, "Plugin never became invisible in part4.");
      SimpleTest.finish();
      return;
    }

    clearInterval(part4Interval);

    ok(true, "Plugin became invisible again.");
    p.setColor('FF00FF00');
    setTimeout(SimpleTest.finish, 500);
    // wait to make sure we don't actually paint
  }

  function inPaint() {
    // We're actually in the middle of painting the plugin so don't do anything
    // complex here, for the sake of cases where async plugin painting isn't
    // enabled yet
    setTimeout(didPaint, 0);
    // Don't run that didPaint callback again
    didPaint = function() {};
  }
  </script>

  <embed id="theplugin" class="hidden" type="application/x-test" drawmode="solid" color="FFFF0000" paintscript="inPaint()"></embed>
  
  <script type="application/javascript">
  var p = document.getElementById('theplugin');
  </script>