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

Unified Diff: LayoutTests/fast/forms/reportValidity-handler-updates-dom.html

Issue 660783002: Implement reportValidity() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Apply couple more tkent's comments + pull Created 6 years, 2 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: LayoutTests/fast/forms/reportValidity-handler-updates-dom.html
diff --git a/LayoutTests/fast/forms/checkValidity-handler-updates-dom.html b/LayoutTests/fast/forms/reportValidity-handler-updates-dom.html
similarity index 58%
copy from LayoutTests/fast/forms/checkValidity-handler-updates-dom.html
copy to LayoutTests/fast/forms/reportValidity-handler-updates-dom.html
index 5d495e492eac886fcc42c39fa1aae49bd7bb0a6c..31620fae4862741b28ee94f374d1b36eae2bba04 100644
--- a/LayoutTests/fast/forms/checkValidity-handler-updates-dom.html
+++ b/LayoutTests/fast/forms/reportValidity-handler-updates-dom.html
@@ -7,7 +7,9 @@
<p id="description"></p>
<div id="console"></div>
<script>
-description('HTMLFormElement::checkValidity() with cases that event handlers called by checkValidity() updates DOM structure.')
+function $(id) { return document.getElementById(id); }
+
+description('HTMLFormElement::reportValidity() with cases that event handlers called by reportValidity() updates DOM structure.')
var parent = document.createElement('div');
document.body.appendChild(parent);
@@ -18,28 +20,46 @@ parent.innerHTML = '<form id=f1><input name=i id=i required></form>';
var handler = function(event) {
parent.innerHTML = '';
};
-document.getElementById('i').addEventListener('invalid', handler, false);
+$('i').addEventListener('invalid', handler, false);
// The specificiation doesn't define the behavior in this case.
// It's ok if WebKit doesn't crash.
-shouldBeFalse('document.getElementById("f1").checkValidity()');
+shouldBeFalse('$("f1").reportValidity()');
// ----------------------------------------------------------------
debug('');
debug('A control to be checked is removed.');
parent.innerHTML = '<form id=f1><input name=i1 id=i1 required><input name=i2 id=i2 required></form>';
var handler1 = function(event) {
- document.getElementById('f1').removeChild(document.getElementById('i2'));
+ $('f1').removeChild($('i2'));
};
-document.getElementById('i1').addEventListener('invalid', handler1, false);
+$('i1').addEventListener('invalid', handler1, false);
var handler2Called = false;
var handler2 = function(event) {
handler2Called = true;
};
-document.getElementById('i2').addEventListener('invalid', handler2, false);
-shouldBeFalse('document.getElementById("f1").checkValidity()');
+$('i2').addEventListener('invalid', handler2, false);
+shouldBeFalse('$("f1").reportValidity()');
// If the node was removed from the form, i2.checkValidity() is called, but an
// invalid event is not fired because it is not in any documents.
shouldBeFalse('handler2Called');
+shouldBe('document.activeElement', '$("i1")');
+
+// ----------------------------------------------------------------
+debug('');
+debug('A control that was checked was removed.');
+parent.innerHTML = '<form id=f1><input name=i1 id=i1 required><input name=i2 id=i2 required></form>';
+var handler1 = function(event) {
+ $('f1').removeChild($('i1'));
+};
+$('i1').addEventListener('invalid', handler1, false);
+var handler2Called = false;
+var handler2 = function(event) {
+ handler2Called = true;
+};
+$('i2').addEventListener('invalid', handler2, false);
+shouldBeFalse('$("f1").reportValidity()');
+shouldBeTrue('handler2Called');
+shouldBe('document.activeElement', '$("i2")');
// ----------------------------------------------------------------
debug('');
@@ -54,12 +74,13 @@ handler1 = function(event) {
input.name = 'i2';
input.required = true;
input.addEventListener('invalid', handler2, false);
- document.getElementById('f1').appendChild(input);
+ $('f1').appendChild(input);
};
-document.getElementById('i1').addEventListener('invalid', handler1, false);
-shouldBeFalse('document.getElementById("f1").checkValidity()');
-// If a new node is added to the form, checkValidity() doesn't handle it.
+$('i1').addEventListener('invalid', handler1, false);
+shouldBeFalse('$("f1").reportValidity()');
+// If a new node is added to the form, reportValidity() doesn't handle it.
shouldBeFalse('handler2Called');
+shouldBe('document.activeElement', '$("i1")');
// ----------------------------------------------------------------
debug('');
@@ -67,17 +88,18 @@ debug('A control is moved to another form.');
parent.innerHTML = '<form id=f1><input name=i1 id=i1 required><input name=i2 id=i2 required></form>'
+ '<form id=f2></form>';
handler1 = function(event) {
- document.getElementById('f2').appendChild(document.getElementById('i2'));
+ $('f2').appendChild($('i2'));
};
-document.getElementById('i1').addEventListener('invalid', handler1, false);
+$('i1').addEventListener('invalid', handler1, false);
handler2Called = false;
handler2 = function(event) {
handler2Called = true;
};
-document.getElementById('i2').addEventListener('invalid', handler2, false);
-shouldBeFalse('document.getElementById("f1").checkValidity()');
+$('i2').addEventListener('invalid', handler2, false);
+shouldBeFalse('$("f1").reportValidity()');
// The moved control is not checked.
shouldBeFalse('handler2Called');
+shouldBe('document.activeElement', '$("i1")');
// ----------------------------------------------------------------
debug('');
@@ -85,12 +107,12 @@ debug('A control is moved to another document.');
parent.innerHTML = '<form id=f1><input name=i1 id=i1 required></form>';
var doc2 = document.implementation.createHTMLDocument();
handler1 = function(event) {
- doc2.body.appendChild(doc2.adoptNode(document.getElementById('i1')));
+ doc2.body.appendChild(doc2.adoptNode($('i1')));
};
-document.getElementById('i1').addEventListener('invalid', handler1, false);
+$('i1').addEventListener('invalid', handler1, false);
// i1 is not listed in 'unhandled invalid controls' because it was moved to
// another document.
-shouldBeTrue('document.getElementById("f1").checkValidity()');
+shouldBeTrue('$("f1").reportValidity()');
parent.innerHTML = '';
</script>

Powered by Google App Engine
This is Rietveld 408576698