summaryrefslogtreecommitdiffstats
path: root/layout/style/test/test_style_attr_listener.html
blob: b824fe7ff45fbf6b0bb3de0caf949c9b42fdc60b (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
<!DOCTYPE html>
<html>
<head>
  <title>Test for Bug 338679 (from bug 1340341)</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<div style=""></div>
<script>
SimpleTest.waitForExplicitFinish();

// Run the test first with mutation events enabled and then disabled.
SpecialPowers.pushPrefEnv(
  { 'set': [['dom.mutation-events.cssom.disabled', false]] },
  runTest
);

function runTest(stop) {
  let div = document.querySelector('div');
  let expectation;
  let count = 0;
  div.style.color = "red";
  div.addEventListener('DOMAttrModified', function(evt) {
    count++;
    is(evt.prevValue, expectation.prevValue, `Previous value for event ${count}`);
    is(evt.newValue, expectation.newValue, `New value for event ${count}`);
  });
  expectation = { prevValue: 'color: red;', newValue: 'color: green;' };
  div.style.color = "green";
  expectation = { prevValue: 'color: green;', newValue: '' };
  div.style.color = '';
  if (SpecialPowers.getBoolPref("dom.mutation-events.cssom.disabled")) {
    is(count, 0, "No DOMAttrModified event should be triggered");
  } else {
    is(count, 2, "DOMAttrModified events should have been triggered");
  }

  if (!stop) {
    div.setAttribute("style", "");
    SpecialPowers.pushPrefEnv(
      { 'set': [['dom.mutation-events.cssom.disabled', true]] },
      function() {
        runTest(true);
        SimpleTest.finish();
      }
    );
  }
}
</script>
</body>
</html>