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..a916127af31c0112bf4c4dd2cd7ce439bb2bb2cb 100644 |
--- a/LayoutTests/fast/forms/input-autofilled.html |
+++ b/LayoutTests/fast/forms/input-autofilled.html |
@@ -1,122 +1,226 @@ |
<head> |
tkent
2014/08/14 23:10:26
We should remove |input| from the file name becaus
ziran.sun
2014/08/15 13:58:28
I'll do this in another CL once this patch is land
|
- <script src="../../resources/js-test.js"></script> |
- <script> |
- function test() { |
- if (window.testRunner) { |
- testRunner.dumpAsText(); |
- } |
+<script src="../../resources/js-test.js"></script> |
+<script> |
+function test() { |
+ if (!window.internals) { |
+ testFailed('This test requires the test harness to run.'); |
+ return; |
+ } |
+ |
+ 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'); |
- if (!window.internals) { |
- testFailed('This test requires the test harness to run.'); |
- return; |
- } |
+ var computedStyleField = document.defaultView.getComputedStyle(field); |
+ var computedStyleSearch = document.defaultView.getComputedStyle(search); |
+ var computedStyleTextarea1 = document.defaultView.getComputedStyle(textarea1); |
+ var computedStyleTextarea2 = document.defaultView.getComputedStyle(textarea2); |
+ var computedStyleSelect1 = document.defaultView.getComputedStyle(select1); |
+ var computedStyleSelect2 = document.defaultView.getComputedStyle(select2); |
+ var originalForeground = computedStyleField.color; |
+ var originalBackground = computedStyleField.backgroundColor; |
- var field = document.getElementById('field'); |
- var textarea = document.getElementById('textarea'); |
- var select = document.getElementById('select'); |
+ if (originalForeground != computedStyleTextarea1.color) { |
+ testFailed('Unexpected initial foreground color for <textarea> field.'); |
+ return; |
+ } |
+ if (originalBackground != computedStyleTextarea1.backgroundColor) { |
+ testFailed('Unexpected initial background color for <textarea> field.'); |
+ return; |
+ } |
- 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 (window.internals) { |
tkent
2014/08/14 23:10:25
This check is unnecessary. We already have it in
|
+ 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); |
+ } |
- 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; |
- } |
+ shouldBe('search.value', '"Search value"'); |
tkent
2014/08/14 23:10:25
shouldBeEqualToString('search.value', 'Search valu
|
- 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); |
+ computedStyleSearch = document.defaultView.getComputedStyle(search); |
tkent
2014/08/14 23:10:25
inconsistent indentation.
|
+ computedStyleTextarea1 = document.defaultView.getComputedStyle(textarea1); |
+ computedStyleTextarea2 = document.defaultView.getComputedStyle(textarea2); |
+ computedStyleSelect1 = document.defaultView.getComputedStyle(select1); |
+ computedStyleSelect2 = document.defaultView.getComputedStyle(select2); |
+ if (computedStyleField.color == originalForeground) { |
tkent
2014/08/14 23:10:25
Why don't you use shouldBe()?
|
+ testFailed('Foreground color for <input> text element did not change when autofilled.'); |
+ return; |
+ } |
+ if (computedStyleField.backgroundColor == originalBackground) { |
+ testFailed('Background color for <input> text element did not change when autofilled.'); |
+ return; |
+ } |
+ if (computedStyleSearch.color == originalForeground) { |
+ testFailed('Foreground color for <input> serach element did not change when autofilled.'); |
+ return; |
+ } |
+ if (computedStyleSearch.backgroundColor == originalBackground) { |
+ testFailed('Background color for <input> search element did not change when autofilled.'); |
+ return; |
+ } |
+ if (computedStyleTextarea1.color == originalForeground) { |
+ testFailed('Foreground color for <textarea> element did not change when autofilled.'); |
+ return; |
+ } |
+ if (computedStyleTextarea1.backgroundColor == originalBackground) { |
+ testFailed('Background color for <textarea> element did not change when autofilled.'); |
+ return; |
+ } |
+ if (computedStyleTextarea2.color == originalForeground) { |
+ testFailed('Foreground color for <textarea> element did not change when autofilled.'); |
+ return; |
+ } |
+ if (computedStyleTextarea2.backgroundColor == originalBackground) { |
+ testFailed('Background color for <textarea> element did not change when autofilled.'); |
+ return; |
+ } |
+ if (computedStyleSelect1.color == originalForeground) { |
+ testFailed('Foreground color for <select> element did not change when autofilled.'); |
+ return; |
+ } |
+ if (computedStyleSelect1.backgroundColor == originalBackground) { |
+ testFailed('Background color for <select> element did not change when autofilled.'); |
+ return; |
+ } |
+ if (computedStyleSelect2.color == originalForeground) { |
+ testFailed('Foreground color for <select> element did not change when autofilled.'); |
+ return; |
+ } |
+ if (computedStyleSelect2.backgroundColor == originalBackground) { |
+ testFailed('Background color for <select> element did not change when autofilled.'); |
+ return; |
+ } |
+ |
+ // Remove an unselected option from <select> element. This should not affect the background color for the autofilled <select> element. |
+ if (select2.options.length != 3) |
+ log("Incorrect options length: " + select2.options.length); |
tkent
2014/08/14 23:10:25
Inconsistent quote marks. This line uses double-q
|
+ select2.removeChild(select2.childNodes[1]); |
+ if (select2.options.length != 2) |
+ log("Incorrect options length: " + select2.options.length); |
+ var autofilledSelectForeground = computedStyleSelect2.color; |
+ var autofilledSelectBackground = computedStyleSelect2.backgroundColor; |
+ computedStyleSelect2 = document.defaultView.getComputedStyle(select2); |
+ if (computedStyleSelect2.color !== autofilledSelectForeground) { |
+ testFailed('Foreground color for <select> element changed after removing unselected option(s).'); |
+ return; |
+ } |
+ if (computedStyleSelect2.backgroundColor !== autofilledSelectBackground) { |
+ testFailed('Background color for <select> element changed after removing unselected option(s).'); |
+ return; |
+ } |
- // 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) { |
tkent
2014/08/14 23:10:25
This check is unnecessary.
|
+ window.internals.setAutofilled(field, false); |
+ window.internals.setAutofilled(textarea1, false); |
+ window.internals.setAutofilled(select1, false); |
+ } |
- if (window.internals) { |
- window.internals.setAutofilled(field, false); |
- window.internals.setAutofilled(textarea, false); |
- window.internals.setAutofilled(select, false); |
- } |
+ // Cancel search by pressing cancel button |
+ eventSender.mouseMoveTo(search.offsetLeft + search.offsetWidth - 8, search.offsetTop + search.offsetHeight / 2); |
tkent
2014/08/14 23:10:25
Please use searchCancelButtonPosition() defined in
|
+ eventSender.mouseDown(); |
+ eventSender.mouseUp(); |
+ shouldBe('search.value', '""'); |
tkent
2014/08/14 23:10:25
shouldBeEqualToString
|
- // 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; |
- } |
+ // 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); |
- testPassed(''); |
+ // Colors should be restored. |
+ computedStyleField = document.defaultView.getComputedStyle(field); |
+ computedStyleSearch = document.defaultView.getComputedStyle(search); |
+ computedStyleTextarea1 = document.defaultView.getComputedStyle(textarea1); |
+ computedStyleTextarea2 = document.defaultView.getComputedStyle(textarea2); |
+ computedStyleSelect1 = document.defaultView.getComputedStyle(select1); |
+ computedStyleSelect2 = document.defaultView.getComputedStyle(select2); |
tkent
2014/08/14 23:10:26
inconsistent indentation
|
+ if (computedStyleField.color !== originalForeground) { |
tkent
2014/08/14 23:10:26
Why don't you use shouldBe()?
|
+ testFailed('Foreground color for <input> element did not revert when un-autofilled.'); |
+ return; |
+ } |
+ if (computedStyleField.backgroundColor !== originalBackground) { |
+ testFailed('Background color for <input> text element did not revert when un-autofilled.'); |
+ return; |
+ } |
+ if (computedStyleSearch.color !== originalForeground) { |
+ testFailed('Foreground color for <input> search element did not revert when search is cancelled'); |
+ return; |
+ } |
+ if (computedStyleSearch.backgroundColor !== originalBackground) { |
+ testFailed('Background color for <input> search element did not revert when search is cancelled'); |
+ return; |
+ } |
+ if (computedStyleTextarea1.color !== originalForeground) { |
+ testFailed('Foreground color for <textarea> element did not revert when un-autofilled.'); |
+ return; |
} |
- </script> |
+ if (computedStyleTextarea1.backgroundColor !== originalBackground) { |
+ testFailed('Background color for <textarea> element did not revert when un-autofilled.'); |
+ return; |
+ } |
+ if (computedStyleTextarea2.color !== originalForeground) { |
+ testFailed('Foreground color for <textarea> element did not revert when editing autofilled text.'); |
+ return; |
+ } |
+ if (computedStyleTextarea2.backgroundColor !== originalBackground) { |
+ testFailed('Background color for <textarea> element did not revert when editing autofilled text.'); |
+ return; |
+ } |
+ if (computedStyleSelect1.color != originalForeground) { |
+ testFailed('Foreground color for <select> element did not revert when un-autofilled.'); |
+ return; |
+ } |
+ if (computedStyleSelect1.backgroundColor != originalBackground) { |
+ testFailed('Background color for <select> element did not revert when un-autofilled.'); |
+ return; |
+ } |
+ if (computedStyleSelect2.color != originalForeground) { |
+ testFailed('Foreground color for <select> element did not revert when autofilled option is removed'); |
+ return; |
+ } |
+ if (computedStyleSelect2.backgroundColor != originalBackground) { |
+ testFailed('Background color for <select> element did not revert when autofilled option is removed'); |
+ return; |
+ } |
+ |
+ testPassed(''); |
+} |
+</script> |
- <style> |
- #field, #textarea, #select { |
- color: #FFFFFF; |
- background-color: #FFFFFF; |
+<style> |
+ #field, #search, #textarea1, #textarea2, #select1, #select2 { |
tkent
2014/08/14 23:10:25
Indentation is unnecessary.
|
+ color: #FFFFFF; |
+ background-color: #FFFFFF; |
} |
- </style> |
+</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> |