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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 <style>
6 :focus { background: rgb(0, 255, 0); }
7 :not(:focus) { background: rgb(255, 0, 0); }
8 </style>
9 </head>
10 <body>
11 <p id="description"></p>
12 <div id="console"></div>
13 <script>
14 function backgroundOf(id) {
15 return document.defaultView.getComputedStyle(document.getElementById(id), nu ll).getPropertyValue('background-color');
16 }
17 function focusOn(id) {
18 document.getElementById(id).focus();
19 }
20 var unfocusedColor = 'rgb(255, 0, 0)';
21 var focusedColor = 'rgb(0, 255, 0)';
22
23 description('Tests for reportValidity() with invalid event canceling');
24
25 var parent = document.createElement('div');
26 document.body.appendChild(parent);
27 parent.innerHTML = '<form><input id=input-unset name=i required><input id=input2 ></form>';
28 var form = parent.firstChild;
29 var input = form.firstChild;
30
31 debug('"invalid" event is not canceled.');
32 var invalidFired = false;
33 var nothingListener = {};
34 nothingListener.handleEvent = function(event) {
35 invalidFired = true;
36 };
37 focusOn('input2');
38 shouldBeTrue('input.addEventListener("invalid", nothingListener, false); !input. reportValidity() && invalidFired');
39 shouldBe('backgroundOf("input-unset")', 'focusedColor');
40 focusOn('input2');
41 shouldBeTrue('invalidFired = false; !form.reportValidity() && invalidFired');
42 shouldBe('backgroundOf("input-unset")', 'focusedColor');
43 input.removeEventListener('invalid', nothingListener, false);
44
45 debug('');
46 debug('"invalid" event is canceled.');
47 invalidFired = false;
48 var cancelListener = {};
49 cancelListener.handleEvent = function(event) {
50 invalidFired = true;
51 event.preventDefault();
52 };
53 // Even if 'invalid' is canceled, the input.reportValidity() result is still fal se.
54 focusOn('input2');
55 shouldBeTrue('input.addEventListener("invalid", cancelListener, false); !input.r eportValidity() && invalidFired');
56 shouldBe('backgroundOf("input-unset")', 'unfocusedColor');
57 // form.reportValidity() also should be false.
58 shouldBeTrue('invalidFired = false; !form.reportValidity() && invalidFired');
59 shouldBe('backgroundOf("input-unset")', 'unfocusedColor');
60 </script>
61 </body>
62 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698