<html>
<head>
    <script src="../../resources/js-test-pre.js"></script>
    <script>
    function test() {
        if (window.testRunner) {
            testRunner.dumpAsText();
        }

        var tf = document.getElementById('tf');
        var computedStyle = document.defaultView.getComputedStyle(tf);
        var originalForeground = computedStyle.color;
        var originalBackground = computedStyle.backgroundColor;

        if (window.internals) {
            window.internals.setAutoFilledAndObscured(tf, true);
        }

        // Both the foreground and background colors should change.
        computedStyle = document.defaultView.getComputedStyle(tf);
        var autofilledForeground = computedStyle.color;
        var autofilledBackground = computedStyle.backgroundColor;
        if (autofilledForeground == originalForeground) {
            testFailed('Foreground color did not change when autofilled.');
            return;
        }
        if (autofilledBackground == originalBackground) {
            testFailed('Background color did not change when autofilled.');
            return;
        }
		
		tf.value = "";

        // Colors should be restored.
        computedStyle = document.defaultView.getComputedStyle(tf);
        if (computedStyle.color !== originalForeground) {
            testFailed('Foreground color did not revert when field was emptied.');
            return;
        }
        if (computedStyle.backgroundColor !== originalBackground) {
            testFailed('Background color did not revert when field was emptied.');
            return;
        }

        testPassed('');
    }
    </script>

    <style>
    #tf {
      color: #FFFFFF;
      background-color: #FFFFFF;
    }
    </style>
</head>
<body onload="test()">
    This tests that foreground and background colors properly change for autofilled-and-obscured inputs. It can only be run using DumpRenderTree.<br>
    <form name="fm">
        <input type="text" id="tf" value="Field value" />
    </form>
    <div id="console"></div>
</body>
</html>
