4 <script src=
"../../resources/js-test.js"></script>
6 <body onload=
"startTests()">
8 <form action=
"input-image-submit.html" method=GET id=form
>
9 <input type=hidden name=state id=state value=step1
>
10 <input type=image name=image id=image src=resources/apple.gif value=value
>
13 <div id=
"console"></div>
15 function notifyDone() {
16 if (window
.testRunner
)
17 testRunner
.notifyDone();
20 function failAndDone(message
) {
25 function handleSubmit() {
26 if (state
.value
== 'to-text-on-submit') {
28 } else if (state
.value
== 'to-image-on-submit') {
30 } else if (state
.value
== 'remove-input-on-submit') {
31 image
.parentNode
.removeChild(image
);
33 // Try to clear the reference count of the element.
38 function handleClick() {
39 if (state
.value
== 'to-image-on-click') {
44 if (window
.testRunner
)
45 testRunner
.waitUntilDone();
47 var state
= document
.getElementById('state');
48 var image
= document
.getElementById('image');
49 image
.addEventListener('click', handleClick
, false);
50 var form
= document
.getElementById('form');
51 form
.addEventListener('submit', handleSubmit
, false);
53 function startTests() {
54 var x
= image
.offsetLeft
+ 7;
55 var y
= image
.offsetTop
+ 11;
56 var clickEvent
= document
.createEvent('MouseEvent');
57 clickEvent
.initMouseEvent('click', true, false, document
.defaultView
, 1, x
, y
, x
, y
, false, false, false, false, 0, document
);
58 var enterEvent
= document
.createEvent('TextEvent');
59 enterEvent
.initTextEvent("textInput", true, true, document
.defaultView
, "\n");
60 var query
= window
.location
.search
;
62 if (query
.indexOf('state=') == -1) {
63 // Step 1a: Normal submission by mouse click with type=image
64 state
.value
= 'normal';
65 image
.dispatchEvent(clickEvent
);
66 } else if (query
.indexOf('state=normal') != -1) {
67 // Should have image.x=7&image.y=11&image=value.
68 if (query
.indexOf('image.x=7&image.y=11&image=value') == -1) {
69 failAndDone('Normal submission failed: ' + query
);
73 // Step 1b: Submission by element.click() method with type=image
74 state
.value
= 'click-method';
76 } else if (query
.indexOf('state=click-method') != -1) {
77 if (query
.indexOf('image.x=0&image.y=0&image=value') == -1) {
78 failAndDone('Click method failed: ' + query
);
82 // Step 1c: Submission by keyboard activation with type=image
83 state
.value
= 'keyboard';
84 if (window
.eventSender
) {
86 eventSender
.keyDown(' ');
88 failAndDone('This test requires eventSender');
91 } else if (query
.indexOf('state=keyboard') != -1) {
92 if (query
.indexOf('image.x=0&image.y=0&image=value') == -1) {
93 failAndDone('Activating with keyboard failed: ' + query
);
97 // Step 2: Change the type to text on 'submit' event
98 state
.value
= 'to-text-on-submit';
99 image
.dispatchEvent(clickEvent
);
100 } else if (query
.indexOf('state=to-text-on-submit') != -1) {
101 // Should have only image=value.
102 if (query
.indexOf('image=value') == -1) {
103 failAndDone('Changing to text on submit failed: ' + query
);
107 // Step 3: Change the type to image on 'submit' event
108 state
.value
= 'to-image-on-submit';
111 image
.dispatchEvent(enterEvent
);
112 } else if (query
.indexOf('state=to-image-on-submit') != -1) {
113 // Should have image.x and image.y, but their values are 0.
114 if (query
.indexOf('image.x=0&image.y=0&image=value') == -1) {
115 failAndDone('Changing to image on submit failed: ' + query
);
119 // Step 4: Change the type to image on 'click' event
120 state
.value
= 'to-image-on-click';
122 image
.dispatchEvent(clickEvent
);
123 } else if (query
.indexOf('state=to-image-on-click') != -1) {
124 // Same as the normal submission.
125 if (query
.indexOf('image.x=7&image.y=11&image=value') == -1) {
126 failAndDone('Changing to image on click failed: ' + query
);
130 // Step 5: Removed the image button on 'submit' event
131 state
.value
= 'remove-input-on-submit';
132 image
.dispatchEvent(clickEvent
);
133 } else if (query
.indexOf('state=remove-input-on-submit') != -1) {
134 // Should have nothing about image.
135 if (query
.indexOf('image.x=') != -1 || query
.indexOf('image=value') != -1)
136 testFailed('Removing the input on submit failed: ' + query
);
138 testPassed('All tests passed.');