| 12
 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
 
 | <!DOCTYPE HTML>
<meta charset="UTF-8">
<title>CSS Toggles: creation of toggles</title>
<link rel="author" title="L. David Baron" href="https://dbaron.org/">
<link rel="author" title="Google" href="http://www.google.com/">
<link rel="help" href="https://tabatkins.github.io/css-toggle/#toggle-root-property">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/toggle-helpers.js"></script>
<body>
<div id="container"></div>
<script>
let container = document.getElementById("container");
promise_test(async () => {
  container.innerHTML = '<div id="t" style="toggle: mytoggle"></div>';
  let t = document.getElementById("t");
  await wait_for_toggle_creation(t);
  assert_false(t.matches(':toggle(mytoggle)'));
  assert_true(t.matches(':toggle(mytoggle 0)'));
  assert_false(t.matches(':toggle(mytoggle 1)'));
  t.click();
  assert_true(t.matches(':toggle(mytoggle)'));
  assert_false(t.matches(':toggle(mytoggle 0)'));
  assert_true(t.matches(':toggle(mytoggle 1)'));
  t.click();
  assert_true(t.matches(':toggle(mytoggle 0)'));
  assert_false(t.matches(':toggle(mytoggle 1)'));
}, "basic toggle creation");
promise_test(async () => {
  // Test that changing the toggle-root property to add 'self' doesn't change
  // the toggle's scope from wide to narrow.
  container.innerHTML = `
    <div id="a" style="toggle-root: changing-scope 3 at 2">
      <div id="b" style="toggle-trigger: changing-scope"></div>
    </div>
    <div id="c"></div>
  `;
  let a = document.getElementById("a");
  let b = document.getElementById("b");
  let c = document.getElementById("c");
  await wait_for_toggle_creation(a);
  assert_true(b.matches(':toggle(changing-scope 2)'));
  assert_true(c.matches(':toggle(changing-scope 2)'));
  a.style.toggleRoot = "changing-scope 3 at 2 self";
  await wait_for_toggle_creation(a);
  assert_true(b.matches(':toggle(changing-scope 2)'));
  assert_true(c.matches(':toggle(changing-scope 2)'));
  // The reverse -- removing 'self'.
  container.innerHTML = `
    <div id="a" style="toggle-root: changing-scope 3 at 2 self">
      <div id="b" style="toggle-trigger: changing-scope"></div>
    </div>
    <div id="c"></div>
  `;
  a = document.getElementById("a");
  b = document.getElementById("b");
  c = document.getElementById("c");
  await wait_for_toggle_creation(a);
  assert_true(b.matches(':toggle(changing-scope 2)'));
  assert_false(c.matches(':toggle(changing-scope 2)'));
  a.style.toggleRoot = "changing-scope 3 at 2";
  await wait_for_toggle_creation(a);
  assert_true(b.matches(':toggle(changing-scope 2)'));
  assert_false(c.matches(':toggle(changing-scope 2)'));
}, "changing toggle-root doesn't change toggle");
</script>
 |