Chromium Code Reviews| Index: LayoutTests/fast/forms/input-autofilled.html |
| diff --git a/LayoutTests/fast/forms/input-autofilled.html b/LayoutTests/fast/forms/input-autofilled.html |
| index b0543e23a7ffd8116b7b8338def20d93f33a777b..6c457b2e8ea46dbd15a3570ff3dfc668417fbe4d 100644 |
| --- a/LayoutTests/fast/forms/input-autofilled.html |
| +++ b/LayoutTests/fast/forms/input-autofilled.html |
| @@ -1,122 +1,138 @@ |
| <head> |
| - <script src="../../resources/js-test.js"></script> |
| - <script> |
| - function test() { |
| - if (window.testRunner) { |
| - testRunner.dumpAsText(); |
| - } |
| - |
| - if (!window.internals) { |
| - testFailed('This test requires the test harness to run.'); |
| - return; |
| - } |
| - |
| - var field = document.getElementById('field'); |
| - var textarea = document.getElementById('textarea'); |
| - var select = document.getElementById('select'); |
| - |
| - var computedStyleField = document.defaultView.getComputedStyle(field); |
| - var computedStyleTextarea = document.defaultView.getComputedStyle(textarea); |
| - var computedStyleSelect = document.defaultView.getComputedStyle(select); |
| - var originalForeground = computedStyleField.color; |
| - var originalBackground = computedStyleField.backgroundColor; |
| - |
| - if (originalForeground != computedStyleTextarea.color) { |
| - testFailed('Unexpected initial foreground color for <textarea> field.'); |
| - return; |
| - } |
| - if (originalForeground != computedStyleTextarea.backgroundColor) { |
| - testFailed('Unexpected initial background color for <textarea> field.'); |
| - return; |
| - } |
| - |
| - if (window.internals) { |
| - window.internals.setAutofilled(field, true); |
| - window.internals.setAutofilled(textarea, true); |
| - window.internals.setAutofilled(select, true); |
| - } |
| - |
| - // Both the foreground and background colors should change. |
| - computedStyleField = document.defaultView.getComputedStyle(field); |
| - computedStyleTextarea = document.defaultView.getComputedStyle(textarea); |
| - computedStyleSelect = document.defaultView.getComputedStyle(select); |
| - if (computedStyleField.color == originalForeground) { |
| - testFailed('Foreground color for <input> element did not change when autofilled.'); |
| - return; |
| - } |
| - if (computedStyleField.backgroundColor == originalBackground) { |
| - testFailed('Background color for <input> element did not change when autofilled.'); |
| - return; |
| - } |
| - if (computedStyleTextarea.color == originalForeground) { |
| - testFailed('Foreground color for <textarea> element did not change when autofilled.'); |
| - return; |
| - } |
| - if (computedStyleTextarea.backgroundColor == originalBackground) { |
| - testFailed('Background color for <textarea> element did not change when autofilled.'); |
| - return; |
| - } |
| - if (computedStyleSelect.color == originalForeground) { |
| - testFailed('Foreground color for <select> element did not change when autofilled.'); |
| - return; |
| - } |
| - if (computedStyleSelect.backgroundColor == originalBackground) { |
| - testFailed('Background color for <select> element did not change when autofilled.'); |
| - return; |
| - } |
| - |
| - if (window.internals) { |
| - window.internals.setAutofilled(field, false); |
| - window.internals.setAutofilled(textarea, false); |
| - window.internals.setAutofilled(select, false); |
| - } |
| - |
| - // Colors should be restored. |
| - computedStyleField = document.defaultView.getComputedStyle(field); |
| - computedStyleTextarea = document.defaultView.getComputedStyle(textarea); |
| - computedStyleSelect = document.defaultView.getComputedStyle(select); |
| - if (computedStyleField.color != originalForeground) { |
| - testFailed('Foreground color for <input> element did not revert when un-autofilled.'); |
| - return; |
| - } |
| - if (computedStyleField.backgroundColor != originalBackground) { |
| - testFailed('Background color for <input> element did not revert when un-autofilled.'); |
| - return; |
| - } |
| - if (computedStyleTextarea.color != originalForeground) { |
| - testFailed('Foreground color for <textarea> element did not revert when un-autofilled.'); |
| - return; |
| - } |
| - if (computedStyleTextarea.backgroundColor != originalBackground) { |
| - testFailed('Background color for <textarea> element did not revert when un-autofilled.'); |
| - return; |
| - } |
| - if (computedStyleSelect.color != originalForeground) { |
| - testFailed('Foreground color for <select> element did not revert when un-autofilled.'); |
| - return; |
| - } |
| - if (computedStyleSelect.backgroundColor != originalBackground) { |
| - testFailed('Background color for <select> element did not revert when un-autofilled.'); |
| - return; |
| - } |
| - |
| - testPassed(''); |
| +<script src="../../resources/js-test.js"></script> |
| +<script src="resources/common.js"></script> |
| +<script> |
| + |
| +function backgroundOf(element) { |
| + return document.defaultView.getComputedStyle(element, null).getPropertyValue('background-color'); |
| +} |
| + |
| +function foregroundOf(element) { |
| + return document.defaultView.getComputedStyle(element, null).getPropertyValue('color'); |
| +} |
| + |
| +var originalForeground = 'rgb(255, 255, 255)'; |
| +var originalBackground = 'rgb(255, 255, 255)'; |
| + |
| +function test() { |
| + if (!window.internals) { |
| + testFailed('This test requires the test harness to run.'); |
| + return; |
| } |
| - </script> |
| - <style> |
| - #field, #textarea, #select { |
| - color: #FFFFFF; |
| - background-color: #FFFFFF; |
| + var field = document.getElementById('field'); |
| + var search = document.getElementById('search'); |
| + var textarea1 = document.getElementById('textarea1'); |
| + var textarea2 = document.getElementById('textarea2'); |
| + textarea2.value = 'autofilled is true'; |
| + var select1 = document.getElementById('select1'); |
| + var select2 = document.getElementById('select2'); |
| + |
| + shouldBe('foregroundOf(textarea1)', 'originalForeground'); |
| + shouldBe('backgroundOf(textarea1)', 'originalBackground'); |
| + |
| + window.internals.setAutofilled(field, true); |
| + window.internals.setAutofilled(search, true); |
| + window.internals.setAutofilled(textarea1, true); |
| + window.internals.setAutofilled(textarea2, true); |
| + window.internals.setAutofilled(select1, true); |
| + window.internals.setAutofilled(select2, true); |
| + |
| + shouldBeEqualToString('search.value', 'Search value'); |
| + |
| + // Both the foreground and background colors should change. |
| + shouldNotBe('foregroundOf(field)', 'originalForeground'); |
| + shouldNotBe('backgroundOf(field)', 'originalBackground'); |
| + shouldNotBe('foregroundOf(search)', 'originalForeground'); |
| + shouldNotBe('backgroundOf(search)', 'originalBackground'); |
| + shouldNotBe('foregroundOf(textarea1)', 'originalForeground'); |
| + shouldNotBe('backgroundOf(textarea1)', 'originalBackground'); |
| + shouldNotBe('foregroundOf(textarea2)', 'originalForeground'); |
| + shouldNotBe('backgroundOf(textarea2)', 'originalBackground'); |
| + shouldNotBe('foregroundOf(select1)', 'originalForeground'); |
| + shouldNotBe('backgroundOf(select1)', 'originalBackground'); |
| + shouldNotBe('foregroundOf(select2)', 'originalForeground'); |
| + shouldNotBe('backgroundOf(select2)', 'originalBackground'); |
| + |
| + // Remove an unselected option from <select> element. This should not affect the background color for the autofilled <select> element. |
| + computedStyleSelect2 = document.defaultView.getComputedStyle(select2); |
| + if (select2.options.length != 3) |
|
tkent
2014/08/15 14:20:39
Use shouldBe().
Because shouldBe can not access lo
|
| + log('Incorrect options length: ' + select2.options.length); |
| + select2.removeChild(select2.childNodes[1]); |
| + if (select2.options.length != 2) |
|
tkent
2014/08/15 14:20:38
Use shouldBe()
|
| + log('Incorrect options length: ' + select2.options.length); |
| + var autofilledSelectForeground = computedStyleSelect2.color; |
| + var autofilledSelectBackground = computedStyleSelect2.backgroundColor; |
| + computedStyleSelect2 = document.defaultView.getComputedStyle(select2); |
| + if (computedStyleSelect2.color !== autofilledSelectForeground) { |
|
tkent
2014/08/15 14:20:38
Use shouldBe().
|
| + testFailed('Foreground color for <select> element changed after removing unselected option(s).'); |
| + return; |
| } |
| - </style> |
| + if (computedStyleSelect2.backgroundColor !== autofilledSelectBackground) { |
|
tkent
2014/08/15 14:20:38
Use shouldBe().
|
| + testFailed('Background color for <select> element changed after removing unselected option(s).'); |
| + return; |
| + } |
| + |
| + window.internals.setAutofilled(field, false); |
| + window.internals.setAutofilled(textarea1, false); |
| + window.internals.setAutofilled(select1, false); |
| + |
| + // Cancel search by pressing cancel button |
| + var cancelPos = searchCancelButtonPosition(search); |
| + eventSender.mouseMoveTo(cancelPos.x, cancelPos.y); |
| + eventSender.mouseDown(); |
| + eventSender.mouseUp(); |
| + shouldBeEmptyString('search.value'); |
| + |
| + // Edit text in the autofilled textarea. |
| + textarea2.focus(); |
| + document.execCommand('Delete', false, null); |
| + document.execCommand('Delete', false, null); |
| + document.execCommand('Delete', false, null); |
| + document.execCommand('Delete', false, null); |
| + document.execCommand('InsertText', false, 'false'); |
| + |
| + // Remove selected option for select2 element |
| + select2.removeChild(select2.firstChild); |
| + |
| + // Colors should be restored. |
| + shouldBe('foregroundOf(field)', 'originalForeground'); |
| + shouldBe('backgroundOf(field)', 'originalBackground'); |
| + shouldBe('foregroundOf(search)', 'originalForeground'); |
| + shouldBe('backgroundOf(search)', 'originalBackground'); |
| + shouldBe('foregroundOf(textarea1)', 'originalForeground'); |
| + shouldBe('backgroundOf(textarea1)', 'originalBackground'); |
| + shouldBe('foregroundOf(textarea2)', 'originalForeground'); |
| + shouldBe('backgroundOf(textarea2)', 'originalBackground'); |
| + shouldBe('foregroundOf(select1)', 'originalForeground'); |
| + shouldBe('backgroundOf(select1)', 'originalBackground'); |
| + shouldBe('foregroundOf(select2)', 'originalForeground'); |
| + shouldBe('backgroundOf(select2)', 'originalBackground'); |
| + |
| + testPassed(''); |
|
tkent
2014/08/15 14:20:38
This line is unnecessary.
|
| +} |
| +</script> |
| + |
| +<style> |
| +#field, #search, #textarea1, #textarea2, #select1, #select2 { |
| + color: #FFFFFF; |
| + background-color: #FFFFFF; |
| +} |
| +</style> |
| </head> |
| <body onload="test()"> |
| 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> |
| <form name="fm"> |
| <input type="text" id="field" value="Field value"> |
| - <textarea id="textarea"></textarea> |
| - <select id="select"></select> |
| + <input type="search" id="search" value="Search value"> |
| + <textarea id="textarea1"></textarea> |
| + <textarea id="textarea2"></textarea> |
| + <select id="select1"></select> |
| + <select id="select2"> |
| + <option selected>1</option> |
| + <option >2</option> |
| + <option>3</option> |
| + </select> |
| </form> |
| <div id="console"></div> |
| -</body> |
| +</body> |