Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(848)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/css/pseudo-default-dynamic.html

Issue 1763553002: Invalidate :default pseudo classes when a default button is added or removed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <body>
rune 2016/03/03 09:11:03 <body> can be dropped.
tkent 2016/03/04 00:05:08 Done.
3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/testharnessreport.js"></script>
5 <div id="log"></div>
6 <div id="container"></div>
7 <style>
8 button, input { background: red; }
9 button:default, input:default { background: green; }
10 </style>
11 <script>
12 // TODO(tkent): This should be merged to web-platform-tests/html/semantics/selec tors/pseudo-classes/default.html.
13
14 var container = document.querySelector('#container');
15 const DEFAULT = 'rgb(0, 128, 0)';
16 const NOT_DEFAULT = 'rgb(255, 0, 0)';
rune 2016/03/03 09:11:03 Heh, I didn't know about the existence const in ja
17
18 function background(id) {
19 return document.defaultView.getComputedStyle(document.getElementById(id), nu ll).getPropertyValue('background-color');
20 }
21
22 test(function() {
23 container.innerHTML = '<form><input type=submit id=removed><input type=submi t id=second></form>';
24 assert_equals(background('removed'), DEFAULT);
25 assert_equals(background('second'), NOT_DEFAULT);
26 document.querySelector('#removed').type = 'text';
27 assert_equals(background('removed'), NOT_DEFAULT);
28 assert_equals(background('second'), DEFAULT);
29
30 container.innerHTML = '<form><button type=submit id=removed></button><input type=submit id=second></form>';
31 assert_equals(background('removed'), DEFAULT);
32 assert_equals(background('second'), NOT_DEFAULT);
33 document.querySelector('#removed').type = 'reset';
34 assert_equals(background('removed'), NOT_DEFAULT);
35 assert_equals(background('second'), DEFAULT);
36
37 container.innerHTML = '<form id=f1><input type=submit id=removed></form><inp ut type=submit id=second form=f1>';
38 assert_equals(background('removed'), DEFAULT);
39 assert_equals(background('second'), NOT_DEFAULT);
40 document.querySelector('#removed').type = 'reset';
41 assert_equals(background('removed'), NOT_DEFAULT);
42 assert_equals(background('second'), DEFAULT);
43 }, 'Removing the :default button by updating type attribute should update the de fault button.');
44
45 test(function() {
46 container.innerHTML = '<form><input type=submit id=removed><input type=submi t id=second></form>';
47 assert_equals(background('removed'), DEFAULT);
48 assert_equals(background('second'), NOT_DEFAULT);
49 document.querySelector('#removed').remove();
50 assert_equals(background('second'), DEFAULT);
51 }, 'Removing the :default button by detaching should update the default button.' );
52
53 test(function() {
54 container.innerHTML = '<input type=submit id=removed form=f1><form id=f1><in put type=submit id=second></form>';
55 assert_equals(background('removed'), DEFAULT);
56 assert_equals(background('second'), NOT_DEFAULT);
57 document.querySelector('#removed').removeAttribute('form');
58 assert_equals(background('removed'), NOT_DEFAULT);
59 assert_equals(background('second'), DEFAULT);
60 }, 'Removing the :default button by updating form content attribute should updat e the default button.');
61
62 test(function() {
63 container.innerHTML = '<form><input type=text id=added><input type=submit id =second></form>';
64 assert_equals(background('added'), NOT_DEFAULT);
65 assert_equals(background('second'), DEFAULT);
66 document.querySelector('#added').type = 'image';
67 assert_equals(background('added'), DEFAULT);
68 assert_equals(background('second'), NOT_DEFAULT);
69 }, 'Adding a button by updating type attribute should update the default button. ');
70
71 test(function() {
72 container.innerHTML = '<form><input type=submit id=second></form>';
73 assert_equals(background('second'), DEFAULT);
74 var button = document.createElement('button');
75 button.id = 'added'
76 document.querySelector('form').insertBefore(button, document.querySelector(' #second'));
77 assert_equals(background('added'), DEFAULT);
78 assert_equals(background('second'), NOT_DEFAULT);
79 }, 'Adding a button to a DOM tree should update the default button.');
80
81 test(function() {
82 container.innerHTML = '<input type=submit id=added><form id=f1><input type=s ubmit id=second></form>';
83 assert_equals(background('added'), NOT_DEFAULT);
84 assert_equals(background('second'), DEFAULT);
85 document.querySelector('#added').setAttribute('form', 'f1');
86 assert_equals(background('added'), DEFAULT, 'added button should be default. ');
87 assert_equals(background('second'), NOT_DEFAULT);
88 }, 'Adding a button by form content attribute should update the default button.' );
89
90 </script>
91 </body>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698