<!DOCTYPE html>
<!--
     Any copyright is dedicated to the Public Domain.
     http://creativecommons.org/publicdomain/zero/1.0/
-->
<html class="reftest-wait" lang="en-US">
  <head>
  <title>Test LEGEND placed into FIELDSET shadow DOM</title>
  <link rel="author" title="Mats Palmgren" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1140579">
  <link rel="match" href="shadow-dom-ref.html">
<style>
html,body {
    color:black; background-color:white; font-size:16px; padding:0; margin:0;
}
.before::before {content: "a ";}
.after::after {content: " c";}
div.before::before {content: "X ";}
div.after::after {content: " Y";}
.b,.c { display:contents; }
</style>
  </head>
  <body>
    <fieldset id="host1" class="before"></fieldset>
    <fieldset id="host2"></fieldset>
    <fieldset id="host3" class="after"></fieldset>
    <fieldset id="host4" class="before after"></fieldset>
    <fieldset id="host5" class="after"></fieldset>
    <fieldset id="host6" class="before"></fieldset>
    <fieldset id="host7"></fieldset>
    <fieldset id="host8"></fieldset>
    <fieldset id="host9"></fieldset>

   <script>
      function shadow(id) {
        return document.getElementById(id).createShadowRoot();
      }
      function legend(s) {
        var e = document.createElement("legend");
        var t = document.createTextNode(s);
        e.appendChild(t);
        return e;
      }
      function contents(n) {
        var e = document.createElement("z");
        e.style.display = "contents";
        e.style.color = "blue"; 
        if (n) e.appendChild(n);
        return e;
      }

      document.body.offsetHeight;

      shadow("host1").innerHTML = '<content></content> c';
      shadow("host2").innerHTML = 'a <content></content> c';
      shadow("host3").innerHTML = 'a <content></content>';
      shadow("host4").innerHTML = '<content></content>';
      shadow("host5").innerHTML = 'a <content></content>';
      shadow("host6").innerHTML = '<z style="color:blue; display:contents"><content></content></z> c';
      shadow("host7").innerHTML = 'a <content select=".c"></content> <content select=".b"></content> B';
      shadow("host8").innerHTML = 'A <content select=".c"></content> <content select=".b"></content> B';
      shadow("host9").innerHTML = 'A <content select=".c"></content> <content select=".b"></content> B <content select=".b"></content>';

      function tweak() {
        document.body.offsetHeight;

        host1.appendChild(legend("1"));
        host2.appendChild(legend("2"));
        host3.appendChild(legend("3"));
        host4.appendChild(legend("4"));

        var e = legend("5");
        e.style.display = "contents";
        host5.appendChild(e);

        host6.appendChild(legend("6"));

        var e = legend("L");
        e.className = "b";
        host7.appendChild(e);
        var e = legend("7");
        e.className = "c";
        host7.appendChild(e);

        var e = legend("L");
        e.className = "b after";
        host8.appendChild(e);
        var e = legend("8");
        e.className = "c  before";
        host8.appendChild(e);

        var e = legend("L2");
        e.className = "b before after";
        host9.appendChild(e);
        var e = contents(legend(" L3"));
        e.className = "b before after";
        host9.appendChild(e);
        var e = legend("9");
        e.className = "c  before";
        host9.appendChild(e);

        document.body.offsetHeight;
        setTimeout(function() {
            document.body.offsetHeight;
            document.documentElement.removeAttribute("class");
          },0);
      }

      window.addEventListener("MozReftestInvalidate", tweak, false);
    </script>
  </body>
</html>