Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <head> | 1 <head> |
| 2 <script src="../../resources/js-test.js"></script> | 2 <script src="../../resources/js-test.js"></script> |
| 3 <script> | 3 <script src="resources/common.js"></script> |
| 4 function test() { | 4 <script> |
| 5 if (window.testRunner) { | |
| 6 testRunner.dumpAsText(); | |
| 7 } | |
| 8 | 5 |
| 9 if (!window.internals) { | 6 function backgroundOf(element) { |
| 10 testFailed('This test requires the test harness to run.'); | 7 return document.defaultView.getComputedStyle(element, null).getPropertyValue ('background-color'); |
| 11 return; | 8 } |
| 12 } | |
| 13 | 9 |
| 14 var field = document.getElementById('field'); | 10 function foregroundOf(element) { |
| 15 var textarea = document.getElementById('textarea'); | 11 return document.defaultView.getComputedStyle(element, null).getPropertyValue ('color'); |
| 16 var select = document.getElementById('select'); | 12 } |
| 17 | 13 |
| 18 var computedStyleField = document.defaultView.getComputedStyle(field); | 14 var originalForeground = 'rgb(255, 255, 255)'; |
| 19 var computedStyleTextarea = document.defaultView.getComputedStyle(textar ea); | 15 var originalBackground = 'rgb(255, 255, 255)'; |
| 20 var computedStyleSelect = document.defaultView.getComputedStyle(select); | |
| 21 var originalForeground = computedStyleField.color; | |
| 22 var originalBackground = computedStyleField.backgroundColor; | |
| 23 | 16 |
| 24 if (originalForeground != computedStyleTextarea.color) { | 17 function test() { |
| 25 testFailed('Unexpected initial foreground color for <textarea> field .'); | 18 if (!window.internals) { |
| 26 return; | 19 testFailed('This test requires the test harness to run.'); |
| 27 } | 20 return; |
| 28 if (originalForeground != computedStyleTextarea.backgroundColor) { | 21 } |
| 29 testFailed('Unexpected initial background color for <textarea> field .'); | |
| 30 return; | |
| 31 } | |
| 32 | 22 |
| 33 if (window.internals) { | 23 var field = document.getElementById('field'); |
| 34 window.internals.setAutofilled(field, true); | 24 var search = document.getElementById('search'); |
| 35 window.internals.setAutofilled(textarea, true); | 25 var textarea1 = document.getElementById('textarea1'); |
| 36 window.internals.setAutofilled(select, true); | 26 var textarea2 = document.getElementById('textarea2'); |
| 37 } | 27 textarea2.value = 'autofilled is true'; |
| 28 var select1 = document.getElementById('select1'); | |
| 29 var select2 = document.getElementById('select2'); | |
| 30 | |
| 31 shouldBe('foregroundOf(textarea1)', 'originalForeground'); | |
| 32 shouldBe('backgroundOf(textarea1)', 'originalBackground'); | |
| 38 | 33 |
| 39 // Both the foreground and background colors should change. | 34 window.internals.setAutofilled(field, true); |
| 40 computedStyleField = document.defaultView.getComputedStyle(field); | 35 window.internals.setAutofilled(search, true); |
| 41 computedStyleTextarea = document.defaultView.getComputedStyle(textarea); | 36 window.internals.setAutofilled(textarea1, true); |
| 42 computedStyleSelect = document.defaultView.getComputedStyle(select); | 37 window.internals.setAutofilled(textarea2, true); |
| 43 if (computedStyleField.color == originalForeground) { | 38 window.internals.setAutofilled(select1, true); |
| 44 testFailed('Foreground color for <input> element did not change when autofilled.'); | 39 window.internals.setAutofilled(select2, true); |
| 45 return; | |
| 46 } | |
| 47 if (computedStyleField.backgroundColor == originalBackground) { | |
| 48 testFailed('Background color for <input> element did not change when autofilled.'); | |
| 49 return; | |
| 50 } | |
| 51 if (computedStyleTextarea.color == originalForeground) { | |
| 52 testFailed('Foreground color for <textarea> element did not change w hen autofilled.'); | |
| 53 return; | |
| 54 } | |
| 55 if (computedStyleTextarea.backgroundColor == originalBackground) { | |
| 56 testFailed('Background color for <textarea> element did not change w hen autofilled.'); | |
| 57 return; | |
| 58 } | |
| 59 if (computedStyleSelect.color == originalForeground) { | |
| 60 testFailed('Foreground color for <select> element did not change whe n autofilled.'); | |
| 61 return; | |
| 62 } | |
| 63 if (computedStyleSelect.backgroundColor == originalBackground) { | |
| 64 testFailed('Background color for <select> element did not change whe n autofilled.'); | |
| 65 return; | |
| 66 } | |
| 67 | 40 |
| 68 if (window.internals) { | 41 shouldBeEqualToString('search.value', 'Search value'); |
| 69 window.internals.setAutofilled(field, false); | |
| 70 window.internals.setAutofilled(textarea, false); | |
| 71 window.internals.setAutofilled(select, false); | |
| 72 } | |
| 73 | 42 |
| 74 // Colors should be restored. | 43 // Both the foreground and background colors should change. |
| 75 computedStyleField = document.defaultView.getComputedStyle(field); | 44 shouldNotBe('foregroundOf(field)', 'originalForeground'); |
| 76 computedStyleTextarea = document.defaultView.getComputedStyle(textarea); | 45 shouldNotBe('backgroundOf(field)', 'originalBackground'); |
| 77 computedStyleSelect = document.defaultView.getComputedStyle(select); | 46 shouldNotBe('foregroundOf(search)', 'originalForeground'); |
| 78 if (computedStyleField.color != originalForeground) { | 47 shouldNotBe('backgroundOf(search)', 'originalBackground'); |
| 79 testFailed('Foreground color for <input> element did not revert when un-autofilled.'); | 48 shouldNotBe('foregroundOf(textarea1)', 'originalForeground'); |
| 80 return; | 49 shouldNotBe('backgroundOf(textarea1)', 'originalBackground'); |
| 81 } | 50 shouldNotBe('foregroundOf(textarea2)', 'originalForeground'); |
| 82 if (computedStyleField.backgroundColor != originalBackground) { | 51 shouldNotBe('backgroundOf(textarea2)', 'originalBackground'); |
| 83 testFailed('Background color for <input> element did not revert when un-autofilled.'); | 52 shouldNotBe('foregroundOf(select1)', 'originalForeground'); |
| 84 return; | 53 shouldNotBe('backgroundOf(select1)', 'originalBackground'); |
| 85 } | 54 shouldNotBe('foregroundOf(select2)', 'originalForeground'); |
| 86 if (computedStyleTextarea.color != originalForeground) { | 55 shouldNotBe('backgroundOf(select2)', 'originalBackground'); |
| 87 testFailed('Foreground color for <textarea> element did not revert w hen un-autofilled.'); | |
| 88 return; | |
| 89 } | |
| 90 if (computedStyleTextarea.backgroundColor != originalBackground) { | |
| 91 testFailed('Background color for <textarea> element did not revert w hen un-autofilled.'); | |
| 92 return; | |
| 93 } | |
| 94 if (computedStyleSelect.color != originalForeground) { | |
| 95 testFailed('Foreground color for <select> element did not revert whe n un-autofilled.'); | |
| 96 return; | |
| 97 } | |
| 98 if (computedStyleSelect.backgroundColor != originalBackground) { | |
| 99 testFailed('Background color for <select> element did not revert whe n un-autofilled.'); | |
| 100 return; | |
| 101 } | |
| 102 | 56 |
| 103 testPassed(''); | 57 // Remove an unselected option from <select> element. This should not affect the background color for the autofilled <select> element. |
| 58 computedStyleSelect2 = document.defaultView.getComputedStyle(select2); | |
| 59 if (select2.options.length != 3) | |
|
tkent
2014/08/15 14:20:39
Use shouldBe().
Because shouldBe can not access lo
| |
| 60 log('Incorrect options length: ' + select2.options.length); | |
| 61 select2.removeChild(select2.childNodes[1]); | |
| 62 if (select2.options.length != 2) | |
|
tkent
2014/08/15 14:20:38
Use shouldBe()
| |
| 63 log('Incorrect options length: ' + select2.options.length); | |
| 64 var autofilledSelectForeground = computedStyleSelect2.color; | |
| 65 var autofilledSelectBackground = computedStyleSelect2.backgroundColor; | |
| 66 computedStyleSelect2 = document.defaultView.getComputedStyle(select2); | |
| 67 if (computedStyleSelect2.color !== autofilledSelectForeground) { | |
|
tkent
2014/08/15 14:20:38
Use shouldBe().
| |
| 68 testFailed('Foreground color for <select> element changed after removing unselected option(s).'); | |
| 69 return; | |
| 104 } | 70 } |
| 105 </script> | 71 if (computedStyleSelect2.backgroundColor !== autofilledSelectBackground) { |
|
tkent
2014/08/15 14:20:38
Use shouldBe().
| |
| 72 testFailed('Background color for <select> element changed after removing unselected option(s).'); | |
| 73 return; | |
| 74 } | |
| 106 | 75 |
| 107 <style> | 76 window.internals.setAutofilled(field, false); |
| 108 #field, #textarea, #select { | 77 window.internals.setAutofilled(textarea1, false); |
| 109 color: #FFFFFF; | 78 window.internals.setAutofilled(select1, false); |
| 110 background-color: #FFFFFF; | 79 |
| 111 } | 80 // Cancel search by pressing cancel button |
| 112 </style> | 81 var cancelPos = searchCancelButtonPosition(search); |
| 82 eventSender.mouseMoveTo(cancelPos.x, cancelPos.y); | |
| 83 eventSender.mouseDown(); | |
| 84 eventSender.mouseUp(); | |
| 85 shouldBeEmptyString('search.value'); | |
| 86 | |
| 87 // Edit text in the autofilled textarea. | |
| 88 textarea2.focus(); | |
| 89 document.execCommand('Delete', false, null); | |
| 90 document.execCommand('Delete', false, null); | |
| 91 document.execCommand('Delete', false, null); | |
| 92 document.execCommand('Delete', false, null); | |
| 93 document.execCommand('InsertText', false, 'false'); | |
| 94 | |
| 95 // Remove selected option for select2 element | |
| 96 select2.removeChild(select2.firstChild); | |
| 97 | |
| 98 // Colors should be restored. | |
| 99 shouldBe('foregroundOf(field)', 'originalForeground'); | |
| 100 shouldBe('backgroundOf(field)', 'originalBackground'); | |
| 101 shouldBe('foregroundOf(search)', 'originalForeground'); | |
| 102 shouldBe('backgroundOf(search)', 'originalBackground'); | |
| 103 shouldBe('foregroundOf(textarea1)', 'originalForeground'); | |
| 104 shouldBe('backgroundOf(textarea1)', 'originalBackground'); | |
| 105 shouldBe('foregroundOf(textarea2)', 'originalForeground'); | |
| 106 shouldBe('backgroundOf(textarea2)', 'originalBackground'); | |
| 107 shouldBe('foregroundOf(select1)', 'originalForeground'); | |
| 108 shouldBe('backgroundOf(select1)', 'originalBackground'); | |
| 109 shouldBe('foregroundOf(select2)', 'originalForeground'); | |
| 110 shouldBe('backgroundOf(select2)', 'originalBackground'); | |
| 111 | |
| 112 testPassed(''); | |
|
tkent
2014/08/15 14:20:38
This line is unnecessary.
| |
| 113 } | |
| 114 </script> | |
| 115 | |
| 116 <style> | |
| 117 #field, #search, #textarea1, #textarea2, #select1, #select2 { | |
| 118 color: #FFFFFF; | |
| 119 background-color: #FFFFFF; | |
| 120 } | |
| 121 </style> | |
| 113 </head> | 122 </head> |
| 114 <body onload="test()"> | 123 <body onload="test()"> |
| 115 This tests that foreground and background colors properly change for autofil led inputs or select options. It can only be run using the test harness.<br> | 124 This tests that foreground and background colors properly change for autofil led inputs or select options. It can only be run using the test harness.<br> |
| 116 <form name="fm"> | 125 <form name="fm"> |
| 117 <input type="text" id="field" value="Field value"> | 126 <input type="text" id="field" value="Field value"> |
| 118 <textarea id="textarea"></textarea> | 127 <input type="search" id="search" value="Search value"> |
| 119 <select id="select"></select> | 128 <textarea id="textarea1"></textarea> |
| 129 <textarea id="textarea2"></textarea> | |
| 130 <select id="select1"></select> | |
| 131 <select id="select2"> | |
| 132 <option selected>1</option> | |
| 133 <option >2</option> | |
| 134 <option>3</option> | |
| 135 </select> | |
| 120 </form> | 136 </form> |
| 121 <div id="console"></div> | 137 <div id="console"></div> |
| 122 </body> | 138 </body> |
| OLD | NEW |