| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var embedder = {}; | 5 var embedder = {}; |
| 6 embedder.tests = {}; | 6 embedder.tests = {}; |
| 7 embedder.baseGuestURL = ''; | 7 embedder.baseGuestURL = ''; |
| 8 embedder.guestURL = ''; | 8 embedder.guestURL = ''; |
| 9 | 9 |
| 10 window.runTest = function(testName) { | 10 window.runTest = function(testName) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 webview.addEventListener('dialog', function(e) { | 98 webview.addEventListener('dialog', function(e) { |
| 99 dialogHandler(e); | 99 dialogHandler(e); |
| 100 }); | 100 }); |
| 101 | 101 |
| 102 webview.setAttribute('src', guestUrl); | 102 webview.setAttribute('src', guestUrl); |
| 103 document.body.appendChild(webview); | 103 document.body.appendChild(webview); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Tests begin. | 106 // Tests begin. |
| 107 | 107 |
| 108 function testAlertDialog() { | 108 function testDialogAlert() { |
| 109 var messageText = '1337h@x0r'; | 109 var messageText = '1337h@x0r'; |
| 110 | 110 |
| 111 var messageCallback = function(webview, data) { | 111 var messageCallback = function(webview, data) { |
| 112 if (data[0] == 'connected') { | 112 if (data[0] == 'connected') { |
| 113 console.log('The alert dialog test has started.'); | 113 console.log('The alert dialog test has started.'); |
| 114 var msg = ['start-alert-dialog-test', messageText]; | 114 var msg = ['start-alert-dialog-test', messageText]; |
| 115 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); | 115 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); |
| 116 return; | 116 return; |
| 117 } | 117 } |
| 118 | 118 |
| 119 if (data[0] == 'alert-dialog-done') { | 119 if (data[0] == 'alert-dialog-done') { |
| 120 console.log( | 120 console.log( |
| 121 'webview has been unblocked after requesting an alert dialog.'); | 121 'webview has been unblocked after requesting an alert dialog.'); |
| 122 embedder.test.succeed(); | 122 embedder.test.succeed(); |
| 123 return; | 123 return; |
| 124 } | 124 } |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 var dialogHandler = function(e) { | 127 var dialogHandler = function(e) { |
| 128 console.log('webview has requested a dialog.'); | 128 console.log('webview has requested a dialog.'); |
| 129 embedder.test.assertEq('alert', e.messageType); | 129 embedder.test.assertEq('alert', e.messageType); |
| 130 embedder.test.assertEq(messageText, e.messageText); | 130 embedder.test.assertEq(messageText, e.messageText); |
| 131 e.dialog.ok(); | 131 e.dialog.ok(); |
| 132 console.log('The app has responded to the dialog request.'); | 132 console.log('The app has responded to the dialog request.'); |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 setUpDialogTest(messageCallback, dialogHandler); | 135 setUpDialogTest(messageCallback, dialogHandler); |
| 136 } | 136 } |
| 137 | 137 |
| 138 function testConfirmDialog() { | 138 function testDialogConfirm() { |
| 139 var messageText = 'foobar'; | 139 var messageText = 'foobar'; |
| 140 | 140 |
| 141 var messageCallback = function(webview, data) { | 141 var messageCallback = function(webview, data) { |
| 142 if (data[0] == 'connected') { | 142 if (data[0] == 'connected') { |
| 143 console.log('The confirm dialog test has started.'); | 143 console.log('The confirm dialog test has started.'); |
| 144 var msg = ['start-confirm-dialog-test', messageText]; | 144 var msg = ['start-confirm-dialog-test', messageText]; |
| 145 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); | 145 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); |
| 146 return; | 146 return; |
| 147 } | 147 } |
| 148 | 148 |
| 149 if (data[0] == 'confirm-dialog-result') { | 149 if (data[0] == 'confirm-dialog-result') { |
| 150 console.log('webview has reported a result for its confirm dialog.'); | 150 console.log('webview has reported a result for its confirm dialog.'); |
| 151 embedder.test.assertEq(true, data[1]); | 151 embedder.test.assertEq(true, data[1]); |
| 152 embedder.test.succeed(); | 152 embedder.test.succeed(); |
| 153 return; | 153 return; |
| 154 } | 154 } |
| 155 }; | 155 }; |
| 156 | 156 |
| 157 var dialogHandler = function(e) { | 157 var dialogHandler = function(e) { |
| 158 console.log('webview has requested a dialog.'); | 158 console.log('webview has requested a dialog.'); |
| 159 embedder.test.assertEq('confirm', e.messageType); | 159 embedder.test.assertEq('confirm', e.messageType); |
| 160 embedder.test.assertEq(messageText, e.messageText); | 160 embedder.test.assertEq(messageText, e.messageText); |
| 161 e.dialog.ok(); | 161 e.dialog.ok(); |
| 162 console.log('The app has responded to the dialog request.'); | 162 console.log('The app has responded to the dialog request.'); |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 setUpDialogTest(messageCallback, dialogHandler); | 165 setUpDialogTest(messageCallback, dialogHandler); |
| 166 } | 166 } |
| 167 | 167 |
| 168 function testConfirmDialogCancel() { | 168 function testDialogConfirmCancel() { |
| 169 var messageText = 'foobar'; | 169 var messageText = 'foobar'; |
| 170 | 170 |
| 171 var messageCallback = function(webview, data) { | 171 var messageCallback = function(webview, data) { |
| 172 if (data[0] == 'connected') { | 172 if (data[0] == 'connected') { |
| 173 console.log('The confirm dialog test has started.'); | 173 console.log('The confirm dialog test has started.'); |
| 174 var msg = ['start-confirm-dialog-test', messageText]; | 174 var msg = ['start-confirm-dialog-test', messageText]; |
| 175 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); | 175 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); |
| 176 return; | 176 return; |
| 177 } | 177 } |
| 178 | 178 |
| 179 if (data[0] == 'confirm-dialog-result') { | 179 if (data[0] == 'confirm-dialog-result') { |
| 180 console.log('webview has reported a result for its confirm dialog.'); | 180 console.log('webview has reported a result for its confirm dialog.'); |
| 181 embedder.test.assertEq(false, data[1]); | 181 embedder.test.assertEq(false, data[1]); |
| 182 embedder.test.succeed(); | 182 embedder.test.succeed(); |
| 183 return; | 183 return; |
| 184 } | 184 } |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 var dialogHandler = function(e) { | 187 var dialogHandler = function(e) { |
| 188 console.log('webview has requested a dialog.'); | 188 console.log('webview has requested a dialog.'); |
| 189 embedder.test.assertEq('confirm', e.messageType); | 189 embedder.test.assertEq('confirm', e.messageType); |
| 190 embedder.test.assertEq(messageText, e.messageText); | 190 embedder.test.assertEq(messageText, e.messageText); |
| 191 e.dialog.cancel(); | 191 e.dialog.cancel(); |
| 192 console.log('The app has responded to the dialog request.'); | 192 console.log('The app has responded to the dialog request.'); |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 setUpDialogTest(messageCallback, dialogHandler); | 195 setUpDialogTest(messageCallback, dialogHandler); |
| 196 } | 196 } |
| 197 | 197 |
| 198 function testConfirmDialogDefaultCancel() { | 198 function testDialogConfirmDefaultCancel() { |
| 199 var messageText = 'foobar'; | 199 var messageText = 'foobar'; |
| 200 | 200 |
| 201 var messageCallback = function(webview, data) { | 201 var messageCallback = function(webview, data) { |
| 202 if (data[0] == 'connected') { | 202 if (data[0] == 'connected') { |
| 203 console.log('The confirm dialog test has started.'); | 203 console.log('The confirm dialog test has started.'); |
| 204 var msg = ['start-confirm-dialog-test', messageText]; | 204 var msg = ['start-confirm-dialog-test', messageText]; |
| 205 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); | 205 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); |
| 206 return; | 206 return; |
| 207 } | 207 } |
| 208 | 208 |
| 209 if (data[0] == 'confirm-dialog-result') { | 209 if (data[0] == 'confirm-dialog-result') { |
| 210 console.log('webview has reported a result for its confirm dialog.'); | 210 console.log('webview has reported a result for its confirm dialog.'); |
| 211 embedder.test.assertEq(false, data[1]); | 211 embedder.test.assertEq(false, data[1]); |
| 212 embedder.test.succeed(); | 212 embedder.test.succeed(); |
| 213 return; | 213 return; |
| 214 } | 214 } |
| 215 }; | 215 }; |
| 216 | 216 |
| 217 var dialogHandler = function(e) { | 217 var dialogHandler = function(e) { |
| 218 console.log('webview has requested a dialog.'); | 218 console.log('webview has requested a dialog.'); |
| 219 embedder.test.assertEq('confirm', e.messageType); | 219 embedder.test.assertEq('confirm', e.messageType); |
| 220 embedder.test.assertEq(messageText, e.messageText); | 220 embedder.test.assertEq(messageText, e.messageText); |
| 221 }; | 221 }; |
| 222 | 222 |
| 223 setUpDialogTest(messageCallback, dialogHandler); | 223 setUpDialogTest(messageCallback, dialogHandler); |
| 224 } | 224 } |
| 225 | 225 |
| 226 function testConfirmDialogDefaultGCCancel() { | 226 function testDialogConfirmDefaultGCCancel() { |
| 227 var messageText = 'foobar'; | 227 var messageText = 'foobar'; |
| 228 | 228 |
| 229 var messageCallback = function(webview, data) { | 229 var messageCallback = function(webview, data) { |
| 230 if (data[0] == 'connected') { | 230 if (data[0] == 'connected') { |
| 231 console.log('The confirm dialog test has started.'); | 231 console.log('The confirm dialog test has started.'); |
| 232 var msg = ['start-confirm-dialog-test', messageText]; | 232 var msg = ['start-confirm-dialog-test', messageText]; |
| 233 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); | 233 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); |
| 234 return; | 234 return; |
| 235 } | 235 } |
| 236 | 236 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 247 embedder.test.assertEq('confirm', e.messageType); | 247 embedder.test.assertEq('confirm', e.messageType); |
| 248 embedder.test.assertEq(messageText, e.messageText); | 248 embedder.test.assertEq(messageText, e.messageText); |
| 249 // Prevent default to leave cleanup in the GC's hands. | 249 // Prevent default to leave cleanup in the GC's hands. |
| 250 e.preventDefault(); | 250 e.preventDefault(); |
| 251 window.setTimeout(function() { window.gc(); }); | 251 window.setTimeout(function() { window.gc(); }); |
| 252 }; | 252 }; |
| 253 | 253 |
| 254 setUpDialogTest(messageCallback, dialogHandler); | 254 setUpDialogTest(messageCallback, dialogHandler); |
| 255 } | 255 } |
| 256 | 256 |
| 257 function testPromptDialog() { | 257 function testDialogPrompt() { |
| 258 var messageText = 'bleep'; | 258 var messageText = 'bleep'; |
| 259 var defaultPromptText = 'bloop'; | 259 var defaultPromptText = 'bloop'; |
| 260 var returnPromptText = 'blah'; | 260 var returnPromptText = 'blah'; |
| 261 | 261 |
| 262 var messageCallback = function(webview, data) { | 262 var messageCallback = function(webview, data) { |
| 263 if (data[0] == 'connected') { | 263 if (data[0] == 'connected') { |
| 264 console.log('The prompt dialog test has started.'); | 264 console.log('The prompt dialog test has started.'); |
| 265 var msg = ['start-prompt-dialog-test', messageText, defaultPromptText]; | 265 var msg = ['start-prompt-dialog-test', messageText, defaultPromptText]; |
| 266 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); | 266 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); |
| 267 return; | 267 return; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 281 embedder.test.assertEq(messageText, e.messageText); | 281 embedder.test.assertEq(messageText, e.messageText); |
| 282 embedder.test.assertEq(defaultPromptText, e.defaultPromptText); | 282 embedder.test.assertEq(defaultPromptText, e.defaultPromptText); |
| 283 e.dialog.ok(returnPromptText); | 283 e.dialog.ok(returnPromptText); |
| 284 console.log('The app has responded to the dialog request.'); | 284 console.log('The app has responded to the dialog request.'); |
| 285 }; | 285 }; |
| 286 | 286 |
| 287 setUpDialogTest(messageCallback, dialogHandler); | 287 setUpDialogTest(messageCallback, dialogHandler); |
| 288 } | 288 } |
| 289 | 289 |
| 290 embedder.test.testList = { | 290 embedder.test.testList = { |
| 291 'testAlertDialog': testAlertDialog, | 291 'testDialogAlert': testDialogAlert, |
| 292 'testConfirmDialog': testConfirmDialog, | 292 'testDialogConfirm': testDialogConfirm, |
| 293 'testConfirmDialogDefaultCancel': testConfirmDialogDefaultCancel, | 293 'testDialogConfirmCancel': testDialogConfirmCancel, |
| 294 'testConfirmDialogDefaultGCCancel': testConfirmDialogDefaultGCCancel, | 294 'testDialogConfirmDefaultCancel': testDialogConfirmDefaultCancel, |
| 295 'testConfirmDialogCancel': testConfirmDialogCancel, | 295 'testDialogConfirmDefaultGCCancel': testDialogConfirmDefaultGCCancel, |
| 296 'testPromptDialog': testPromptDialog | 296 'testDialogPrompt': testDialogPrompt |
| 297 }; | 297 }; |
| 298 | 298 |
| 299 onload = function() { | 299 onload = function() { |
| 300 chrome.test.getConfig(function(config) { | 300 chrome.test.getConfig(function(config) { |
| 301 chrome.test.sendMessage('Launched'); | 301 chrome.test.sendMessage('LAUNCHED'); |
| 302 }); | 302 }); |
| 303 }; | 303 }; |
| OLD | NEW |