layout/style/test/test_style_attr_listener.html
author Cristian Tuns <ctuns@mozilla.com>
Wed, 22 Sep 2021 08:44:17 -0400
changeset 592892 488c5f6dfe3ead33952f232a52cf0ed4a4208640
parent 469640 c9c0c6f2eed54a187e124942e53c3660b4cf17d8
permissions -rw-r--r--
Backed out 2 changesets (bug 1731223) for likely causing localized Windows builds to break (bug 1732034) a=backout Backed out changeset 0aa04e588a4e (bug 1731223) Backed out changeset 59a15d9c5391 (bug 1731223)

<!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>