chromium/third_party/blink/web_tests/fast/dom/domstring-attribute-reflection.html

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

function testDOMStringReflection(elementName, contentAttributeName, idlAttributeName, treatNullAsEmptyString) {
    idlAttributeName = idlAttributeName || contentAttributeName;
    element = document.createElement(elementName);
    debug('Reflected DOMString attribute test for ' + elementName + '/@' + contentAttributeName);
    debug('Initial value:');
    shouldBeEqualToString('element.' + idlAttributeName, '');
    shouldBeNull('element.getAttribute("' + contentAttributeName + '")');

    debug('Setting a value via the IDL attribute:');
    shouldBeEqualToString('element.' + idlAttributeName + ' = "foo"; element.' + idlAttributeName, 'foo');
    shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', 'foo');

    debug('Setting a value via the content attribute:');
    shouldBeEqualToString('element.setAttribute("' + contentAttributeName + '", " bar\\n"); element.' + idlAttributeName, ' bar\n');
    shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', ' bar\n');

    debug('Setting null via the IDL attribute:');
    if (treatNullAsEmptyString) {
        shouldBeEqualToString('element.' + idlAttributeName + ' = null; element.' + idlAttributeName, '');
        shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', '');
    } else {
        shouldBeEqualToString('element.' + idlAttributeName + ' = null; element.' + idlAttributeName, 'null');
        shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', 'null');
    }

    debug('Setting null via the content attribute:');
    shouldBeEqualToString('element.setAttribute("' + contentAttributeName + '", null); element.' + idlAttributeName, 'null');
    shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', 'null');

    debug('Setting undefined via the IDL attribute:');
    shouldBeEqualToString('element.' + idlAttributeName + ' = undefined; element.' + idlAttributeName, 'undefined');
    shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', 'undefined');

    debug('Setting undefined via the content attribute:');
    shouldBeEqualToString('element.setAttribute("' + contentAttributeName + '", undefined); element.' + idlAttributeName, 'undefined');
    shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', 'undefined');

    debug('Setting non-string via the IDL attribute:');
    shouldBeEqualToString('element.' + idlAttributeName + ' = 123; element.' + idlAttributeName, '123');
    shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', '123');

    debug('Setting non-string via the content attribute:');
    shouldBeEqualToString('element.setAttribute("' + contentAttributeName + '", 456); element.' + idlAttributeName, '456');
    shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', '456');

    debug('\n');
}

testDOMStringReflection('button', 'name');
testDOMStringReflection('fieldset', 'name');
testDOMStringReflection('form', 'name');
testDOMStringReflection('input', 'name');
testDOMStringReflection('input', 'step');
testDOMStringReflection('object', 'name');
testDOMStringReflection('output', 'name');
testDOMStringReflection('select', 'name');
testDOMStringReflection('textarea', 'name');

// [TreatNullAs=EmptyString]
testDOMStringReflection('frame', 'marginheight', 'marginHeight', true);
testDOMStringReflection('frame', 'marginwidth', 'marginWidth', true);
testDOMStringReflection('iframe', 'marginheight', 'marginHeight', true);
testDOMStringReflection('iframe', 'marginwidth', 'marginWidth', true);
testDOMStringReflection('body', 'text', 'text', true);
testDOMStringReflection('body', 'link', 'link', true);
testDOMStringReflection('body', 'alink', 'aLink', true);
testDOMStringReflection('body', 'vlink', 'vLink', true);
testDOMStringReflection('body', 'bgcolor', 'bgColor', true);
testDOMStringReflection('font', 'color', 'color', true);
testDOMStringReflection('img', 'border', 'border', true);
testDOMStringReflection('object', 'border', 'border', true);
testDOMStringReflection('table', 'bgcolor', 'bgColor', true);
testDOMStringReflection('table', 'cellpadding', 'cellPadding', true);
testDOMStringReflection('table', 'cellspacing', 'cellSpacing', true);
testDOMStringReflection('td', 'bgcolor', 'bgColor', true);
testDOMStringReflection('th', 'bgcolor', 'bgColor', true);
testDOMStringReflection('tr', 'bgcolor', 'bgColor', true);


// Add more DOMString attributes!

</script>
</body>
</html>