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

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: 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-cancel.html
diff --git a/LayoutTests/fast/forms/reportValidity-cancel.html b/LayoutTests/fast/forms/reportValidity-cancel.html
new file mode 100644
index 0000000000000000000000000000000000000000..7aeb4756638d9d612759e67b47ab42d085f78147
--- /dev/null
+++ b/LayoutTests/fast/forms/reportValidity-cancel.html
@@ -0,0 +1,62 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+<style>
+:focus { background: rgb(0, 255, 0); }
+:not(:focus) { background: rgb(255, 0, 0); }
+</style>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+function backgroundOf(id) {
+ return document.defaultView.getComputedStyle(document.getElementById(id), null).getPropertyValue('background-color');
+}
+function focusOn(id) {
+ document.getElementById(id).focus();
+}
+var unfocusedColor = 'rgb(255, 0, 0)';
+var focusedColor = 'rgb(0, 255, 0)';
+
+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('backgroundOf("input-unset")', 'focusedColor');
+focusOn('input2');
+shouldBeTrue('invalidFired = false; !form.reportValidity() && invalidFired');
+shouldBe('backgroundOf("input-unset")', 'focusedColor');
+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');
+shouldBe('backgroundOf("input-unset")', 'unfocusedColor');
+// form.reportValidity() also should be false.
+shouldBeTrue('invalidFired = false; !form.reportValidity() && invalidFired');
+shouldBe('backgroundOf("input-unset")', 'unfocusedColor');
+</script>
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698