4 <script src="../js/resources/js-test-pre.js"></script>
5 <script src="resources/common.js"></script>
8 <input id="search_input" type="search" />
11 This tests the behavior of a cancel button in search input forms.
15 function click(position) {
18 eventSender.mouseMoveTo(position.x, position.y);
19 eventSender.mouseDown();
20 eventSender.mouseMoveTo(position.x, position.y);
21 eventSender.mouseUp();
22 eventSender.leapForward(1000);
25 function keydown(character) {
28 eventSender.keyDown(character);
29 eventSender.leapForward(1000);
32 function setInputAttributes(input, value, disabled, readonly) {
34 input.disabled = disabled;
35 input.readOnly = !!readonly;
38 if (window.layoutTestController) {
39 var input = $("search_input");
40 var cancelButtonPosition = searchCancelButtonPosition(input);
41 var middleButtonPosition = {};
42 middleButtonPosition.x = input.offsetLeft + input.offsetWidth / 2;
43 middleButtonPosition.y = input.offsetTop + input.offsetHeight / 2;
48 debug("Test on the input form with disabled=false and readonly=false");
50 setInputAttributes(input, "foo", enabled);
51 debug("Click the cancel button:");
52 click(cancelButtonPosition);
53 shouldBe('input.value', '""');
54 debug("... and then input one character:");
56 shouldBe('input.value', '"b"');
58 setInputAttributes(input, "foo", enabled);
59 debug("Click the center of the form:");
60 click(middleButtonPosition);
61 shouldBe('input.value', '"foo"');
62 debug("... and then input one character:");
64 shouldBe('input.value', '"foob"');
67 debug("Test on the input form with disabled=false and readonly=true");
69 setInputAttributes(input, "foo", enabled, readonly);
70 debug("Click the cancel button:");
71 click(cancelButtonPosition);
72 shouldBe('input.value', '"foo"');
73 debug("... and then input one character:");
75 shouldBe('input.value', '"foo"');
77 setInputAttributes(input, "foo", enabled, readonly);
78 debug("Click the center of the form:");
79 click(middleButtonPosition);
80 shouldBe('input.value', '"foo"');
81 debug("... and then input one character:");
83 shouldBe('input.value', '"foo"');
86 debug("Test on the input form with disabled=true and readonly=false");
88 setInputAttributes(input, "foo", disabled);
89 debug("Click the cancel button:");
90 click(cancelButtonPosition);
91 shouldBe('input.value', '"foo"');
92 debug("... and then input one character:");
94 shouldBe('input.value', '"foo"');
96 setInputAttributes(input, "foo", disabled);
97 debug("Click the center of the form:");
98 click(middleButtonPosition);
99 shouldBe('input.value', '"foo"');
100 debug("... and then input one character:");
102 shouldBe('input.value', '"foo"');
105 debug("Test on the input form with disabled=true and readonly=true");
107 setInputAttributes(input, "foo", disabled, readonly);
108 debug("Click the cancel button:");
109 click(cancelButtonPosition);
110 shouldBe('input.value', '"foo"');
111 debug("... and then input one character:");
113 shouldBe('input.value', '"foo"');
115 setInputAttributes(input, "foo", disabled, readonly);
116 debug("Click the center of the form:");
117 click(middleButtonPosition);
118 shouldBe('input.value', '"foo"');
119 debug("... and then input one character:");
121 shouldBe('input.value', '"foo"');
126 <script src="../js/resources/js-test-post.js"></script>