| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 util = {}; | 5 var util = {}; |
| 6 | 6 |
| 7 // Creates a <webview> tag in document.body and returns the reference to it. | 7 // Creates a <webview> tag in document.body and returns the reference to it. |
| 8 // It also sets a dummy src. The dummy src is significant because this makes | 8 // It also sets a dummy src. The dummy src is significant because this makes |
| 9 // sure that the <object> shim is created (asynchronously at this point) for the | 9 // sure that the <object> shim is created (asynchronously at this point) for the |
| 10 // <webview> tag. This makes the <webview> tag ready for add/removeEventListener | 10 // <webview> tag. This makes the <webview> tag ready for add/removeEventListener |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 }, 0); | 125 }, 0); |
| 126 }, | 126 }, |
| 127 | 127 |
| 128 function webViewEventName() { | 128 function webViewEventName() { |
| 129 var webview = document.createElement('webview'); | 129 var webview = document.createElement('webview'); |
| 130 webview.setAttribute('src', 'data:text/html,webview check api'); | 130 webview.setAttribute('src', 'data:text/html,webview check api'); |
| 131 document.body.appendChild(webview); | 131 document.body.appendChild(webview); |
| 132 | 132 |
| 133 setTimeout(function() { | 133 setTimeout(function() { |
| 134 webview.addEventListener('loadstart', function(evt) { | 134 webview.addEventListener('loadstart', function(evt) { |
| 135 chrome.test.assertEq('loadstart', evt.name); | 135 chrome.test.assertEq('loadstart', evt.type); |
| 136 }); | 136 }); |
| 137 | 137 |
| 138 webview.addEventListener('loadstop', function(evt) { | 138 webview.addEventListener('loadstop', function(evt) { |
| 139 chrome.test.assertEq('loadstop', evt.name); | 139 chrome.test.assertEq('loadstop', evt.type); |
| 140 webview.terminate(); | 140 webview.terminate(); |
| 141 }); | 141 }); |
| 142 | 142 |
| 143 webview.addEventListener('exit', function(evt) { | 143 webview.addEventListener('exit', function(evt) { |
| 144 chrome.test.assertEq('exit', evt.name); | 144 chrome.test.assertEq('exit', evt.type); |
| 145 chrome.test.succeed(); | 145 chrome.test.succeed(); |
| 146 }); | 146 }); |
| 147 | 147 |
| 148 webview.setAttribute('src', 'data:text/html,trigger navigation'); | 148 webview.setAttribute('src', 'data:text/html,trigger navigation'); |
| 149 }, 0); | 149 }, 0); |
| 150 }, | 150 }, |
| 151 | 151 |
| 152 // This test registers two listeners on an event (loadcommit) and removes | 152 // This test registers two listeners on an event (loadcommit) and removes |
| 153 // the <webview> tag when the first listener fires. | 153 // the <webview> tag when the first listener fires. |
| 154 // Current expected behavior is that the second event listener will still | 154 // Current expected behavior is that the second event listener will still |
| (...skipping 12 matching lines...) Expand all Loading... |
| 167 webview = null; | 167 webview = null; |
| 168 // Make sure the js executes after nulling |webview|. | 168 // Make sure the js executes after nulling |webview|. |
| 169 continuedAfterDelete = true; | 169 continuedAfterDelete = true; |
| 170 } else if (loadCommitCount == 2) { | 170 } else if (loadCommitCount == 2) { |
| 171 chrome.test.assertTrue(continuedAfterDelete); | 171 chrome.test.assertTrue(continuedAfterDelete); |
| 172 chrome.test.succeed(); | 172 chrome.test.succeed(); |
| 173 } | 173 } |
| 174 }; | 174 }; |
| 175 | 175 |
| 176 var onLoadCommitA = function(e) { | 176 var onLoadCommitA = function(e) { |
| 177 chrome.test.assertEq('loadcommit', e.name); | 177 chrome.test.assertEq('loadcommit', e.type); |
| 178 if (e.url == url) { | 178 if (e.url == url) { |
| 179 updateLoadCommitCount(); | 179 updateLoadCommitCount(); |
| 180 } | 180 } |
| 181 }; | 181 }; |
| 182 var onLoadCommitB = function(e) { | 182 var onLoadCommitB = function(e) { |
| 183 chrome.test.assertEq('loadcommit', e.name); | 183 chrome.test.assertEq('loadcommit', e.type); |
| 184 if (e.url == url) { | 184 if (e.url == url) { |
| 185 updateLoadCommitCount(); | 185 updateLoadCommitCount(); |
| 186 } | 186 } |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 setTimeout(function() { | 189 setTimeout(function() { |
| 190 // The test starts from here, by setting the src to |url|. Event | 190 // The test starts from here, by setting the src to |url|. Event |
| 191 // listener registration works because we already have a (dummy) src set | 191 // listener registration works because we already have a (dummy) src set |
| 192 // on the <webview> tag. | 192 // on the <webview> tag. |
| 193 webview.addEventListener('loadcommit', onLoadCommitA); | 193 webview.addEventListener('loadcommit', onLoadCommitA); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 chrome.test.assertTrue(loadCommitCCalledStep2); | 271 chrome.test.assertTrue(loadCommitCCalledStep2); |
| 272 | 272 |
| 273 chrome.test.succeed(); | 273 chrome.test.succeed(); |
| 274 } else if (listenerFireCount2 > 2) { | 274 } else if (listenerFireCount2 > 2) { |
| 275 // More than expected listeners fired. | 275 // More than expected listeners fired. |
| 276 chrome.test.fail(); | 276 chrome.test.fail(); |
| 277 } | 277 } |
| 278 }; | 278 }; |
| 279 | 279 |
| 280 var onLoadCommitA = function(e) { | 280 var onLoadCommitA = function(e) { |
| 281 chrome.test.assertEq('loadcommit', e.name); | 281 chrome.test.assertEq('loadcommit', e.type); |
| 282 switch (e.url) { | 282 switch (e.url) { |
| 283 case urlStep1: // Step 1. | 283 case urlStep1: // Step 1. |
| 284 chrome.test.log('Step 1. onLoadCommitA'); | 284 chrome.test.log('Step 1. onLoadCommitA'); |
| 285 chrome.test.assertFalse(loadCommitACalledStep1); | 285 chrome.test.assertFalse(loadCommitACalledStep1); |
| 286 loadCommitACalledStep1 = true; | 286 loadCommitACalledStep1 = true; |
| 287 | 287 |
| 288 updateTestStateOnListenerStep1(); | 288 updateTestStateOnListenerStep1(); |
| 289 break; | 289 break; |
| 290 case urlStep2: // Step 2. | 290 case urlStep2: // Step 2. |
| 291 chrome.test.log('Step 2. onLoadCommitA'); | 291 chrome.test.log('Step 2. onLoadCommitA'); |
| 292 chrome.test.assertTrue(expectAToFireInStep2); | 292 chrome.test.assertTrue(expectAToFireInStep2); |
| 293 // Can be called at most once. | 293 // Can be called at most once. |
| 294 chrome.test.assertFalse(loadCommitACalledStep2); | 294 chrome.test.assertFalse(loadCommitACalledStep2); |
| 295 loadCommitACalledStep2 = true; | 295 loadCommitACalledStep2 = true; |
| 296 | 296 |
| 297 updateTestStateOnListenerStep2(); | 297 updateTestStateOnListenerStep2(); |
| 298 break; | 298 break; |
| 299 } | 299 } |
| 300 }; | 300 }; |
| 301 | 301 |
| 302 var onLoadCommitB = function(e) { | 302 var onLoadCommitB = function(e) { |
| 303 chrome.test.assertEq('loadcommit', e.name); | 303 chrome.test.assertEq('loadcommit', e.type); |
| 304 switch (e.url) { | 304 switch (e.url) { |
| 305 case urlStep1: // Step 1. | 305 case urlStep1: // Step 1. |
| 306 chrome.test.log('Step 1. onLoadCommitB'); | 306 chrome.test.log('Step 1. onLoadCommitB'); |
| 307 chrome.test.assertFalse(loadCommitBCalledStep1); | 307 chrome.test.assertFalse(loadCommitBCalledStep1); |
| 308 loadCommitBCalledStep1 = true; | 308 loadCommitBCalledStep1 = true; |
| 309 | 309 |
| 310 updateTestStateOnListenerStep1(); | 310 updateTestStateOnListenerStep1(); |
| 311 break; | 311 break; |
| 312 case urlStep2: // Step 2. | 312 case urlStep2: // Step 2. |
| 313 chrome.test.log('Step 2. onLoadCommitB'); | 313 chrome.test.log('Step 2. onLoadCommitB'); |
| 314 chrome.test.assertTrue(expecBToFireInStep2); | 314 chrome.test.assertTrue(expecBToFireInStep2); |
| 315 // Can be called at most once. | 315 // Can be called at most once. |
| 316 chrome.test.assertFalse(loadCommitBCalledStep2); | 316 chrome.test.assertFalse(loadCommitBCalledStep2); |
| 317 loadCommitBCalledStep2 = true; | 317 loadCommitBCalledStep2 = true; |
| 318 | 318 |
| 319 updateTestStateOnListenerStep2(); | 319 updateTestStateOnListenerStep2(); |
| 320 break; | 320 break; |
| 321 } | 321 } |
| 322 }; | 322 }; |
| 323 | 323 |
| 324 var onLoadCommitC = function(e) { | 324 var onLoadCommitC = function(e) { |
| 325 chrome.test.assertEq('loadcommit', e.name); | 325 chrome.test.assertEq('loadcommit', e.type); |
| 326 switch (e.url) { | 326 switch (e.url) { |
| 327 case urlStep1: // Step 1. | 327 case urlStep1: // Step 1. |
| 328 chrome.test.fail(); | 328 chrome.test.fail(); |
| 329 break; | 329 break; |
| 330 case urlStep2: // Step 2. | 330 case urlStep2: // Step 2. |
| 331 chrome.test.log('Step 2. onLoadCommitC'); | 331 chrome.test.log('Step 2. onLoadCommitC'); |
| 332 chrome.test.assertFalse(loadCommitCCalledStep2); | 332 chrome.test.assertFalse(loadCommitCCalledStep2); |
| 333 loadCommitCCalledStep2 = true; | 333 loadCommitCCalledStep2 = true; |
| 334 | 334 |
| 335 updateTestStateOnListenerStep2(); | 335 updateTestStateOnListenerStep2(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 352 // which should not be possible. | 352 // which should not be possible. |
| 353 function cannotMutateEventName() { | 353 function cannotMutateEventName() { |
| 354 var webview = util.createWebViewTagInDOM(); | 354 var webview = util.createWebViewTagInDOM(); |
| 355 var url = 'data:text/html,<body>Two</body>'; | 355 var url = 'data:text/html,<body>Two</body>'; |
| 356 | 356 |
| 357 var loadCommitACalled = false; | 357 var loadCommitACalled = false; |
| 358 var loadCommitBCalled = false; | 358 var loadCommitBCalled = false; |
| 359 | 359 |
| 360 var maybeFinishTest = function(e) { | 360 var maybeFinishTest = function(e) { |
| 361 if (loadCommitACalled && loadCommitBCalled) { | 361 if (loadCommitACalled && loadCommitBCalled) { |
| 362 chrome.test.assertEq('loadcommit', e.name); | 362 chrome.test.assertEq('loadcommit', e.type); |
| 363 chrome.test.assertTrue(e.isTopLevel); | 363 chrome.test.assertTrue(e.isTopLevel); |
| 364 chrome.test.succeed(); | 364 chrome.test.succeed(); |
| 365 } | 365 } |
| 366 }; | 366 }; |
| 367 | 367 |
| 368 var onLoadCommitA = function(e) { | 368 var onLoadCommitA = function(e) { |
| 369 if (e.url == url) { | 369 if (e.url == url) { |
| 370 chrome.test.assertEq('loadcommit', e.name); | 370 chrome.test.assertEq('loadcommit', e.type); |
| 371 chrome.test.assertTrue(e.isTopLevel); | 371 chrome.test.assertTrue(e.isTopLevel); |
| 372 chrome.test.assertFalse(loadCommitACalled); | 372 chrome.test.assertFalse(loadCommitACalled); |
| 373 loadCommitACalled = true; | 373 loadCommitACalled = true; |
| 374 // Try mucking with properities inside |e|. | 374 // Try mucking with properities inside |e|. |
| 375 e.name = 'modified'; | 375 e.type = 'modified'; |
| 376 e.isTopLevel = 'string-value'; | 376 e.isTopLevel = 'string-value'; |
| 377 maybeFinishTest(e); | 377 maybeFinishTest(e); |
| 378 } | 378 } |
| 379 }; | 379 }; |
| 380 var onLoadCommitB = function(e) { | 380 var onLoadCommitB = function(e) { |
| 381 if (e.url == url) { | 381 if (e.url == url) { |
| 382 chrome.test.assertEq('loadcommit', e.name); | 382 chrome.test.assertEq('loadcommit', e.type); |
| 383 chrome.test.assertTrue(e.isTopLevel); | 383 chrome.test.assertTrue(e.isTopLevel); |
| 384 chrome.test.assertFalse(loadCommitBCalled); | 384 chrome.test.assertFalse(loadCommitBCalled); |
| 385 loadCommitBCalled = true; | 385 loadCommitBCalled = true; |
| 386 // Try mucking with properities inside |e|. | 386 // Try mucking with properities inside |e|. |
| 387 e.name = 'modified'; | 387 e.type = 'modified'; |
| 388 e.isTopLevel = 'string-value'; | 388 e.isTopLevel = 'string-value'; |
| 389 maybeFinishTest(e); | 389 maybeFinishTest(e); |
| 390 } | 390 } |
| 391 }; | 391 }; |
| 392 | 392 |
| 393 setTimeout(function() { | 393 setTimeout(function() { |
| 394 // The test starts from here, by setting the src to |url|. Event | 394 // The test starts from here, by setting the src to |url|. Event |
| 395 // listener registration works because we already have a (dummy) src set | 395 // listener registration works because we already have a (dummy) src set |
| 396 // on the <webview> tag. | 396 // on the <webview> tag. |
| 397 webview.addEventListener('loadcommit', onLoadCommitA); | 397 webview.addEventListener('loadcommit', onLoadCommitA); |
| 398 webview.addEventListener('loadcommit', onLoadCommitB); | 398 webview.addEventListener('loadcommit', onLoadCommitB); |
| 399 webview.setAttribute('src', url); | 399 webview.setAttribute('src', url); |
| 400 }, 0); | 400 }, 0); |
| 401 } | 401 } |
| 402 ]); | 402 ]); |
| 403 }; | 403 }; |
| OLD | NEW |