Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(972)

Side by Side Diff: chrome/test/data/extensions/platform_apps/web_view/shim/main.js

Issue 23514016: <webview>: Cleanup WebRequest event listeners when embedder destroyed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More fixes Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 webview.addEventListener('contentload', function(e) { 751 webview.addEventListener('contentload', function(e) {
752 embedder.test.succeed(); 752 embedder.test.succeed();
753 }); 753 });
754 webview.setAttribute('src', 'data:text/html,trigger navigation'); 754 webview.setAttribute('src', 'data:text/html,trigger navigation');
755 document.body.appendChild(webview); 755 document.body.appendChild(webview);
756 } 756 }
757 757
758 // This test verifies that the WebRequest API onBeforeRequest event fires on 758 // This test verifies that the WebRequest API onBeforeRequest event fires on
759 // webview. 759 // webview.
760 function testWebRequestAPI() { 760 function testWebRequestAPI() {
761 var webview = document.createElement('webview'); 761 var webview = new WebView();
762 webview.setAttribute('src', 'data:text/html,trigger navigation'); 762 webview.request.onBeforeRequest.addListener(function(e) {
763 var firstLoad = function() { 763 embedder.test.succeed();
764 webview.removeEventListener('loadstop', firstLoad); 764 }, { urls: ['<all_urls>']}) ;
765 webview.onBeforeRequest.addListener(function(e) { 765 webview.src = embedder.windowOpenGuestURL;
766 embedder.test.succeed();
767 }, { urls: ['<all_urls>']}, ['blocking']) ;
768 webview.src = embedder.windowOpenGuestURL;
769 };
770 webview.addEventListener('loadstop', firstLoad);
771 document.body.appendChild(webview); 766 document.body.appendChild(webview);
772 } 767 }
773 768
774 // This test verifies that the WebRequest API onBeforeRequest event fires on 769 // This test verifies that the WebRequest API onBeforeRequest event fires on
775 // clients*.google.com URLs. 770 // clients*.google.com URLs.
776 function testWebRequestAPIGoogleProperty() { 771 function testWebRequestAPIGoogleProperty() {
777 var webview = document.createElement('webview'); 772 var webview = new WebView();
778 webview.setAttribute('src', 'data:text/html,trigger navigation'); 773 webview.request.onBeforeRequest.addListener(function(e) {
779 var firstLoad = function() { 774 embedder.test.succeed();
780 webview.removeEventListener('loadstop', firstLoad); 775 return {cancel: true};
781 webview.onBeforeRequest.addListener(function(e) { 776 }, { urls: ['<all_urls>']}, ['blocking']) ;
782 embedder.test.succeed(); 777 webview.src = 'http://clients6.google.com';
783 return {cancel: true};
784 }, { urls: ['<all_urls>']}, ['blocking']) ;
785 webview.src = 'http://clients6.google.com';
786 };
787 webview.addEventListener('loadstop', firstLoad);
788 document.body.appendChild(webview); 778 document.body.appendChild(webview);
789 } 779 }
790 780
781 // This test verifies that the WebRequest event listener for onBeforeRequest
782 // survives reparenting of the <webview>.
783 function testWebRequestListenerSurvivesReparenting() {
784 var webview = new WebView();
785 var count = 0;
786 webview.request.onBeforeRequest.addListener(function(e) {
787 if (++count == 2) {
788 embedder.test.succeed();
789 }
790 }, { urls: ['<all_urls>']});
791 var onLoadStop = function(e) {
792 webview.removeEventListener('loadstop', onLoadStop);
793 webview.parentNode.removeChild(webview);
794 var container = document.getElementById('object-container');
795 if (!container) {
796 embedder.test.fail('Container for object not found.');
797 return;
798 }
799 container.appendChild(webview);
800 };
801 webview.addEventListener('loadstop', onLoadStop);
802 webview.src = embedder.emptyGuestURL;
803 document.body.appendChild(webview);
804 }
805
791 // This test verifies that getProcessId is defined and returns a non-zero 806 // This test verifies that getProcessId is defined and returns a non-zero
792 // value corresponding to the processId of the guest process. 807 // value corresponding to the processId of the guest process.
793 function testGetProcessId() { 808 function testGetProcessId() {
794 var webview = document.createElement('webview'); 809 var webview = document.createElement('webview');
795 webview.setAttribute('src', 'data:text/html,trigger navigation'); 810 webview.setAttribute('src', 'data:text/html,trigger navigation');
796 var firstLoad = function() { 811 var firstLoad = function() {
797 webview.removeEventListener('loadstop', firstLoad); 812 webview.removeEventListener('loadstop', firstLoad);
798 embedder.test.assertTrue(webview.getProcessId() > 0); 813 embedder.test.assertTrue(webview.getProcessId() > 0);
799 embedder.test.succeed(); 814 embedder.test.succeed();
800 }; 815 };
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 'testReassignSrcAttribute': testReassignSrcAttribute, 1021 'testReassignSrcAttribute': testReassignSrcAttribute,
1007 'testRemoveSrcAttribute': testRemoveSrcAttribute, 1022 'testRemoveSrcAttribute': testRemoveSrcAttribute,
1008 'testBrowserPluginNotAllowed': testBrowserPluginNotAllowed, 1023 'testBrowserPluginNotAllowed': testBrowserPluginNotAllowed,
1009 'testNewWindow': testNewWindow, 1024 'testNewWindow': testNewWindow,
1010 'testNewWindowTwoListeners': testNewWindowTwoListeners, 1025 'testNewWindowTwoListeners': testNewWindowTwoListeners,
1011 'testNewWindowNoPreventDefault': testNewWindowNoPreventDefault, 1026 'testNewWindowNoPreventDefault': testNewWindowNoPreventDefault,
1012 'testNewWindowNoReferrerLink': testNewWindowNoReferrerLink, 1027 'testNewWindowNoReferrerLink': testNewWindowNoReferrerLink,
1013 'testContentLoadEvent': testContentLoadEvent, 1028 'testContentLoadEvent': testContentLoadEvent,
1014 'testWebRequestAPI': testWebRequestAPI, 1029 'testWebRequestAPI': testWebRequestAPI,
1015 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty, 1030 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty,
1031 'testWebRequestListenerSurvivesReparenting':
1032 testWebRequestListenerSurvivesReparenting,
1016 'testGetProcessId': testGetProcessId, 1033 'testGetProcessId': testGetProcessId,
1017 'testLoadStartLoadRedirect': testLoadStartLoadRedirect, 1034 'testLoadStartLoadRedirect': testLoadStartLoadRedirect,
1018 'testLoadAbortEmptyResponse': testLoadAbortEmptyResponse, 1035 'testLoadAbortEmptyResponse': testLoadAbortEmptyResponse,
1019 'testLoadAbortIllegalChromeURL': testLoadAbortIllegalChromeURL, 1036 'testLoadAbortIllegalChromeURL': testLoadAbortIllegalChromeURL,
1020 'testLoadAbortIllegalFileURL': testLoadAbortIllegalFileURL, 1037 'testLoadAbortIllegalFileURL': testLoadAbortIllegalFileURL,
1021 'testNavigationToExternalProtocol': testNavigationToExternalProtocol, 1038 'testNavigationToExternalProtocol': testNavigationToExternalProtocol,
1022 'testReload': testReload, 1039 'testReload': testReload,
1023 'testRemoveWebviewOnExit': testRemoveWebviewOnExit, 1040 'testRemoveWebviewOnExit': testRemoveWebviewOnExit,
1024 'testRemoveWebviewAfterNavigation': testRemoveWebviewAfterNavigation, 1041 'testRemoveWebviewAfterNavigation': testRemoveWebviewAfterNavigation,
1025 'testResizeWebviewResizesContent': testResizeWebviewResizesContent 1042 'testResizeWebviewResizesContent': testResizeWebviewResizesContent
1026 }; 1043 };
1027 1044
1028 onload = function() { 1045 onload = function() {
1029 chrome.test.getConfig(function(config) { 1046 chrome.test.getConfig(function(config) {
1030 embedder.setUp_(config); 1047 embedder.setUp_(config);
1031 chrome.test.sendMessage("Launched"); 1048 chrome.test.sendMessage("Launched");
1032 }); 1049 });
1033 }; 1050 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698