<!DOCTYPE html>
<html>
<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('In HTML, attributes should be ASCII case-insensitive. This test mostly checks Element.hasAttribute() with different source for setting the attribute.');

var testContainer = document.getElementById('test-container');

function testAttributeOnTarget(equivalentNames, distinctNames) {
    for (var equivalentName of equivalentNames) {
        shouldBeTrue('document.getElementById("target").hasAttribute("' + equivalentName + '")');
        shouldBeEqualToString('document.getElementById("target").getAttribute("' + equivalentName + '")', 'WebKit!');
    }

    for (var distinctName of distinctNames) {
        shouldBeFalse('document.getElementById("target").hasAttribute("' + distinctName + '")');
        shouldBe('document.getElementById("target").getAttribute("' + distinctName + '")', 'null');
    }

    var target = document.getElementById("target");
    for (var distinctName of distinctNames) {
        target.removeAttribute(distinctName);
    }

    for (var equivalentName of equivalentNames) {
        shouldBeTrue('document.getElementById("target").hasAttribute("' + equivalentName + '")');
        shouldBeEqualToString('document.getElementById("target").getAttribute("' + equivalentName + '")', 'WebKit!');
    }
}

function testParsedAttribute(attribute, equivalentNames, distinctNames) {
    testContainer.innerHTML = '<div ' + attribute + '="WebKit!" id="target"></div>';
    testAttributeOnTarget(equivalentNames, distinctNames);
    testContainer.innerHTML = '';
}

function testAttributeFromDOMApis(attribute, equivalentNames, distinctNames) {
    var newElement = document.createElement('div');
    newElement.setAttribute('id', 'target');
    newElement.setAttribute(attribute, "WebKit!");
    testContainer.appendChild(newElement);
    testAttributeOnTarget(equivalentNames, distinctNames);
    testContainer.innerHTML = '';
}

function testAttribute(equivalentNames, distinctNames) {
    for (var testCase of equivalentNames) {
        debug("Testing " + testCase);
        testParsedAttribute(testCase, equivalentNames, distinctNames);
        testAttributeFromDOMApis(testCase, equivalentNames, distinctNames);
        debug("");
    }
}

testAttribute(['data-æøå', 'DATA-æøå', 'Data-æøå'], ['data-ÆØÅ', 'data-Æøå']);
testAttribute(['data-Æøå', 'DATA-Æøå', 'Data-Æøå'], ['data-ÆØÅ', 'data-æøå']);
testAttribute(['data-ÆØÅ', 'DATA-ÆØÅ', 'Data-ÆØÅ'], ['data-Æøå', 'data-æøå']);
</script>
<script src="../../../resources/js-test-post.js"></script>
</html>
