Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>Modal Prompts Test</title>
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
6 <script type="text/javascript" src="prompt_common.js"></script>
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
8 </head>
9 <body>
10 Prompter tests: modal prompts
11 <p id="display"></p>
13 <div id="content" style="display: none">
14 <iframe id="iframe"></iframe>
15 </div>
17 <pre id="test">
18 <script class="testbody" type="text/javascript;version=1.8">
20 let prompter = Cc["@mozilla.org/embedcomp/prompt-service;1"].
21 getService(Ci.nsIPromptService2);
22 let ioService = Cc["@mozilla.org/network/io-service;1"].
23 getService(Ci.nsIIOService);
24 let pollTimer;
26 function pollDialog(dialog) {
27 if (dialog.getButton("accept").disabled)
28 return;
30 ok(true, "dialog button is enabled now");
31 pollTimer.cancel();
32 pollTimer = null;
33 dialog.acceptDialog();
34 didDialog = true;
35 }
37 function checkExpectedSelectState(doc, state) {
38 let msg = doc.getElementById("info.txt").value;
39 // XXX check title? OS X has title in content
40 let listbox = doc.getElementById("list");
42 is(msg, state.msg, "Checking expected message");
43 // XXX check title? OS X has title in content
44 // Compare listbox contents
45 let count = listbox.itemCount;
46 is(count, state.items.length, "Checking listbox length");
47 if (count)
48 is(listbox.selectedIndex, 0, "Checking selected index");
50 for (let i = 0; i < count; i++) {
51 let item = listbox.getItemAtIndex(i).label;
52 is(item, items[i], "Checking item #" + i + " label");
53 }
54 }
56 /*
57 * handleDialog
58 *
59 * Invoked a short period of time after calling startCallbackTimer(), and
60 * allows testing the actual prompt dialog while it's being displayed. Tests
61 * should call startCallbackTimer() each time the auth dialog is expected (the
62 * timer is a one-shot).
63 */
64 function handleDialog(doc, testNum) {
65 ok(true, "--- handleDialog for test " + testNum + " ---");
67 let dialog = doc.getElementsByTagName("dialog")[0];
68 let listbox = doc.getElementById("list");
69 let clickOK = true;
70 let state;
72 // XXX check focused element
73 // XXX check text/passbox labels?
74 // XXX check button labels?
76 switch(testNum) {
77 case 1:
78 // Select (0 items)
79 state = {
80 msg : "This is the select text.",
81 title : "TestTitle",
82 items : [],
83 };
84 checkExpectedSelectState(doc, state);
85 break;
87 case 2:
88 // Select (3 items, default ok)
89 state = {
90 msg : "This is the select text.",
91 title : "TestTitle",
92 items : ["one", "two", "three"],
93 };
94 checkExpectedSelectState(doc, state);
95 break;
97 case 3:
98 // Select (3 items, change selection, ok)
99 state = {
100 msg : "This is the select text.",
101 title : "TestTitle",
102 items : ["one", "two", "three"],
103 };
104 checkExpectedSelectState(doc, state);
105 // XXX need to trigger old code's click listener
106 listbox.selectedIndex = 1;
107 //listbox.getItemAtIndex(1).click();
108 break;
110 case 4:
111 // Select (3 items, cancel)
112 state = {
113 msg : "This is the select text.",
114 title : "TestTitle",
115 items : ["one", "two", "three"],
116 };
117 checkExpectedSelectState(doc, state);
118 clickOK = false;
119 break;
121 default:
122 ok(false, "Uhh, unhandled switch for testNum #" + testNum);
123 break;
124 }
127 if (clickOK)
128 dialog.acceptDialog();
129 else
130 dialog.cancelDialog();
132 ok(true, "handleDialog done");
133 didDialog = true;
134 }
136 let testNum = 0;
137 let selectVal = {};
138 let isOK;
140 isSelectDialog = true;
141 isTabModal = false;
142 usePromptService = true;
144 // ===== test 1 =====
145 // Select (0 items, ok)
146 testNum++;
147 startCallbackTimer();
148 items = [];
149 selectVal.value = null; // outparam, just making sure.
150 isOK = prompter.select(window, "TestTitle", "This is the select text.", items.length, items, selectVal);
151 is(isOK, true, "checked expected retval");
152 is(selectVal.value, -1, "checking selected index");
153 ok(didDialog, "handleDialog was invoked");
155 // ===== test 2 =====
156 // Select (3 items, ok)
157 testNum++;
158 startCallbackTimer();
159 items = ["one", "two", "three"];
160 selectVal.value = null; // outparam, just making sure.
161 isOK = prompter.select(window, "TestTitle", "This is the select text.", items.length, items, selectVal);
162 is(isOK, true, "checked expected retval");
163 is(selectVal.value, 0, "checking selected index");
164 ok(didDialog, "handleDialog was invoked");
166 // ===== test 3 =====
167 // Select (3 items, selection changed, ok)
168 testNum++;
169 startCallbackTimer();
170 items = ["one", "two", "three"];
171 selectVal.value = null; // outparam, just making sure.
172 isOK = prompter.select(window, "TestTitle", "This is the select text.", items.length, items, selectVal);
173 is(isOK, true, "checked expected retval");
174 is(selectVal.value, 1, "checking selected index");
175 ok(didDialog, "handleDialog was invoked");
177 // ===== test 4 =====
178 // Select (3 items, cancel)
179 testNum++;
180 startCallbackTimer();
181 items = ["one", "two", "three"];
182 selectVal.value = null; // outparam, just making sure.
183 isOK = prompter.select(window, "TestTitle", "This is the select text.", items.length, items, selectVal);
184 is(isOK, false, "checked expected retval");
185 is(selectVal.value, 0, "checking selected index");
186 ok(didDialog, "handleDialog was invoked");
189 </script>
190 </pre>
191 </body>
192 </html>