1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body onload="startTests()">
<form action="input-image-submit.html" method=GET id=form>
<input type=hidden name=state id=state value=step1>
<input type=image name=image id=image src="../resources/apple.gif" value=value>
</form>
<div id="console"></div>
<script>
function notifyDone() {
if (window.testRunner)
testRunner.notifyDone();
}
function failAndDone(message) {
testFailed(message);
notifyDone();
}
function handleSubmit() {
if (state.value == 'to-text-on-submit') {
image.type = 'text';
} else if (state.value == 'to-image-on-submit') {
image.type = 'image';
} else if (state.value == 'remove-input-on-submit') {
image.parentNode.removeChild(image);
image = null;
// Try to clear the reference count of the element.
gc();
}
}
function handleClick() {
if (state.value == 'to-image-on-click') {
image.type = 'image'
}
}
if (window.testRunner)
testRunner.waitUntilDone();
var state = document.getElementById('state');
var image = document.getElementById('image');
image.addEventListener('click', handleClick, false);
var form = document.getElementById('form');
form.addEventListener('submit', handleSubmit, false);
function startTests() {
var x = image.offsetLeft + 7;
var y = image.offsetTop + 11;
var clickEvent = document.createEvent('MouseEvent');
clickEvent.initMouseEvent('click', true, false, document.defaultView, 1, x, y, x, y, false, false, false, false, 0, document);
var enterEvent = document.createEvent('TextEvent');
enterEvent.initTextEvent("textInput", true, true, document.defaultView, "\n");
var query = window.location.search;
if (query.indexOf('state=') == -1) {
// Step 1a: Normal submission by mouse click with type=image
state.value = 'normal';
image.dispatchEvent(clickEvent);
} else if (query.indexOf('state=normal') != -1) {
// Should have image.x=7&image.y=11&image=value.
if (query.indexOf('image.x=7&image.y=11&image=value') == -1) {
failAndDone('Normal submission failed: ' + query);
return;
}
// Step 1b: Submission by element.click() method with type=image
state.value = 'click-method';
image.click();
} else if (query.indexOf('state=click-method') != -1) {
if (query.indexOf('image.x=0&image.y=0&image=value') == -1) {
failAndDone('Click method failed: ' + query);
return;
}
// Step 1c: Submission by keyboard activation with type=image
state.value = 'keyboard';
if (window.eventSender) {
image.focus();
eventSender.keyDown(' ');
} else {
failAndDone('This test requires eventSender');
return;
}
} else if (query.indexOf('state=keyboard') != -1) {
if (query.indexOf('image.x=0&image.y=0&image=value') == -1) {
failAndDone('Activating with keyboard failed: ' + query);
return;
}
// Step 2: Change the type to text on 'submit' event
state.value = 'to-text-on-submit';
image.dispatchEvent(clickEvent);
} else if (query.indexOf('state=to-text-on-submit') != -1) {
// Should have only image=value.
if (query.indexOf('image=value') == -1) {
failAndDone('Changing to text on submit failed: ' + query);
return;
}
// Step 3: Change the type to image on 'submit' event
state.value = 'to-image-on-submit';
image.type = 'text';
image.focus();
image.dispatchEvent(enterEvent);
} else if (query.indexOf('state=to-image-on-submit') != -1) {
// Should have image.x and image.y, but their values are 0.
if (query.indexOf('image.x=0&image.y=0&image=value') == -1) {
failAndDone('Changing to image on submit failed: ' + query);
return;
}
// Step 4: Change the type to image on 'click' event
state.value = 'to-image-on-click';
image.type = 'text';
image.dispatchEvent(clickEvent);
} else if (query.indexOf('state=to-image-on-click') != -1) {
// Same as the normal submission.
if (query.indexOf('image.x=7&image.y=11&image=value') == -1) {
failAndDone('Changing to image on click failed: ' + query);
return;
}
// Step 5: Removed the image button on 'submit' event
state.value = 'remove-input-on-submit';
image.dispatchEvent(clickEvent);
} else if (query.indexOf('state=remove-input-on-submit') != -1) {
// Should have nothing about image.
if (query.indexOf('image.x=') != -1 || query.indexOf('image=value') != -1)
testFailed('Removing the input on submit failed: ' + query);
else
testPassed('All tests passed.');
notifyDone();
}
}
</script>
</body>
</html>
|