OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | 6 |
7 // TODO(lfg) Move these functions to a common js. | 7 // TODO(lfg) Move these functions to a common js. |
8 window.runTest = function(testName) { | 8 window.runTest = function(testName) { |
9 if (!embedder.test.testList[testName]) { | 9 if (!embedder.test.testList[testName]) { |
10 window.console.warn('Incorrect testName: ' + testName); | 10 window.console.warn('Incorrect testName: ' + testName); |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 try { | 530 try { |
531 webview.executeScript( | 531 webview.executeScript( |
532 {code: 'document.body.style.backgroundColor = "red";'}, | 532 {code: 'document.body.style.backgroundColor = "red";'}, |
533 function(results) { embedder.test.fail(); }); | 533 function(results) { embedder.test.fail(); }); |
534 } | 534 } |
535 catch (e) { | 535 catch (e) { |
536 embedder.test.succeed(); | 536 embedder.test.succeed(); |
537 } | 537 } |
538 } | 538 } |
539 | 539 |
| 540 // This test verifies that the loadabort event fires when loading a webview |
| 541 // accessible resource from a partition that is not privileged. |
| 542 function testLoadAbortChromeExtensionURLWrongPartition() { |
| 543 var localResource = chrome.runtime.getURL('guest.html'); |
| 544 var webview = document.createElement('webview'); |
| 545 webview.addEventListener('loadabort', function(e) { |
| 546 embedder.test.assertEq('ERR_ADDRESS_UNREACHABLE', e.reason); |
| 547 embedder.test.succeed(); |
| 548 }); |
| 549 webview.addEventListener('loadstop', function(e) { |
| 550 embedder.test.fail(); |
| 551 }); |
| 552 webview.setAttribute('src', localResource); |
| 553 document.body.appendChild(webview); |
| 554 } |
| 555 |
| 556 // This test verifies that the loadabort event fires as expected when an illegal |
| 557 // chrome URL is provided. |
| 558 function testLoadAbortIllegalChromeURL() { |
| 559 var webview = document.createElement('webview'); |
| 560 var onFirstLoadStop = function(e) { |
| 561 webview.removeEventListener('loadstop', onFirstLoadStop); |
| 562 webview.setAttribute('src', 'chrome://newtab'); |
| 563 }; |
| 564 webview.addEventListener('loadstop', onFirstLoadStop); |
| 565 webview.addEventListener('loadabort', function(e) { |
| 566 embedder.test.assertEq('ERR_ABORTED', e.reason); |
| 567 embedder.test.succeed(); |
| 568 }); |
| 569 webview.setAttribute('src', 'about:blank'); |
| 570 document.body.appendChild(webview); |
| 571 } |
| 572 |
| 573 function testLoadAbortIllegalFileURL() { |
| 574 var webview = document.createElement('webview'); |
| 575 webview.addEventListener('loadabort', function(e) { |
| 576 embedder.test.assertEq('ERR_ABORTED', e.reason); |
| 577 embedder.test.succeed(); |
| 578 }); |
| 579 webview.setAttribute('src', 'file://foo'); |
| 580 document.body.appendChild(webview); |
| 581 } |
| 582 |
| 583 function testLoadAbortIllegalJavaScriptURL() { |
| 584 var webview = document.createElement('webview'); |
| 585 webview.addEventListener('loadabort', function(e) { |
| 586 embedder.test.assertEq('ERR_ABORTED', e.reason); |
| 587 embedder.test.succeed(); |
| 588 }); |
| 589 webview.setAttribute('src', 'javascript:void(document.bgColor="#0000FF")'); |
| 590 document.body.appendChild(webview); |
| 591 } |
| 592 |
| 593 // Verifies that navigating to invalid URL (e.g. 'http:') doesn't cause a crash. |
| 594 function testLoadAbortInvalidNavigation() { |
| 595 var webview = document.createElement('webview'); |
| 596 var validSchemeWithEmptyURL = 'http:'; |
| 597 webview.addEventListener('loadabort', function(e) { |
| 598 embedder.test.assertEq('ERR_ABORTED', e.reason); |
| 599 embedder.test.assertEq('', e.url); |
| 600 embedder.test.succeed(); |
| 601 }); |
| 602 webview.addEventListener('exit', function(e) { |
| 603 // We should not crash. |
| 604 embedder.test.fail(); |
| 605 }); |
| 606 webview.setAttribute('src', validSchemeWithEmptyURL); |
| 607 document.body.appendChild(webview); |
| 608 } |
| 609 |
| 610 // Verifies that navigation to a URL that is valid but not web-safe or |
| 611 // pseudo-scheme fires loadabort and doesn't cause a crash. |
| 612 function testLoadAbortNonWebSafeScheme() { |
| 613 var webview = document.createElement('webview'); |
| 614 var chromeGuestURL = 'chrome-guest://abc123'; |
| 615 webview.addEventListener('loadabort', function(e) { |
| 616 embedder.test.assertEq('ERR_ABORTED', e.reason); |
| 617 embedder.test.assertEq('chrome-guest://abc123/', e.url); |
| 618 embedder.test.succeed(); |
| 619 }); |
| 620 webview.addEventListener('exit', function(e) { |
| 621 // We should not crash. |
| 622 embedder.test.fail(); |
| 623 }); |
| 624 webview.setAttribute('src', chromeGuestURL); |
| 625 document.body.appendChild(webview); |
| 626 }; |
| 627 |
| 628 // Tests that the 'loadprogress' event is triggered correctly. |
| 629 function testLoadProgressEvent() { |
| 630 var webview = document.createElement('webview'); |
| 631 var progress = 0; |
| 632 |
| 633 webview.addEventListener('loadstop', function(evt) { |
| 634 embedder.test.assertEq(1, progress); |
| 635 embedder.test.succeed(); |
| 636 }); |
| 637 |
| 638 webview.addEventListener('loadprogress', function(evt) { |
| 639 progress = evt.progress; |
| 640 }); |
| 641 |
| 642 webview.setAttribute('src', 'data:text/html,trigger navigation'); |
| 643 document.body.appendChild(webview); |
| 644 } |
540 | 645 |
541 | 646 |
542 // Tests end. | 647 // Tests end. |
543 | 648 |
544 embedder.test.testList = { | 649 embedder.test.testList = { |
545 'testAllowTransparencyAttribute': testAllowTransparencyAttribute, | 650 'testAllowTransparencyAttribute': testAllowTransparencyAttribute, |
546 'testAPIMethodExistence': testAPIMethodExistence, | 651 'testAPIMethodExistence': testAPIMethodExistence, |
547 'testAssignSrcAfterCrash': testAssignSrcAfterCrash, | 652 'testAssignSrcAfterCrash': testAssignSrcAfterCrash, |
548 'testAutosizeAfterNavigation': testAutosizeAfterNavigation, | 653 'testAutosizeAfterNavigation': testAutosizeAfterNavigation, |
549 'testAutosizeBeforeNavigation': testAutosizeBeforeNavigation, | 654 'testAutosizeBeforeNavigation': testAutosizeBeforeNavigation, |
550 'testAutosizeHeight': testAutosizeHeight, | 655 'testAutosizeHeight': testAutosizeHeight, |
551 'testAutosizeRemoveAttributes': testAutosizeRemoveAttributes, | 656 'testAutosizeRemoveAttributes': testAutosizeRemoveAttributes, |
552 'testAutosizeWithPartialAttributes': testAutosizeWithPartialAttributes, | 657 'testAutosizeWithPartialAttributes': testAutosizeWithPartialAttributes, |
553 'testCannotMutateEventName': testCannotMutateEventName, | 658 'testCannotMutateEventName': testCannotMutateEventName, |
554 'testContentLoadEvent': testContentLoadEvent, | 659 'testContentLoadEvent': testContentLoadEvent, |
555 'testDestroyOnEventListener': testDestroyOnEventListener, | 660 'testDestroyOnEventListener': testDestroyOnEventListener, |
556 'testDisplayNoneWebviewLoad': testDisplayNoneWebviewLoad, | 661 'testDisplayNoneWebviewLoad': testDisplayNoneWebviewLoad, |
557 'testDisplayNoneWebviewRemoveChild': testDisplayNoneWebviewRemoveChild, | 662 'testDisplayNoneWebviewRemoveChild': testDisplayNoneWebviewRemoveChild, |
558 'testExecuteScript': testExecuteScript, | 663 'testExecuteScript': testExecuteScript, |
559 'testExecuteScriptFail': testExecuteScriptFail | 664 'testExecuteScriptFail': testExecuteScriptFail, |
| 665 'testLoadAbortChromeExtensionURLWrongPartition': |
| 666 testLoadAbortChromeExtensionURLWrongPartition, |
| 667 'testLoadAbortIllegalChromeURL': testLoadAbortIllegalChromeURL, |
| 668 'testLoadAbortIllegalFileURL': testLoadAbortIllegalFileURL, |
| 669 'testLoadAbortIllegalJavaScriptURL': testLoadAbortIllegalJavaScriptURL, |
| 670 'testLoadAbortInvalidNavigation': testLoadAbortInvalidNavigation, |
| 671 'testLoadAbortNonWebSafeScheme': testLoadAbortNonWebSafeScheme, |
| 672 'testLoadProgressEvent': testLoadProgressEvent |
560 }; | 673 }; |
561 | 674 |
562 onload = function() { | 675 onload = function() { |
563 chrome.test.sendMessage('LAUNCHED'); | 676 chrome.test.sendMessage('LAUNCHED'); |
564 }; | 677 }; |
OLD | NEW |