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 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 webview.addEventListener('contentload', function(e) { | 759 webview.addEventListener('contentload', function(e) { |
760 embedder.test.succeed(); | 760 embedder.test.succeed(); |
761 }); | 761 }); |
762 webview.setAttribute('src', 'data:text/html,trigger navigation'); | 762 webview.setAttribute('src', 'data:text/html,trigger navigation'); |
763 document.body.appendChild(webview); | 763 document.body.appendChild(webview); |
764 } | 764 } |
765 | 765 |
766 // This test verifies that the WebRequest API onBeforeRequest event fires on | 766 // This test verifies that the WebRequest API onBeforeRequest event fires on |
767 // webview. | 767 // webview. |
768 function testWebRequestAPI() { | 768 function testWebRequestAPI() { |
769 var webview = document.createElement('webview'); | 769 var webview = new WebView(); |
770 webview.setAttribute('src', 'data:text/html,trigger navigation'); | 770 webview.request.onBeforeRequest.addListener(function(e) { |
771 var firstLoad = function() { | 771 embedder.test.succeed(); |
772 webview.removeEventListener('loadstop', firstLoad); | 772 }, { urls: ['<all_urls>']}) ; |
773 webview.onBeforeRequest.addListener(function(e) { | 773 webview.src = embedder.windowOpenGuestURL; |
774 embedder.test.succeed(); | |
775 }, { urls: ['<all_urls>']}, ['blocking']) ; | |
776 webview.src = embedder.windowOpenGuestURL; | |
777 }; | |
778 webview.addEventListener('loadstop', firstLoad); | |
779 document.body.appendChild(webview); | 774 document.body.appendChild(webview); |
780 } | 775 } |
781 | 776 |
782 // This test verifies that the WebRequest API onBeforeRequest event fires on | 777 // This test verifies that the WebRequest API onBeforeRequest event fires on |
783 // clients*.google.com URLs. | 778 // clients*.google.com URLs. |
784 function testWebRequestAPIGoogleProperty() { | 779 function testWebRequestAPIGoogleProperty() { |
785 var webview = document.createElement('webview'); | 780 var webview = new WebView(); |
786 webview.setAttribute('src', 'data:text/html,trigger navigation'); | 781 webview.request.onBeforeRequest.addListener(function(e) { |
787 var firstLoad = function() { | 782 embedder.test.succeed(); |
788 webview.removeEventListener('loadstop', firstLoad); | 783 return {cancel: true}; |
789 webview.onBeforeRequest.addListener(function(e) { | 784 }, { urls: ['<all_urls>']}, ['blocking']) ; |
790 embedder.test.succeed(); | 785 webview.src = 'http://clients6.google.com'; |
791 return {cancel: true}; | |
792 }, { urls: ['<all_urls>']}, ['blocking']) ; | |
793 webview.src = 'http://clients6.google.com'; | |
794 }; | |
795 webview.addEventListener('loadstop', firstLoad); | |
796 document.body.appendChild(webview); | 786 document.body.appendChild(webview); |
797 } | 787 } |
798 | 788 |
| 789 // This test verifies that the WebRequest event listener for onBeforeRequest |
| 790 // survives reparenting of the <webview>. |
| 791 function testWebRequestListenerSurvivesReparenting() { |
| 792 var webview = new WebView(); |
| 793 var count = 0; |
| 794 webview.request.onBeforeRequest.addListener(function(e) { |
| 795 if (++count == 2) { |
| 796 embedder.test.succeed(); |
| 797 } |
| 798 }, { urls: ['<all_urls>']}); |
| 799 var onLoadStop = function(e) { |
| 800 webview.removeEventListener('loadstop', onLoadStop); |
| 801 webview.parentNode.removeChild(webview); |
| 802 var container = document.getElementById('object-container'); |
| 803 if (!container) { |
| 804 embedder.test.fail('Container for object not found.'); |
| 805 return; |
| 806 } |
| 807 container.appendChild(webview); |
| 808 }; |
| 809 webview.addEventListener('loadstop', onLoadStop); |
| 810 webview.src = embedder.emptyGuestURL; |
| 811 document.body.appendChild(webview); |
| 812 } |
| 813 |
799 // This test verifies that getProcessId is defined and returns a non-zero | 814 // This test verifies that getProcessId is defined and returns a non-zero |
800 // value corresponding to the processId of the guest process. | 815 // value corresponding to the processId of the guest process. |
801 function testGetProcessId() { | 816 function testGetProcessId() { |
802 var webview = document.createElement('webview'); | 817 var webview = document.createElement('webview'); |
803 webview.setAttribute('src', 'data:text/html,trigger navigation'); | 818 webview.setAttribute('src', 'data:text/html,trigger navigation'); |
804 var firstLoad = function() { | 819 var firstLoad = function() { |
805 webview.removeEventListener('loadstop', firstLoad); | 820 webview.removeEventListener('loadstop', firstLoad); |
806 embedder.test.assertTrue(webview.getProcessId() > 0); | 821 embedder.test.assertTrue(webview.getProcessId() > 0); |
807 embedder.test.succeed(); | 822 embedder.test.succeed(); |
808 }; | 823 }; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 'testReassignSrcAttribute': testReassignSrcAttribute, | 1030 'testReassignSrcAttribute': testReassignSrcAttribute, |
1016 'testRemoveSrcAttribute': testRemoveSrcAttribute, | 1031 'testRemoveSrcAttribute': testRemoveSrcAttribute, |
1017 'testBrowserPluginNotAllowed': testBrowserPluginNotAllowed, | 1032 'testBrowserPluginNotAllowed': testBrowserPluginNotAllowed, |
1018 'testNewWindow': testNewWindow, | 1033 'testNewWindow': testNewWindow, |
1019 'testNewWindowTwoListeners': testNewWindowTwoListeners, | 1034 'testNewWindowTwoListeners': testNewWindowTwoListeners, |
1020 'testNewWindowNoPreventDefault': testNewWindowNoPreventDefault, | 1035 'testNewWindowNoPreventDefault': testNewWindowNoPreventDefault, |
1021 'testNewWindowNoReferrerLink': testNewWindowNoReferrerLink, | 1036 'testNewWindowNoReferrerLink': testNewWindowNoReferrerLink, |
1022 'testContentLoadEvent': testContentLoadEvent, | 1037 'testContentLoadEvent': testContentLoadEvent, |
1023 'testWebRequestAPI': testWebRequestAPI, | 1038 'testWebRequestAPI': testWebRequestAPI, |
1024 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty, | 1039 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty, |
| 1040 'testWebRequestListenerSurvivesReparenting': |
| 1041 testWebRequestListenerSurvivesReparenting, |
1025 'testGetProcessId': testGetProcessId, | 1042 'testGetProcessId': testGetProcessId, |
1026 'testLoadStartLoadRedirect': testLoadStartLoadRedirect, | 1043 'testLoadStartLoadRedirect': testLoadStartLoadRedirect, |
1027 'testLoadAbortEmptyResponse': testLoadAbortEmptyResponse, | 1044 'testLoadAbortEmptyResponse': testLoadAbortEmptyResponse, |
1028 'testLoadAbortIllegalChromeURL': testLoadAbortIllegalChromeURL, | 1045 'testLoadAbortIllegalChromeURL': testLoadAbortIllegalChromeURL, |
1029 'testLoadAbortIllegalFileURL': testLoadAbortIllegalFileURL, | 1046 'testLoadAbortIllegalFileURL': testLoadAbortIllegalFileURL, |
1030 'testNavigationToExternalProtocol': testNavigationToExternalProtocol, | 1047 'testNavigationToExternalProtocol': testNavigationToExternalProtocol, |
1031 'testReload': testReload, | 1048 'testReload': testReload, |
1032 'testRemoveWebviewOnExit': testRemoveWebviewOnExit, | 1049 'testRemoveWebviewOnExit': testRemoveWebviewOnExit, |
1033 'testRemoveWebviewAfterNavigation': testRemoveWebviewAfterNavigation, | 1050 'testRemoveWebviewAfterNavigation': testRemoveWebviewAfterNavigation, |
1034 'testResizeWebviewResizesContent': testResizeWebviewResizesContent | 1051 'testResizeWebviewResizesContent': testResizeWebviewResizesContent |
1035 }; | 1052 }; |
1036 | 1053 |
1037 onload = function() { | 1054 onload = function() { |
1038 chrome.test.getConfig(function(config) { | 1055 chrome.test.getConfig(function(config) { |
1039 embedder.setUp_(config); | 1056 embedder.setUp_(config); |
1040 chrome.test.sendMessage("Launched"); | 1057 chrome.test.sendMessage("Launched"); |
1041 }); | 1058 }); |
1042 }; | 1059 }; |
OLD | NEW |