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