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

Unified Diff: LayoutTests/fast/forms/reportValidity-cancel.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
« no previous file with comments | « no previous file | LayoutTests/fast/forms/reportValidity-cancel-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/fast/forms/reportValidity-cancel.html
diff --git a/LayoutTests/fast/forms/reportValidity-cancel.html b/LayoutTests/fast/forms/reportValidity-cancel.html
new file mode 100644
index 0000000000000000000000000000000000000000..18586e39a98158d7494044b2cfb845abab4cc713
--- /dev/null
+++ b/LayoutTests/fast/forms/reportValidity-cancel.html
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+function $(id) { return document.getElementById(id); }
+function focusOn(id) {
+ $(id).focus();
+}
+
+description('Tests for reportValidity() with invalid event canceling');
+
+var parent = document.createElement('div');
+document.body.appendChild(parent);
+parent.innerHTML = '<form><input id=input-unset name=i required><input id=input2></form>';
+var form = parent.firstChild;
+var input = form.firstChild;
+
+debug('"invalid" event is not canceled.');
+var invalidFired = false;
+var nothingListener = {};
+nothingListener.handleEvent = function(event) {
+ invalidFired = true;
+};
+focusOn('input2');
+shouldBeTrue('input.addEventListener("invalid", nothingListener, false); !input.reportValidity() && invalidFired');
+shouldBe('document.activeElement', '$("input-unset")');
+focusOn('input2');
+shouldBeTrue('invalidFired = false; !form.reportValidity() && invalidFired');
+shouldBe('document.activeElement', '$("input-unset")');
+input.removeEventListener('invalid', nothingListener, false);
+
+debug('');
+debug('"invalid" event is canceled.');
+invalidFired = false;
+var cancelListener = {};
+cancelListener.handleEvent = function(event) {
+ invalidFired = true;
+ event.preventDefault();
+};
+// Even if 'invalid' is canceled, the input.reportValidity() result is still false.
+focusOn('input2');
+shouldBeTrue('input.addEventListener("invalid", cancelListener, false); !input.reportValidity() && invalidFired');
+shouldNotBe('document.activeElement', '$("input-unset")');
+// form.reportValidity() also should be false.
+shouldBeTrue('invalidFired = false; !form.reportValidity() && invalidFired');
+shouldNotBe('document.activeElement', '$("input-unset")');
+</script>
+</body>
+</html>
« no previous file with comments | « no previous file | LayoutTests/fast/forms/reportValidity-cancel-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698