chromium/third_party/blink/web_tests/fast/forms/input-common/value-null.html

<!DOCTYPE html>
<html>
<head>
<title>This test checks that assigning null to HTMLInputElement.value behaves
correctly; i.e. as if the empty string was assigned.</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<link rel="stylesheet" href="../../../resources/testharness.css">
</head>
<body>
<form style="display: none">
<input id="text-with-default" type="text" value="default">
<input id="text-without-default" type="text">
<input id="hidden" type="hidden" value="value">
</form>
<script>

test(function () {
    var input = document.getElementById("text-with-default");

    assert_equals(input.value, "default");
    assert_equals(input.getAttribute("value"), "default");

    input.value = "custom";

    assert_equals(input.value, "custom");
    assert_equals(input.getAttribute("value"), "default");

    input.value = null;

    assert_equals(input.value, "");
    assert_true(input.hasAttribute("value"));
}, "input[type=text] with value content attribute.");

test(function () {
    var input = document.getElementById("text-without-default");

    assert_equals(input.value, "");
    assert_false(input.hasAttribute("value"));

    input.value = null;

    assert_equals(input.value, "");
    assert_false(input.hasAttribute("value"));
}, "input[type=text] without value content attribute.");

test(function () {
    var input = document.getElementById("hidden");

    assert_equals(input.value, "value");
    assert_equals(input.getAttribute("value"), "value");

    input.value = null;

    assert_equals(input.value, "");
    assert_true(input.hasAttribute("value"));
    assert_equals(input.getAttribute("value"), "");
}, "input[type=hidden] with value content attribute.");

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