Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / script-tests / inputText-never-fired-on-keydown-cancel.js
blob7340ee3ee2a61552f2b0918af61ca30a65d16634
1 description('Test that ensure textInput events should not fired when preceding key events are cancelled');
3 var targetRoot = document.createElement("div");
4 targetRoot.innerHTML += "<input type='text' id='targetInput' />";
5 targetRoot.innerHTML += "<textarea id='targetTextarea'></textarea>";
6 targetRoot.innerHTML += "<div id='targetEditable' contentEditable></div>";
7 document.body.appendChild(targetRoot);
9 var targetInput = document.getElementById("targetInput");
10 var targetTextarea = document.getElementById("targetTextarea");
11 var targetEditable = document.getElementById("targetEditable");
13 var receivedEventTarget = null;
15 function handleTextInput(evt)
17 receivedEventTarget = evt.target;
20 var shouldCancel = false;
22 function mayCancel(evt)
24 if (shouldCancel)
25 evt.preventDefault();
28 targetInput.addEventListener("textInput", handleTextInput);
29 targetInput.addEventListener("keydown", mayCancel);
30 targetTextarea.addEventListener("textInput", handleTextInput);
31 targetTextarea.addEventListener("keydown", mayCancel);
32 targetEditable.addEventListener("textInput", handleTextInput);
33 targetEditable.addEventListener("keydown", mayCancel);
35 function setup(tocancel)
37 receivedEventTarget = null;
38 shouldCancel = tocancel;
41 function test(targetNode)
43 window.targetNode = targetNode;
44 setup(false);
45 eventSender.keyDown("a");
46 shouldBe("window.targetNode", "receivedEventTarget");
47 setup(true);
48 eventSender.keyDown("a");
49 shouldBe("null", "receivedEventTarget");
52 targetInput.focus();
53 test(targetInput);
55 targetTextarea.focus();
56 test(targetTextarea);
58 window.getSelection().setBaseAndExtent(targetEditable, 0, targetEditable, 0);
59 test(targetEditable);
61 targetRoot.style.display = "none";