Index: chrome/test/data/extensions/platform_apps/web_view/shim/main.js |
diff --git a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js |
index 4156ce82f2d45a367ece77faa6ab2454fc8df81e..c9e772450296b4d7d75dfe3751cf4b60916fa470 100644 |
--- a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js |
+++ b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js |
@@ -766,33 +766,48 @@ function testContentLoadEvent() { |
// This test verifies that the WebRequest API onBeforeRequest event fires on |
// webview. |
function testWebRequestAPI() { |
- var webview = document.createElement('webview'); |
- webview.setAttribute('src', 'data:text/html,trigger navigation'); |
- var firstLoad = function() { |
- webview.removeEventListener('loadstop', firstLoad); |
- webview.onBeforeRequest.addListener(function(e) { |
- embedder.test.succeed(); |
- }, { urls: ['<all_urls>']}, ['blocking']) ; |
- webview.src = embedder.windowOpenGuestURL; |
- }; |
- webview.addEventListener('loadstop', firstLoad); |
+ var webview = new WebView(); |
+ webview.request.onBeforeRequest.addListener(function(e) { |
+ embedder.test.succeed(); |
+ }, { urls: ['<all_urls>']}) ; |
+ webview.src = embedder.windowOpenGuestURL; |
document.body.appendChild(webview); |
} |
// This test verifies that the WebRequest API onBeforeRequest event fires on |
// clients*.google.com URLs. |
function testWebRequestAPIGoogleProperty() { |
- var webview = document.createElement('webview'); |
- webview.setAttribute('src', 'data:text/html,trigger navigation'); |
- var firstLoad = function() { |
- webview.removeEventListener('loadstop', firstLoad); |
- webview.onBeforeRequest.addListener(function(e) { |
+ var webview = new WebView(); |
+ webview.request.onBeforeRequest.addListener(function(e) { |
+ embedder.test.succeed(); |
+ return {cancel: true}; |
+ }, { urls: ['<all_urls>']}, ['blocking']) ; |
+ webview.src = 'http://clients6.google.com'; |
+ document.body.appendChild(webview); |
+} |
+ |
+// This test verifies that the WebRequest event listener for onBeforeRequest |
+// survives reparenting of the <webview>. |
+function testWebRequestListenerSurvivesReparenting() { |
+ var webview = new WebView(); |
+ var count = 0; |
+ webview.request.onBeforeRequest.addListener(function(e) { |
+ if (++count == 2) { |
embedder.test.succeed(); |
- return {cancel: true}; |
- }, { urls: ['<all_urls>']}, ['blocking']) ; |
- webview.src = 'http://clients6.google.com'; |
+ } |
+ }, { urls: ['<all_urls>']}); |
+ var onLoadStop = function(e) { |
+ webview.removeEventListener('loadstop', onLoadStop); |
+ webview.parentNode.removeChild(webview); |
+ var container = document.getElementById('object-container'); |
+ if (!container) { |
+ embedder.test.fail('Container for object not found.'); |
+ return; |
+ } |
+ container.appendChild(webview); |
}; |
- webview.addEventListener('loadstop', firstLoad); |
+ webview.addEventListener('loadstop', onLoadStop); |
+ webview.src = embedder.emptyGuestURL; |
document.body.appendChild(webview); |
} |
@@ -1022,6 +1037,8 @@ embedder.test.testList = { |
'testContentLoadEvent': testContentLoadEvent, |
'testWebRequestAPI': testWebRequestAPI, |
'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty, |
+ 'testWebRequestListenerSurvivesReparenting': |
+ testWebRequestListenerSurvivesReparenting, |
'testGetProcessId': testGetProcessId, |
'testLoadStartLoadRedirect': testLoadStartLoadRedirect, |
'testLoadAbortEmptyResponse': testLoadAbortEmptyResponse, |