blob: de29ee4855ef46428dd4579913da3d8899f1f065 [file] [log] [blame]
<!DOCTYPE html>
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
<script src="../../../resources/js-test-pre.js"></script>
</head>
<body>
<div id="test-container" style="display: none;"></div>
</body>
<script>
description('Test using setAttributeNode() behaves like setAttribute() to get the existing attribute, but like setAttributeNS() to set the new value."');
document.documentElement.setAttribute('FooBar', 'WebKit');
shouldBeNull('document.documentElement.getAttribute("foobar")');
shouldBeFalse('document.documentElement.hasAttribute("foobar")');
shouldBeEqualToString('document.documentElement.getAttribute("FooBar")', 'WebKit');
shouldBeTrue('document.documentElement.hasAttribute("FooBar")');
shouldBeNull('document.documentElement.getAttributeNS("", "foobar")', 'WebKit');
shouldBeFalse('document.documentElement.hasAttributeNS("", "foobar")');
shouldBeEqualToString('document.documentElement.getAttributeNS("", "FooBar")', 'WebKit');
shouldBeTrue('document.documentElement.hasAttributeNS("", "FooBar")');
shouldBe('document.documentElement.attributes.length', '3');
// Should replace the value of "FooBar" by "WebKit".
var camelCaseFoobar = document.createAttribute("FooBar");
camelCaseFoobar.value = 'Rocks!'
var oldAttributeNode = document.documentElement.setAttributeNode(camelCaseFoobar);
shouldNotBe('camelCaseFoobar', 'oldAttributeNode');
shouldBe('document.documentElement.getAttribute("foobar")', 'null');
shouldBeFalse('document.documentElement.hasAttribute("foobar")');
shouldBeEqualToString('document.documentElement.getAttribute("FooBar")', 'Rocks!');
shouldBeTrue('document.documentElement.hasAttribute("FooBar")');
shouldBe('document.documentElement.getAttributeNS("", "foobar")', 'null');
shouldBeFalse('document.documentElement.hasAttributeNS("", "foobar")');
shouldBeEqualToString('document.documentElement.getAttributeNS("", "FooBar")', 'Rocks!');
shouldBeTrue('document.documentElement.hasAttributeNS("", "FooBar")');
// "foobar" should exist alongside "FooBar".
var lowerCaseFoobar = document.createAttribute("foobar");
lowerCaseFoobar.value = 'WebKit2'
var oldAttributeNode2 = document.documentElement.setAttributeNode(lowerCaseFoobar);
shouldBe('oldAttributeNode2', 'null');
shouldBeEqualToString('document.documentElement.getAttribute("foobar")', 'WebKit2');
shouldBeTrue('document.documentElement.hasAttribute("foobar")');
shouldBeEqualToString('document.documentElement.getAttribute("FooBar")', 'Rocks!');
shouldBeTrue('document.documentElement.hasAttribute("FooBar")');
shouldBeEqualToString('document.documentElement.getAttributeNS("", "foobar")', 'WebKit2');
shouldBeTrue('document.documentElement.hasAttributeNS("", "foobar")');
shouldBeEqualToString('document.documentElement.getAttributeNS("", "FooBar")', 'Rocks!');
shouldBeTrue('document.documentElement.hasAttributeNS("", "FooBar")');
</script>
<script src="../../../resources/js-test-post.js"></script>
</html>