| 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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 webview.partition = 'foobar'; | 346 webview.partition = 'foobar'; |
| 347 webview.addEventListener('loadabort', function(e) { | 347 webview.addEventListener('loadabort', function(e) { |
| 348 embedder.test.succeed(); | 348 embedder.test.succeed(); |
| 349 }); | 349 }); |
| 350 webview.setAttribute('src', invalidResource); | 350 webview.setAttribute('src', invalidResource); |
| 351 document.body.appendChild(webview); | 351 document.body.appendChild(webview); |
| 352 } | 352 } |
| 353 | 353 |
| 354 function testWebRequestAPIExistence() { | 354 function testWebRequestAPIExistence() { |
| 355 var apiPropertiesToCheck = [ | 355 var apiPropertiesToCheck = [ |
| 356 // Declarative WebRequest API. |
| 357 'onMessage', |
| 358 'onRequest', |
| 359 // WebRequest API. |
| 356 'onBeforeRequest', | 360 'onBeforeRequest', |
| 357 'onBeforeSendHeaders', | 361 'onBeforeSendHeaders', |
| 358 'onSendHeaders', | 362 'onSendHeaders', |
| 359 'onHeadersReceived', | 363 'onHeadersReceived', |
| 360 'onAuthRequired', | 364 'onAuthRequired', |
| 361 'onBeforeRedirect', | 365 'onBeforeRedirect', |
| 362 'onResponseStarted', | 366 'onResponseStarted', |
| 363 'onCompleted', | 367 'onCompleted', |
| 364 'onErrorOccurred' | 368 'onErrorOccurred' |
| 365 ]; | 369 ]; |
| 366 var webview = document.createElement('webview'); | 370 var webview = document.createElement('webview'); |
| 367 webview.setAttribute('partition', arguments.callee.name); | 371 webview.setAttribute('partition', arguments.callee.name); |
| 368 webview.addEventListener('loadstop', function(e) { | 372 webview.addEventListener('loadstop', function(e) { |
| 369 for (var i = 0; i < apiPropertiesToCheck.length; ++i) { | 373 for (var i = 0; i < apiPropertiesToCheck.length; ++i) { |
| 370 embedder.test.assertEq('object', | 374 embedder.test.assertEq('object', |
| 371 typeof webview[apiPropertiesToCheck[i]]); | 375 typeof webview.request[apiPropertiesToCheck[i]]); |
| 372 embedder.test.assertEq( | 376 embedder.test.assertEq( |
| 373 'function', typeof webview[apiPropertiesToCheck[i]].addListener); | 377 'function', |
| 374 embedder.test.assertEq(webview[apiPropertiesToCheck[i]], | 378 typeof webview.request[apiPropertiesToCheck[i]].addListener); |
| 375 webview.request[apiPropertiesToCheck[i]]); | 379 embedder.test.assertEq( |
| 380 'function', |
| 381 typeof webview.request[apiPropertiesToCheck[i]].addRules); |
| 382 embedder.test.assertEq( |
| 383 'function', |
| 384 typeof webview.request[apiPropertiesToCheck[i]].getRules); |
| 385 embedder.test.assertEq( |
| 386 'function', |
| 387 typeof webview.request[apiPropertiesToCheck[i]].removeRules); |
| 376 } | 388 } |
| 377 | |
| 378 embedder.test.succeed(); | 389 embedder.test.succeed(); |
| 379 }); | 390 }); |
| 380 webview.setAttribute('src', 'data:text/html,webview check api'); | 391 webview.setAttribute('src', 'data:text/html,webview check api'); |
| 381 document.body.appendChild(webview); | 392 document.body.appendChild(webview); |
| 382 } | 393 } |
| 383 | 394 |
| 384 // This test verifies that the loadstart, loadstop, and exit events fire as | 395 // This test verifies that the loadstart, loadstop, and exit events fire as |
| 385 // expected. | 396 // expected. |
| 386 function testEventName() { | 397 function testEventName() { |
| 387 var webview = document.createElement('webview'); | 398 var webview = document.createElement('webview'); |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 // webview. | 886 // webview. |
| 876 function testWebRequestAPI() { | 887 function testWebRequestAPI() { |
| 877 var webview = new WebView(); | 888 var webview = new WebView(); |
| 878 webview.request.onBeforeRequest.addListener(function(e) { | 889 webview.request.onBeforeRequest.addListener(function(e) { |
| 879 embedder.test.succeed(); | 890 embedder.test.succeed(); |
| 880 }, { urls: ['<all_urls>']}) ; | 891 }, { urls: ['<all_urls>']}) ; |
| 881 webview.src = embedder.windowOpenGuestURL; | 892 webview.src = embedder.windowOpenGuestURL; |
| 882 document.body.appendChild(webview); | 893 document.body.appendChild(webview); |
| 883 } | 894 } |
| 884 | 895 |
| 896 // This test verifies that the basic use cases of the declarative WebRequest API |
| 897 // work as expected. This test demonstrates that rules can be added prior to |
| 898 // navigation and attachment. |
| 899 // 1. It adds a rule to block URLs that contain guest. |
| 900 // 2. It attempts to navigate to a guest.html page. |
| 901 // 3. It detects the appropriate loadabort message. |
| 902 // 4. It removes the rule blocking the page and reloads. |
| 903 // 5. The page loads successfully. |
| 904 function testDeclarativeWebRequestAPI() { |
| 905 var step = 1; |
| 906 var webview = new WebView(); |
| 907 var rule = { |
| 908 conditions: [ |
| 909 new chrome.webViewRequest.RequestMatcher( |
| 910 { |
| 911 url: { urlContains: 'guest' } |
| 912 } |
| 913 ) |
| 914 ], |
| 915 actions: [ |
| 916 new chrome.webViewRequest.CancelRequest() |
| 917 ] |
| 918 }; |
| 919 webview.request.onRequest.addRules([rule]); |
| 920 webview.addEventListener('loadabort', function(e) { |
| 921 embedder.test.assertEq(1, step); |
| 922 embedder.test.assertEq('ERR_BLOCKED_BY_CLIENT', e.reason); |
| 923 step = 2; |
| 924 webview.request.onRequest.removeRules(); |
| 925 webview.reload(); |
| 926 }); |
| 927 webview.addEventListener('loadcommit', function(e) { |
| 928 embedder.test.assertEq(2, step); |
| 929 embedder.test.succeed(); |
| 930 }); |
| 931 webview.src = embedder.emptyGuestURL; |
| 932 document.body.appendChild(webview); |
| 933 } |
| 934 |
| 885 // This test verifies that the WebRequest API onBeforeRequest event fires on | 935 // This test verifies that the WebRequest API onBeforeRequest event fires on |
| 886 // clients*.google.com URLs. | 936 // clients*.google.com URLs. |
| 887 function testWebRequestAPIGoogleProperty() { | 937 function testWebRequestAPIGoogleProperty() { |
| 888 var webview = new WebView(); | 938 var webview = new WebView(); |
| 889 webview.request.onBeforeRequest.addListener(function(e) { | 939 webview.request.onBeforeRequest.addListener(function(e) { |
| 890 embedder.test.succeed(); | 940 embedder.test.succeed(); |
| 891 return {cancel: true}; | 941 return {cancel: true}; |
| 892 }, { urls: ['<all_urls>']}, ['blocking']) ; | 942 }, { urls: ['<all_urls>']}, ['blocking']) ; |
| 893 webview.src = 'http://clients6.google.com'; | 943 webview.src = 'http://clients6.google.com'; |
| 894 document.body.appendChild(webview); | 944 document.body.appendChild(webview); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 'testNavOnSrcAttributeChange': testNavOnSrcAttributeChange, | 1217 'testNavOnSrcAttributeChange': testNavOnSrcAttributeChange, |
| 1168 'testReassignSrcAttribute': testReassignSrcAttribute, | 1218 'testReassignSrcAttribute': testReassignSrcAttribute, |
| 1169 'testRemoveSrcAttribute': testRemoveSrcAttribute, | 1219 'testRemoveSrcAttribute': testRemoveSrcAttribute, |
| 1170 'testBrowserPluginNotAllowed': testBrowserPluginNotAllowed, | 1220 'testBrowserPluginNotAllowed': testBrowserPluginNotAllowed, |
| 1171 'testPluginLoadPermission': testPluginLoadPermission, | 1221 'testPluginLoadPermission': testPluginLoadPermission, |
| 1172 'testNewWindow': testNewWindow, | 1222 'testNewWindow': testNewWindow, |
| 1173 'testNewWindowTwoListeners': testNewWindowTwoListeners, | 1223 'testNewWindowTwoListeners': testNewWindowTwoListeners, |
| 1174 'testNewWindowNoPreventDefault': testNewWindowNoPreventDefault, | 1224 'testNewWindowNoPreventDefault': testNewWindowNoPreventDefault, |
| 1175 'testNewWindowNoReferrerLink': testNewWindowNoReferrerLink, | 1225 'testNewWindowNoReferrerLink': testNewWindowNoReferrerLink, |
| 1176 'testContentLoadEvent': testContentLoadEvent, | 1226 'testContentLoadEvent': testContentLoadEvent, |
| 1227 'testDeclarativeWebRequestAPI': testDeclarativeWebRequestAPI, |
| 1177 'testWebRequestAPI': testWebRequestAPI, | 1228 'testWebRequestAPI': testWebRequestAPI, |
| 1178 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty, | 1229 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty, |
| 1179 'testWebRequestListenerSurvivesReparenting': | 1230 'testWebRequestListenerSurvivesReparenting': |
| 1180 testWebRequestListenerSurvivesReparenting, | 1231 testWebRequestListenerSurvivesReparenting, |
| 1181 'testGetProcessId': testGetProcessId, | 1232 'testGetProcessId': testGetProcessId, |
| 1182 'testLoadStartLoadRedirect': testLoadStartLoadRedirect, | 1233 'testLoadStartLoadRedirect': testLoadStartLoadRedirect, |
| 1183 'testLoadAbortChromeExtensionURLWrongPartition': | 1234 'testLoadAbortChromeExtensionURLWrongPartition': |
| 1184 testLoadAbortChromeExtensionURLWrongPartition, | 1235 testLoadAbortChromeExtensionURLWrongPartition, |
| 1185 'testLoadAbortEmptyResponse': testLoadAbortEmptyResponse, | 1236 'testLoadAbortEmptyResponse': testLoadAbortEmptyResponse, |
| 1186 'testLoadAbortIllegalChromeURL': testLoadAbortIllegalChromeURL, | 1237 'testLoadAbortIllegalChromeURL': testLoadAbortIllegalChromeURL, |
| 1187 'testLoadAbortIllegalFileURL': testLoadAbortIllegalFileURL, | 1238 'testLoadAbortIllegalFileURL': testLoadAbortIllegalFileURL, |
| 1188 'testLoadAbortIllegalJavaScriptURL': testLoadAbortIllegalJavaScriptURL, | 1239 'testLoadAbortIllegalJavaScriptURL': testLoadAbortIllegalJavaScriptURL, |
| 1189 'testNavigationToExternalProtocol': testNavigationToExternalProtocol, | 1240 'testNavigationToExternalProtocol': testNavigationToExternalProtocol, |
| 1190 'testReload': testReload, | 1241 'testReload': testReload, |
| 1191 'testRemoveWebviewOnExit': testRemoveWebviewOnExit, | 1242 'testRemoveWebviewOnExit': testRemoveWebviewOnExit, |
| 1192 'testRemoveWebviewAfterNavigation': testRemoveWebviewAfterNavigation, | 1243 'testRemoveWebviewAfterNavigation': testRemoveWebviewAfterNavigation, |
| 1193 'testResizeWebviewResizesContent': testResizeWebviewResizesContent | 1244 'testResizeWebviewResizesContent': testResizeWebviewResizesContent |
| 1194 }; | 1245 }; |
| 1195 | 1246 |
| 1196 onload = function() { | 1247 onload = function() { |
| 1197 chrome.test.getConfig(function(config) { | 1248 chrome.test.getConfig(function(config) { |
| 1198 embedder.setUp_(config); | 1249 embedder.setUp_(config); |
| 1199 chrome.test.sendMessage("Launched"); | 1250 chrome.test.sendMessage("Launched"); |
| 1200 }); | 1251 }); |
| 1201 }; | 1252 }; |
| OLD | NEW |