<html>
<head>
<link rel="stylesheet" href="resources/detached-style.css" type="text/css" media="screen">
<style>* { }</style>
<script src="../../../resources/js-test-pre.js"></script>
</head>
<body>
<p><a href="https://bugs.webkit.org/show_bug.cgi?id=45205">Bug 45205</a>:
Test that &lt;link> elements only have stylesheets when in document.</p>
<div id="console"></div>
<script>
    debug("Testing &lt;link>...");
    sheet = document.styleSheets[0];
    head = document.getElementsByTagName("head")[0];
    link = document.getElementsByTagName("link")[0];

    shouldBe('sheet.ownerNode', 'link')
    shouldBe('link.sheet === sheet', 'true')

    debug("Removing &lt;link>...");
    head.removeChild(link);

    shouldBe('link.sheet', 'null')
    shouldBe('sheet.ownerNode', 'null')
    shouldBe('sheet.cssRules[0].cssText[0]', '"*"')

    debug("Re-adding &lt;link>...");
    head.appendChild(link);
    shouldBe('sheet.ownerNode', 'null')
    shouldBe('link.sheet === sheet', 'false')
    shouldBe('link.sheet.ownerNode', 'link')

    debug("Testing &lt;style>...");
    sheet = document.styleSheets[0];
    head = document.getElementsByTagName("head")[0];
    style = document.getElementsByTagName("style")[0];

    shouldBe('sheet.ownerNode', 'style')
    shouldBe('style.sheet', 'sheet')

    debug("Removing &lt;style>...");
    head.removeChild(style);

    shouldBe('style.sheet', 'null')
    shouldBe('sheet.ownerNode', 'null')
    shouldBe('sheet.cssRules[0].cssText[0]', '"*"')

    debug("Re-adding &lt;style>...");
    head.appendChild(style);
    shouldBe('sheet.ownerNode', 'null')
    shouldBe('style.sheet === sheet', 'false')
    shouldBe('style.sheet.ownerNode', 'style')

</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>
