<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("This test checks a form element can handle elements of which form attribute points the form element even if elements are outside of the form.");

if (window.testRunner)
    testRunner.waitUntilDone();

var container = document.createElement('div');
document.body.appendChild(container);

container.innerHTML = '<input type=hidden name=key1 value=value1 id=outer-before form=owner />' +
    '<form id=owner action="" method="GET">' +
    '    <input type=hidden name=key2 value=value2 id=inner form=owner />' +
    '</form>' +
    '<input type=hidden name=submitted value=true id=outer-after form=owner />';

var owner = document.getElementById('owner');
var outerBefore = document.getElementById('outer-before');
var inner = document.getElementById('inner');
var outerAfter = document.getElementById('outer-after');
var query = window.location.search;

if (query.indexOf('submitted=true') == -1) {
    owner.submit();
} else {
    debug('- Ensures that elements attribute of the form contains elements which are outside of the form.');

    shouldBe('owner.elements.length', '3');
    shouldBe('owner.elements[0]', 'outerBefore');
    shouldBe('owner.elements[1]', 'inner');
    shouldBe('owner.elements[2]', 'outerAfter');

    debug('');
    debug('- Ensures that form submission contains name and value pairs for such elements.');
    var pairs = query.substr(1).split('&');
    shouldBe('pairs.length', '3');
    shouldBeEqualToString('pairs[0]', 'key1=value1');
    shouldBeEqualToString('pairs[1]', 'key2=value2');
    shouldBeEqualToString('pairs[2]', 'submitted=true');
    if (window.testRunner)
        testRunner.notifyDone();
}
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>
