|
1 /* |
|
2 * |
|
3 * Licensed to the Apache Software Foundation (ASF) under one |
|
4 * or more contributor license agreements. See the NOTICE file |
|
5 * distributed with this work for additional information |
|
6 * regarding copyright ownership. The ASF licenses this file |
|
7 * to you under the Apache License, Version 2.0 (the |
|
8 * "License"); you may not use this file except in compliance |
|
9 * with the License. You may obtain a copy of the License at |
|
10 * |
|
11 * http://www.apache.org/licenses/LICENSE-2.0 |
|
12 * |
|
13 * Unless required by applicable law or agreed to in writing, |
|
14 * software distributed under the License is distributed on an |
|
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|
16 * KIND, either express or implied. See the License for the |
|
17 * specific language governing permissions and limitations |
|
18 * under the License. |
|
19 * |
|
20 */ |
|
21 |
|
22 exports.defineAutoTests = function () { |
|
23 describe('Notification (navigator.notification)', function () { |
|
24 it("should exist", function () { |
|
25 expect(navigator.notification).toBeDefined(); |
|
26 }); |
|
27 |
|
28 it("should contain a beep function", function () { |
|
29 expect(typeof navigator.notification.beep).toBeDefined(); |
|
30 expect(typeof navigator.notification.beep).toBe("function"); |
|
31 }); |
|
32 |
|
33 it("should contain an alert function", function () { |
|
34 expect(typeof navigator.notification.alert).toBeDefined(); |
|
35 expect(typeof navigator.notification.alert).toBe("function"); |
|
36 }); |
|
37 |
|
38 it("should contain a confirm function", function () { |
|
39 expect(typeof navigator.notification.confirm).toBeDefined(); |
|
40 expect(typeof navigator.notification.confirm).toBe("function"); |
|
41 }); |
|
42 |
|
43 it("should contain a prompt function", function () { |
|
44 expect(typeof navigator.notification.prompt).toBeDefined(); |
|
45 expect(typeof navigator.notification.prompt).toBe("function"); |
|
46 }); |
|
47 }); |
|
48 }; |
|
49 |
|
50 /******************************************************************************/ |
|
51 /******************************************************************************/ |
|
52 /******************************************************************************/ |
|
53 |
|
54 exports.defineManualTests = function (contentEl, createActionButton) { |
|
55 var logMessage = function (message) { |
|
56 var log = document.getElementById('info'); |
|
57 var logLine = document.createElement('div'); |
|
58 logLine.innerHTML = message; |
|
59 log.appendChild(logLine); |
|
60 } |
|
61 |
|
62 var clearLog = function () { |
|
63 var log = document.getElementById('info'); |
|
64 log.innerHTML = ''; |
|
65 } |
|
66 |
|
67 var beep = function () { |
|
68 console.log("beep()"); |
|
69 navigator.notification.beep(3); |
|
70 }; |
|
71 |
|
72 var alertDialog = function (message, title, button) { |
|
73 console.log("alertDialog()"); |
|
74 navigator.notification.alert(message, |
|
75 function () { |
|
76 console.log("Alert dismissed."); |
|
77 }, |
|
78 title, button); |
|
79 console.log("After alert"); |
|
80 }; |
|
81 |
|
82 var confirmDialogA = function (message, title, buttons) { |
|
83 clearLog(); |
|
84 navigator.notification.confirm(message, |
|
85 function (r) { |
|
86 if (r === 0) { |
|
87 logMessage("Dismissed dialog without making a selection."); |
|
88 console.log("Dismissed dialog without making a selection."); |
|
89 } else { |
|
90 console.log("You selected " + r); |
|
91 logMessage("You selected " + (buttons.split(","))[r - 1]); |
|
92 } |
|
93 }, |
|
94 title, |
|
95 buttons); |
|
96 }; |
|
97 |
|
98 var confirmDialogB = function (message, title, buttons) { |
|
99 clearLog(); |
|
100 navigator.notification.confirm(message, |
|
101 function (r) { |
|
102 if (r === 0) { |
|
103 logMessage("Dismissed dialog without making a selection."); |
|
104 console.log("Dismissed dialog without making a selection."); |
|
105 } else { |
|
106 console.log("You selected " + r); |
|
107 logMessage("You selected " + buttons[r - 1]); |
|
108 } |
|
109 }, |
|
110 title, |
|
111 buttons); |
|
112 }; |
|
113 |
|
114 var promptDialog = function (message, title, buttons) { |
|
115 clearLog(); |
|
116 navigator.notification.prompt(message, |
|
117 function (r) { |
|
118 if (r && r.buttonIndex === 0) { |
|
119 var msg = "Dismissed dialog"; |
|
120 if (r.input1) { |
|
121 msg += " with input: " + r.input1 |
|
122 } |
|
123 logMessage(msg); |
|
124 console.log(msg); |
|
125 } else { |
|
126 console.log("You selected " + r.buttonIndex + " and entered: " + r.input1); |
|
127 logMessage("You selected " + buttons[r.buttonIndex - 1] + " and entered: " + r.input1); |
|
128 } |
|
129 }, |
|
130 title, |
|
131 buttons); |
|
132 }; |
|
133 |
|
134 /******************************************************************************/ |
|
135 |
|
136 var dialogs_tests = '<div id="beep"></div>' + |
|
137 'Expected result: Device will beep (unless device is on silent). Nothing will get updated in status box.' + |
|
138 '<h2>Dialog Tests</h2>' + |
|
139 '<h3>Dialog boxes will pop up for each of the following tests</h3>' + |
|
140 '<p/> <div id="alert"></div>' + |
|
141 'Expected result: Dialog will say "You pressed alert". Press continue to close dialog. Nothing will get updated in status box.' + |
|
142 '<p/> <div id="confirm_deprecated"></div>' + |
|
143 'Expected result: Dialog will say "You pressed confirm". Press Yes, No, or Maybe to close dialog. Status box will tell you what option you selected.' + |
|
144 '<p/> <div id="confirm"></div>' + |
|
145 'Expected result: Dialog will say "You pressed confirm". Press Yes, No, or Maybe, Not Sure to close dialog. Status box will tell you what option you selected, and should use 1-based indexing.' + |
|
146 '<p/> <div id="prompt"></div>' + |
|
147 'Expected result: Dialog will say "You pressed prompt". Enter any message and press Yes, No, or Maybe, Not Sure to close dialog. Status box will tell you what option you selected and message you entered, and should use 1-based indexing.' + |
|
148 '<p/> <div id="built_in_alert"></div>' + |
|
149 'Expected result: Dialog will have title "index.html" and say "You pressed alert" Press OK to close dialog. Nothing will get updated in status box.' + |
|
150 '<p/> <div id="built_in_confirm"></div>' + |
|
151 'Expected result: Dialog will have title "index.html" and say "You selected confirm". Press Cancel or OK to close dialog. Nothing will get updated in status box.' + |
|
152 '<p/> <div id="built_in_prompt"></div>' + |
|
153 'Expected result: Dialog will have title "index.html" and say "This is a prompt". "Default value" will be in text box. Press Cancel or OK to close dialog. Nothing will get updated in status box.'; |
|
154 |
|
155 contentEl.innerHTML = '<div id="info"></div>' + |
|
156 dialogs_tests; |
|
157 |
|
158 createActionButton('Beep', function () { |
|
159 beep(); |
|
160 }, 'beep'); |
|
161 |
|
162 createActionButton('Alert Dialog', function () { |
|
163 alertDialog('You pressed alert.', 'Alert Dialog', 'Continue'); |
|
164 }, 'alert'); |
|
165 |
|
166 // WP8.1 detection is necessary since it doesn't support confirm dialogs with more than 2 buttons |
|
167 var isRunningOnWP81 = cordova.platformId == "windows" && navigator.userAgent.indexOf('Windows Phone') > -1; |
|
168 |
|
169 createActionButton('Confirm Dialog - Deprecated', function () { |
|
170 var buttons = isRunningOnWP81 ? 'Yes,No' : 'Yes,No,Maybe'; |
|
171 confirmDialogA('You pressed confirm.', 'Confirm Dialog', buttons); |
|
172 }, 'confirm_deprecated'); |
|
173 |
|
174 createActionButton('Confirm Dialog', function () { |
|
175 var buttons = isRunningOnWP81 ? ['Yes', 'Actually, No'] : ['Yes', 'No', 'Maybe, Not Sure']; |
|
176 confirmDialogB('You pressed confirm.', 'Confirm Dialog', buttons); |
|
177 }, 'confirm'); |
|
178 |
|
179 createActionButton('Prompt Dialog', function () { |
|
180 promptDialog('You pressed prompt.', 'Prompt Dialog', ['Yes', 'No', 'Maybe, Not Sure']); |
|
181 }, 'prompt'); |
|
182 |
|
183 createActionButton('Built-in Alert Dialog', function () { |
|
184 typeof alert === 'function' && alert('You pressed alert'); |
|
185 }, 'built_in_alert'); |
|
186 |
|
187 createActionButton('Built-in Confirm Dialog', function () { |
|
188 typeof confirm === 'function' && confirm('You selected confirm'); |
|
189 }, 'built_in_confirm'); |
|
190 |
|
191 createActionButton('Built-in Prompt Dialog', function () { |
|
192 typeof prompt === 'function' && prompt('This is a prompt', 'Default value'); |
|
193 }, 'built_in_prompt'); |
|
194 }; |