<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="../../../resources/js-test-pre.js"></script>
<style>
.testDiv {border-inline-start: 5px solid green; border-inline-end: 5px solid red; }
</style>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<div id="result"></div>

<div id="test" dir="auto" class="testDiv"></div>
<script>

description('Test that directionality is re-evaluated when an element with dir=auto set, has its dir attribute changed.');

var el = document.getElementById("test");
var child = document.createElement("div");
child.innerHTML="מקור השם עברית";
el.appendChild(child);
var child2 = document.createElement("div");
child2.innerHTML = "מקור השם עברית";
child2.setAttribute("dir", "auto");
child2.setAttribute("class", "testDiv");
child.appendChild(child2);
shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color')", "'rgb(0, 128, 0)'");
shouldBe("document.defaultView.getComputedStyle(child2, null).getPropertyValue('border-right-color')", "'rgb(0, 128, 0)'");

el.setAttribute("dir", "ltr");
shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color')", "'rgb(255, 0, 0)'");
shouldBe("document.defaultView.getComputedStyle(child2, null).getPropertyValue('border-right-color')", "'rgb(0, 128, 0)'");

child2.innerHTML = "Test";
shouldBe("document.defaultView.getComputedStyle(child2, null).getPropertyValue('border-right-color')", "'rgb(255, 0, 0)'");

el.setAttribute("dir", "auto");
shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color')", "'rgb(0, 128, 0)'");
shouldBe("document.defaultView.getComputedStyle(child2, null).getPropertyValue('border-right-color')", "'rgb(255, 0, 0)'");

el.style.display = "none";
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>
