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 var embedder = {}; | 6 var embedder = {}; |
7 embedder.baseGuestURL = ''; | 7 embedder.baseGuestURL = ''; |
8 embedder.emptyGuestURL = ''; | 8 embedder.emptyGuestURL = ''; |
9 embedder.windowOpenGuestURL = ''; | 9 embedder.windowOpenGuestURL = ''; |
10 embedder.noReferrerGuestURL = ''; | 10 embedder.noReferrerGuestURL = ''; |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 function(results) { | 594 function(results) { |
595 embedder.test.assertEq(1, results.length); | 595 embedder.test.assertEq(1, results.length); |
596 embedder.test.assertEq('red', results[0]); | 596 embedder.test.assertEq('red', results[0]); |
597 embedder.test.succeed(); | 597 embedder.test.succeed(); |
598 }); | 598 }); |
599 }); | 599 }); |
600 webview.setAttribute('src', 'data:text/html,trigger navigation'); | 600 webview.setAttribute('src', 'data:text/html,trigger navigation'); |
601 document.body.appendChild(webview); | 601 document.body.appendChild(webview); |
602 } | 602 } |
603 | 603 |
| 604 // This test verifies that the call of executeScript will fail and return null |
| 605 // if the webview has been navigated to another source. |
| 606 function testExecuteScriptIsAbortedWhenWebViewSourceIsChanged() { |
| 607 var webview = document.createElement('webview'); |
| 608 var step = 1; |
| 609 var navigationOccur = false; |
| 610 var newSrc = 'data:text/html,trigger navigation'; |
| 611 webview.addEventListener('loadstart', function() { |
| 612 if (step == 1) { |
| 613 webview.setAttribute('src', newSrc); |
| 614 navigationOccur = true; |
| 615 } |
| 616 ++step; |
| 617 }); |
| 618 webview.addEventListener('loadstop', function() { |
| 619 webview.executeScript( |
| 620 {code:'document.body.style.backgroundColor = "red";'}, |
| 621 function(results) { |
| 622 if (navigationOccur) { |
| 623 // Expect a null results because the executeScript failed; |
| 624 // return "red", otherwise. |
| 625 embedder.test.assertEq(null, results); |
| 626 embedder.test.succeed(); |
| 627 } |
| 628 navigationOccur = false; |
| 629 } |
| 630 ); |
| 631 }); |
| 632 webview.setAttribute('src', "about:blank"); |
| 633 document.body.appendChild(webview); |
| 634 } |
| 635 |
604 // This test calls terminate() on guest after it has already been | 636 // This test calls terminate() on guest after it has already been |
605 // terminated. This makes sure we ignore the call gracefully. | 637 // terminated. This makes sure we ignore the call gracefully. |
606 function testTerminateAfterExit() { | 638 function testTerminateAfterExit() { |
607 var webview = document.createElement('webview'); | 639 var webview = document.createElement('webview'); |
608 webview.setAttribute('partition', arguments.callee.name); | 640 webview.setAttribute('partition', arguments.callee.name); |
609 var loadstopSucceedsTest = false; | 641 var loadstopSucceedsTest = false; |
610 webview.addEventListener('loadstop', function(evt) { | 642 webview.addEventListener('loadstop', function(evt) { |
611 embedder.test.assertEq('loadstop', evt.type); | 643 embedder.test.assertEq('loadstop', evt.type); |
612 if (loadstopSucceedsTest) { | 644 if (loadstopSucceedsTest) { |
613 embedder.test.succeed(); | 645 embedder.test.succeed(); |
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1473 'testInvalidChromeExtensionURL': testInvalidChromeExtensionURL, | 1505 'testInvalidChromeExtensionURL': testInvalidChromeExtensionURL, |
1474 'testWebRequestAPIExistence': testWebRequestAPIExistence, | 1506 'testWebRequestAPIExistence': testWebRequestAPIExistence, |
1475 'testEventName': testEventName, | 1507 'testEventName': testEventName, |
1476 'testOnEventProperties': testOnEventProperties, | 1508 'testOnEventProperties': testOnEventProperties, |
1477 'testLoadProgressEvent': testLoadProgressEvent, | 1509 'testLoadProgressEvent': testLoadProgressEvent, |
1478 'testDestroyOnEventListener': testDestroyOnEventListener, | 1510 'testDestroyOnEventListener': testDestroyOnEventListener, |
1479 'testCannotMutateEventName': testCannotMutateEventName, | 1511 'testCannotMutateEventName': testCannotMutateEventName, |
1480 'testPartitionRaisesException': testPartitionRaisesException, | 1512 'testPartitionRaisesException': testPartitionRaisesException, |
1481 'testExecuteScriptFail': testExecuteScriptFail, | 1513 'testExecuteScriptFail': testExecuteScriptFail, |
1482 'testExecuteScript': testExecuteScript, | 1514 'testExecuteScript': testExecuteScript, |
| 1515 'testExecuteScriptIsAbortedWhenWebViewSourceIsChanged': |
| 1516 testExecuteScriptIsAbortedWhenWebViewSourceIsChanged, |
1483 'testTerminateAfterExit': testTerminateAfterExit, | 1517 'testTerminateAfterExit': testTerminateAfterExit, |
1484 'testAssignSrcAfterCrash': testAssignSrcAfterCrash, | 1518 'testAssignSrcAfterCrash': testAssignSrcAfterCrash, |
1485 'testNavOnConsecutiveSrcAttributeChanges': | 1519 'testNavOnConsecutiveSrcAttributeChanges': |
1486 testNavOnConsecutiveSrcAttributeChanges, | 1520 testNavOnConsecutiveSrcAttributeChanges, |
1487 'testNavOnSrcAttributeChange': testNavOnSrcAttributeChange, | 1521 'testNavOnSrcAttributeChange': testNavOnSrcAttributeChange, |
1488 'testReassignSrcAttribute': testReassignSrcAttribute, | 1522 'testReassignSrcAttribute': testReassignSrcAttribute, |
1489 'testRemoveSrcAttribute': testRemoveSrcAttribute, | 1523 'testRemoveSrcAttribute': testRemoveSrcAttribute, |
1490 'testBrowserPluginNotAllowed': testBrowserPluginNotAllowed, | 1524 'testBrowserPluginNotAllowed': testBrowserPluginNotAllowed, |
1491 'testPluginLoadPermission': testPluginLoadPermission, | 1525 'testPluginLoadPermission': testPluginLoadPermission, |
1492 'testNewWindow': testNewWindow, | 1526 'testNewWindow': testNewWindow, |
(...skipping 25 matching lines...) Expand all Loading... |
1518 'testFindAPI': testFindAPI, | 1552 'testFindAPI': testFindAPI, |
1519 'testFindAPI_findupdate': testFindAPI | 1553 'testFindAPI_findupdate': testFindAPI |
1520 }; | 1554 }; |
1521 | 1555 |
1522 onload = function() { | 1556 onload = function() { |
1523 chrome.test.getConfig(function(config) { | 1557 chrome.test.getConfig(function(config) { |
1524 embedder.setUp_(config); | 1558 embedder.setUp_(config); |
1525 chrome.test.sendMessage("Launched"); | 1559 chrome.test.sendMessage("Launched"); |
1526 }); | 1560 }); |
1527 }; | 1561 }; |
OLD | NEW |