2 <script src="../../resources/js-test.js"></script>
5 if (window.testRunner) {
6 testRunner.dumpAsText();
9 if (!window.internals) {
10 testFailed('This test requires the test harness to run.');
14 var field = document.getElementById('field');
15 var textarea = document.getElementById('textarea');
16 var select = document.getElementById('select');
18 var computedStyleField = document.defaultView.getComputedStyle(field);
19 var computedStyleTextarea = document.defaultView.getComputedStyle(textarea);
20 var computedStyleSelect = document.defaultView.getComputedStyle(select);
21 var originalForeground = computedStyleField.color;
22 var originalBackground = computedStyleField.backgroundColor;
24 if (originalForeground != computedStyleTextarea.color) {
25 testFailed('Unexpected initial foreground color for <textarea> field.');
28 if (originalForeground != computedStyleTextarea.backgroundColor) {
29 testFailed('Unexpected initial background color for <textarea> field.');
33 if (window.internals) {
34 window.internals.setAutofilled(field, true);
35 window.internals.setAutofilled(textarea, true);
36 window.internals.setAutofilled(select, true);
39 // Both the foreground and background colors should change.
40 computedStyleField = document.defaultView.getComputedStyle(field);
41 computedStyleTextarea = document.defaultView.getComputedStyle(textarea);
42 computedStyleSelect = document.defaultView.getComputedStyle(select);
43 if (computedStyleField.color == originalForeground) {
44 testFailed('Foreground color for <input> element did not change when autofilled.');
47 if (computedStyleField.backgroundColor == originalBackground) {
48 testFailed('Background color for <input> element did not change when autofilled.');
51 if (computedStyleTextarea.color == originalForeground) {
52 testFailed('Foreground color for <textarea> element did not change when autofilled.');
55 if (computedStyleTextarea.backgroundColor == originalBackground) {
56 testFailed('Background color for <textarea> element did not change when autofilled.');
59 if (computedStyleSelect.color == originalForeground) {
60 testFailed('Foreground color for <select> element did not change when autofilled.');
63 if (computedStyleSelect.backgroundColor == originalBackground) {
64 testFailed('Background color for <select> element did not change when autofilled.');
68 if (window.internals) {
69 window.internals.setAutofilled(field, false);
70 window.internals.setAutofilled(textarea, false);
71 window.internals.setAutofilled(select, false);
74 // Colors should be restored.
75 computedStyleField = document.defaultView.getComputedStyle(field);
76 computedStyleTextarea = document.defaultView.getComputedStyle(textarea);
77 computedStyleSelect = document.defaultView.getComputedStyle(select);
78 if (computedStyleField.color != originalForeground) {
79 testFailed('Foreground color for <input> element did not revert when un-autofilled.');
82 if (computedStyleField.backgroundColor != originalBackground) {
83 testFailed('Background color for <input> element did not revert when un-autofilled.');
86 if (computedStyleTextarea.color != originalForeground) {
87 testFailed('Foreground color for <textarea> element did not revert when un-autofilled.');
90 if (computedStyleTextarea.backgroundColor != originalBackground) {
91 testFailed('Background color for <textarea> element did not revert when un-autofilled.');
94 if (computedStyleSelect.color != originalForeground) {
95 testFailed('Foreground color for <select> element did not revert when un-autofilled.');
98 if (computedStyleSelect.backgroundColor != originalBackground) {
99 testFailed('Background color for <select> element did not revert when un-autofilled.');
108 #field, #textarea, #select {
110 background-color: #FFFFFF;
114 <body onload="test()">
115 This tests that foreground and background colors properly change for autofilled inputs or select options. It can only be run using the test harness.<br>
117 <input type="text" id="field" value="Field value">
118 <textarea id="textarea"></textarea>
119 <select id="select"></select>
121 <div id="console"></div>