OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../../resources/testharness.js"></script> |
| 3 <script src="../../resources/testharnessreport.js"></script> |
| 4 <div id="log"></div> |
| 5 <div id="container"></div> |
| 6 <style> |
| 7 button, input { background: red; } |
| 8 button:default, input:default { background: green; } |
| 9 </style> |
| 10 <script> |
| 11 // TODO(tkent): This should be merged to web-platform-tests/html/semantics/selec
tors/pseudo-classes/default.html. |
| 12 |
| 13 var container = document.querySelector('#container'); |
| 14 const DEFAULT = 'rgb(0, 128, 0)'; |
| 15 const NOT_DEFAULT = 'rgb(255, 0, 0)'; |
| 16 |
| 17 function background(id) { |
| 18 return document.defaultView.getComputedStyle(document.getElementById(id), nu
ll).getPropertyValue('background-color'); |
| 19 } |
| 20 |
| 21 test(function() { |
| 22 container.innerHTML = '<form><input type=submit id=removed><object></object>
<input type=submit id=second></form>'; |
| 23 assert_equals(background('removed'), DEFAULT); |
| 24 assert_equals(background('second'), NOT_DEFAULT); |
| 25 document.querySelector('#removed').type = 'text'; |
| 26 assert_equals(background('removed'), NOT_DEFAULT); |
| 27 assert_equals(background('second'), DEFAULT); |
| 28 |
| 29 container.innerHTML = '<form><button type=submit id=removed></button><input
type=submit id=second></form>'; |
| 30 assert_equals(background('removed'), DEFAULT); |
| 31 assert_equals(background('second'), NOT_DEFAULT); |
| 32 document.querySelector('#removed').type = 'reset'; |
| 33 assert_equals(background('removed'), NOT_DEFAULT); |
| 34 assert_equals(background('second'), DEFAULT); |
| 35 |
| 36 container.innerHTML = '<form id=f1><input type=submit id=removed></form><inp
ut type=submit id=second form=f1>'; |
| 37 assert_equals(background('removed'), DEFAULT); |
| 38 assert_equals(background('second'), NOT_DEFAULT); |
| 39 document.querySelector('#removed').type = 'reset'; |
| 40 assert_equals(background('removed'), NOT_DEFAULT); |
| 41 assert_equals(background('second'), DEFAULT); |
| 42 }, 'Removing the :default button by updating type attribute should update the de
fault button.'); |
| 43 |
| 44 test(function() { |
| 45 container.innerHTML = '<form><input type=submit id=removed><input type=submi
t id=second></form>'; |
| 46 assert_equals(background('removed'), DEFAULT); |
| 47 assert_equals(background('second'), NOT_DEFAULT); |
| 48 document.querySelector('#removed').remove(); |
| 49 assert_equals(background('second'), DEFAULT); |
| 50 }, 'Removing the :default button by detaching should update the default button.'
); |
| 51 |
| 52 test(function() { |
| 53 container.innerHTML = '<input type=submit id=removed form=f1><form id=f1><in
put type=submit id=second></form>'; |
| 54 assert_equals(background('removed'), DEFAULT); |
| 55 assert_equals(background('second'), NOT_DEFAULT); |
| 56 document.querySelector('#removed').removeAttribute('form'); |
| 57 assert_equals(background('removed'), NOT_DEFAULT); |
| 58 assert_equals(background('second'), DEFAULT); |
| 59 }, 'Removing the :default button by updating form content attribute should updat
e the default button.'); |
| 60 |
| 61 test(function() { |
| 62 container.innerHTML = '<form><input type=text id=added><input type=submit id
=second></form>'; |
| 63 assert_equals(background('added'), NOT_DEFAULT); |
| 64 assert_equals(background('second'), DEFAULT); |
| 65 document.querySelector('#added').type = 'image'; |
| 66 assert_equals(background('added'), DEFAULT); |
| 67 assert_equals(background('second'), NOT_DEFAULT); |
| 68 }, 'Adding a button by updating type attribute should update the default button.
'); |
| 69 |
| 70 test(function() { |
| 71 container.innerHTML = '<form><input type=submit id=second></form>'; |
| 72 assert_equals(background('second'), DEFAULT); |
| 73 var button = document.createElement('button'); |
| 74 button.id = 'added' |
| 75 document.querySelector('form').insertBefore(button, document.querySelector('
#second')); |
| 76 assert_equals(background('added'), DEFAULT); |
| 77 assert_equals(background('second'), NOT_DEFAULT); |
| 78 }, 'Adding a button to a DOM tree should update the default button.'); |
| 79 |
| 80 test(function() { |
| 81 container.innerHTML = '<input type=submit id=added><form id=f1><input type=s
ubmit id=second></form>'; |
| 82 assert_equals(background('added'), NOT_DEFAULT); |
| 83 assert_equals(background('second'), DEFAULT); |
| 84 document.querySelector('#added').setAttribute('form', 'f1'); |
| 85 assert_equals(background('added'), DEFAULT, 'added button should be default.
'); |
| 86 assert_equals(background('second'), NOT_DEFAULT); |
| 87 }, 'Adding a button by form content attribute should update the default button.'
); |
| 88 |
| 89 </script> |
OLD | NEW |