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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/fast/css/pseudo-default-dynamic.html
diff --git a/third_party/WebKit/LayoutTests/fast/css/pseudo-default-dynamic.html b/third_party/WebKit/LayoutTests/fast/css/pseudo-default-dynamic.html
new file mode 100644
index 0000000000000000000000000000000000000000..8acd27fb09c4aba6e0ea23ee2c64f6e97d01d272
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/css/pseudo-default-dynamic.html
@@ -0,0 +1,91 @@
+<!DOCTYPE html>
+<body>
rune 2016/03/03 09:11:03 <body> can be dropped.
tkent 2016/03/04 00:05:08 Done.
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<div id="log"></div>
+<div id="container"></div>
+<style>
+button, input { background: red; }
+button:default, input:default { background: green; }
+</style>
+<script>
+// TODO(tkent): This should be merged to web-platform-tests/html/semantics/selectors/pseudo-classes/default.html.
+
+var container = document.querySelector('#container');
+const DEFAULT = 'rgb(0, 128, 0)';
+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
+
+function background(id) {
+ return document.defaultView.getComputedStyle(document.getElementById(id), null).getPropertyValue('background-color');
+}
+
+test(function() {
+ container.innerHTML = '<form><input type=submit id=removed><input type=submit id=second></form>';
+ assert_equals(background('removed'), DEFAULT);
+ assert_equals(background('second'), NOT_DEFAULT);
+ document.querySelector('#removed').type = 'text';
+ assert_equals(background('removed'), NOT_DEFAULT);
+ assert_equals(background('second'), DEFAULT);
+
+ container.innerHTML = '<form><button type=submit id=removed></button><input type=submit id=second></form>';
+ assert_equals(background('removed'), DEFAULT);
+ assert_equals(background('second'), NOT_DEFAULT);
+ document.querySelector('#removed').type = 'reset';
+ assert_equals(background('removed'), NOT_DEFAULT);
+ assert_equals(background('second'), DEFAULT);
+
+ container.innerHTML = '<form id=f1><input type=submit id=removed></form><input type=submit id=second form=f1>';
+ assert_equals(background('removed'), DEFAULT);
+ assert_equals(background('second'), NOT_DEFAULT);
+ document.querySelector('#removed').type = 'reset';
+ assert_equals(background('removed'), NOT_DEFAULT);
+ assert_equals(background('second'), DEFAULT);
+}, 'Removing the :default button by updating type attribute should update the default button.');
+
+test(function() {
+ container.innerHTML = '<form><input type=submit id=removed><input type=submit id=second></form>';
+ assert_equals(background('removed'), DEFAULT);
+ assert_equals(background('second'), NOT_DEFAULT);
+ document.querySelector('#removed').remove();
+ assert_equals(background('second'), DEFAULT);
+}, 'Removing the :default button by detaching should update the default button.');
+
+test(function() {
+ container.innerHTML = '<input type=submit id=removed form=f1><form id=f1><input type=submit id=second></form>';
+ assert_equals(background('removed'), DEFAULT);
+ assert_equals(background('second'), NOT_DEFAULT);
+ document.querySelector('#removed').removeAttribute('form');
+ assert_equals(background('removed'), NOT_DEFAULT);
+ assert_equals(background('second'), DEFAULT);
+}, 'Removing the :default button by updating form content attribute should update the default button.');
+
+test(function() {
+ container.innerHTML = '<form><input type=text id=added><input type=submit id=second></form>';
+ assert_equals(background('added'), NOT_DEFAULT);
+ assert_equals(background('second'), DEFAULT);
+ document.querySelector('#added').type = 'image';
+ assert_equals(background('added'), DEFAULT);
+ assert_equals(background('second'), NOT_DEFAULT);
+}, 'Adding a button by updating type attribute should update the default button.');
+
+test(function() {
+ container.innerHTML = '<form><input type=submit id=second></form>';
+ assert_equals(background('second'), DEFAULT);
+ var button = document.createElement('button');
+ button.id = 'added'
+ document.querySelector('form').insertBefore(button, document.querySelector('#second'));
+ assert_equals(background('added'), DEFAULT);
+ assert_equals(background('second'), NOT_DEFAULT);
+}, 'Adding a button to a DOM tree should update the default button.');
+
+test(function() {
+ container.innerHTML = '<input type=submit id=added><form id=f1><input type=submit id=second></form>';
+ assert_equals(background('added'), NOT_DEFAULT);
+ assert_equals(background('second'), DEFAULT);
+ document.querySelector('#added').setAttribute('form', 'f1');
+ assert_equals(background('added'), DEFAULT, 'added button should be default.');
+ assert_equals(background('second'), NOT_DEFAULT);
+}, 'Adding a button by form content attribute should update the default button.');
+
+</script>
+</body>

Powered by Google App Engine
This is Rietveld 408576698