summaryrefslogtreecommitdiff
path: root/toolkit/components/prompts/test/test_dom_prompts.html
blob: 413ed8fd51c74f02f127c90a2181009236e15bc4 (plain)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<html>
<head>
  <title>Test for DOM prompts</title>
  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="text/javascript" src="prompt_common.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
</pre>

<script class="testbody" type="text/javascript">
var rv;
var state, action;

add_task(function* test_alert_ok() {
    info("Starting test: Alert");
    state = {
        msg         : "This is the alert text.",
        iconClass   : "alert-icon",
        titleHidden : true,
        textHidden  : true,
        passHidden  : true,
        checkHidden : true,
        textValue   : "",
        passValue   : "",
        checkMsg    : "",
        checked     : false,
        focused     : "button0",
        defButton   : "button0",
    };
    action = {
        buttonClick: "ok",
    };

    promptDone = handlePrompt(state, action);

    alert("This is the alert text.");

    yield promptDone;
});

// bug 861605 made the arguments to alert/confirm optional (prompt already was).
add_task(function* test_alert_noargs() {
    info("Starting test: Alert with no args");
    state = {
        msg         : "",
        iconClass   : "alert-icon",
        titleHidden : true,
        textHidden  : true,
        passHidden  : true,
        checkHidden : true,
        textValue   : "",
        passValue   : "",
        checkMsg    : "",
        checked     : false,
        focused     : "button0",
        defButton   : "button0",
    };
    action = {
        buttonClick: "ok",
    };

    promptDone = handlePrompt(state, action);

    try {
        alert();
        ok(true, "alert() without arguments should not throw!");
    } catch (e) {
        ok(false, "alert() without arguments should not throw!");
    }

    yield promptDone;
});


add_task(function* test_confirm_ok() {
    info("Starting test: Confirm");
    state = {
        msg         : "This is the confirm text.",
        iconClass   : "question-icon",
        titleHidden : true,
        textHidden  : true,
        passHidden  : true,
        checkHidden : true,
        textValue   : "",
        passValue   : "",
        checkMsg    : "",
        checked     : false,
        focused     : "button0",
        defButton   : "button0",
    };
    action = {
        buttonClick: "ok",
    };

    promptDone = handlePrompt(state, action);

    rv = confirm("This is the confirm text.");
    is(rv, true, "check prompt return value");

    yield promptDone;
});

// bug 861605 made the arguments to alert/confirm optional (prompt already was).
add_task(function* test_confirm_noargs() {
    info("Starting test: Confirm with no args");
    state = {
        msg         : "",
        iconClass   : "question-icon",
        titleHidden : true,
        textHidden  : true,
        passHidden  : true,
        checkHidden : true,
        textValue   : "",
        passValue   : "",
        checkMsg    : "",
        checked     : false,
        focused     : "button0",
        defButton   : "button0",
    };
    action = {
        buttonClick: "ok",
    };

    promptDone = handlePrompt(state, action);

    try {
        rv = confirm();
        ok(true, "confirm() without arguments should not throw!");
    } catch (e) {
        ok(false, "confirm() without arguments should not throw!");
    }
    is(rv, true, "check prompt return value");

    yield promptDone;
});


add_task(function* test_prompt_ok() {
    info("Starting test: Prompt");
    state = {
        msg         : "This is the Prompt text.",
        iconClass   : "question-icon",
        titleHidden : true,
        textHidden  : false,
        passHidden  : true,
        checkHidden : true,
        textValue   : "",
        passValue   : "",
        checkMsg    : "",
        checked     : false,
        focused     : "textField",
        defButton   : "button0",
    };
    action = {
        buttonClick: "ok",
    };

    promptDone = handlePrompt(state, action);

    rv = prompt("This is the Prompt text.");
    is(rv, "", "check prompt return value");

    yield promptDone;
});

// bug 861605 made the arguments to alert/confirm optional (prompt already was).
add_task(function* test_prompt_noargs() {
    info("Starting test: Prompt with no args");
    state = {
        msg         : "",
        iconClass   : "question-icon",
        titleHidden : true,
        textHidden  : false,
        passHidden  : true,
        checkHidden : true,
        textValue   : "",
        passValue   : "",
        checkMsg    : "",
        checked     : false,
        focused     : "textField",
        defButton   : "button0",
    };
    action = {
        buttonClick: "ok",
    };

    promptDone = handlePrompt(state, action);

    try {
        rv = prompt();
        ok(true, "prompt() without arguments should not throw!");
    } catch (e) {
        ok(false, "prompt() without arguments should not throw!");
    }
    is(rv, "", "check prompt return value");

    yield promptDone;
});

</script>

</body>
</html>