<!DOCTYPE html>
<html>
<body>
<script src="../../../resources/js-test-pre.js"></script>
<script>

function newDoc(markup) {
    var iframe = document.createElement('iframe');
    document.body.appendChild(iframe);
    iframe.contentDocument.documentElement.innerHTML = '<head></head><body></body>';
    iframe.contentDocument.body.innerHTML = markup;
    window.doc = iframe.contentDocument;
    window.$ = iframe.contentDocument.querySelector.bind(iframe.contentDocument);
}

function element(name, markup) {
    var element = doc.createElement(name);
    element.textContent = markup;
    return element;
}

description('This test updates contenteditable content attribute, contentEditable IDL property, and -webkit-user-modify CSS property dynamically.');

shouldBeFalse('newDoc("<div></div>"); $("div").isContentEditable');
shouldBeTrue('$("div").contentEditable = "true"; $("div").isContentEditable');
shouldBeTrue('newDoc("<div contenteditable=true></div>"); $("div").isContentEditable');
shouldBeFalse('$("div").contentEditable = "false"; $("div").isContentEditable');
shouldBeTrue('newDoc("<div contenteditable=plaintext-only></div>"); $("div").isContentEditable');
shouldBeFalse('$("div").contentEditable = "false"; $("div").isContentEditable');

debug('');
debug('Style rules');
shouldBeTrue('newDoc("<div></div><style> div { -webkit-user-modify: read-write; } </style>"); $("div").isContentEditable');
shouldBeFalse('$("style").textContent = ""; $("div").isContentEditable');
shouldBeTrue('$("style").textContent = "* { -webkit-user-modify: read-write-plaintext-only; }"; $("div").isContentEditable');
shouldBeFalse('newDoc("<div></div>"); style = element("style", "* { -webkit-user-modify: read-write }"); $("div").isContentEditable');
shouldBeTrue('$("body").appendChild(style); $("div").isContentEditable');
shouldBeFalse('newDoc("<div></div><style></style>"); $("div").isContentEditable');
shouldBeTrue('$("style").sheet.insertRule("* { -webkit-user-modify: read-write; }", 0); $("div").isContentEditable');
shouldBeFalse('$("style").sheet.insertRule("* { -webkit-user-modify: read-only !important; }", 0); $("div").isContentEditable');

debug('');
debug('Inline styles');
shouldBeTrue('newDoc("<div style=\'-webkit-user-modify:read-write\'></div>"); $("div").isContentEditable');
shouldBeTrue('$("head").innerHTML = "<base href=\'http://localhost/\'>"; $("div").isContentEditable');
shouldBeFalse('$("div").style.webkitUserModify = ""; $("div").isContentEditable');
shouldBeTrue('newDoc("<div></div>"); $("div").style.webkitUserModify = "read-write"; $("div").isContentEditable');
shouldBeFalse('$("div").setAttribute("style", ""); $("div").isContentEditable');
shouldBeFalse('newDoc("<div></div>"); $("div").isContentEditable');
shouldBeTrue('$("div").setAttribute("style", "-webkit-user-modify: read-write"); $("div").isContentEditable');
shouldBeFalse('$("div").setAttribute("style", "-webkit-user-modify: read-only"); $("div").isContentEditable');

var iframes = document.querySelectorAll('iframe');
for (var i = 0; i < iframes.length; i++)
    document.body.removeChild(iframes[i]);

var successfullyParsed = true;
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>
