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

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

Issue 28273006: <webview>: Implement declarativeWebRequest API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added tests Created 7 years, 1 month 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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 webview.partition = 'foobar'; 326 webview.partition = 'foobar';
327 webview.addEventListener('loadabort', function(e) { 327 webview.addEventListener('loadabort', function(e) {
328 embedder.test.succeed(); 328 embedder.test.succeed();
329 }); 329 });
330 webview.setAttribute('src', invalidResource); 330 webview.setAttribute('src', invalidResource);
331 document.body.appendChild(webview); 331 document.body.appendChild(webview);
332 } 332 }
333 333
334 function testWebRequestAPIExistence() { 334 function testWebRequestAPIExistence() {
335 var apiPropertiesToCheck = [ 335 var apiPropertiesToCheck = [
336 // Declarative WebRequest API.
337 'onMessage',
338 'onRequest',
339 // WebRequest API.
336 'onBeforeRequest', 340 'onBeforeRequest',
337 'onBeforeSendHeaders', 341 'onBeforeSendHeaders',
338 'onSendHeaders', 342 'onSendHeaders',
339 'onHeadersReceived', 343 'onHeadersReceived',
340 'onAuthRequired', 344 'onAuthRequired',
341 'onBeforeRedirect', 345 'onBeforeRedirect',
342 'onResponseStarted', 346 'onResponseStarted',
343 'onCompleted', 347 'onCompleted',
344 'onErrorOccurred' 348 'onErrorOccurred'
345 ]; 349 ];
346 var webview = document.createElement('webview'); 350 var webview = document.createElement('webview');
347 webview.setAttribute('partition', arguments.callee.name); 351 webview.setAttribute('partition', arguments.callee.name);
348 webview.addEventListener('loadstop', function(e) { 352 webview.addEventListener('loadstop', function(e) {
349 for (var i = 0; i < apiPropertiesToCheck.length; ++i) { 353 for (var i = 0; i < apiPropertiesToCheck.length; ++i) {
350 embedder.test.assertEq('object', 354 embedder.test.assertEq('object',
351 typeof webview[apiPropertiesToCheck[i]]); 355 typeof webview.request[apiPropertiesToCheck[i]]);
352 embedder.test.assertEq( 356 embedder.test.assertEq(
353 'function', typeof webview[apiPropertiesToCheck[i]].addListener); 357 'function',
354 embedder.test.assertEq(webview[apiPropertiesToCheck[i]], 358 typeof webview.request[apiPropertiesToCheck[i]].addListener);
355 webview.request[apiPropertiesToCheck[i]]); 359 embedder.test.assertEq(
360 'function',
361 typeof webview.request[apiPropertiesToCheck[i]].addRules);
362 embedder.test.assertEq(
363 'function',
364 typeof webview.request[apiPropertiesToCheck[i]].getRules);
365 embedder.test.assertEq(
366 'function',
367 typeof webview.request[apiPropertiesToCheck[i]].removeRules);
356 } 368 }
357
358 embedder.test.succeed(); 369 embedder.test.succeed();
359 }); 370 });
360 webview.setAttribute('src', 'data:text/html,webview check api'); 371 webview.setAttribute('src', 'data:text/html,webview check api');
361 document.body.appendChild(webview); 372 document.body.appendChild(webview);
362 } 373 }
363 374
364 // This test verifies that the loadstart, loadstop, and exit events fire as 375 // This test verifies that the loadstart, loadstop, and exit events fire as
365 // expected. 376 // expected.
366 function testEventName() { 377 function testEventName() {
367 var webview = document.createElement('webview'); 378 var webview = document.createElement('webview');
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 // webview. 866 // webview.
856 function testWebRequestAPI() { 867 function testWebRequestAPI() {
857 var webview = new WebView(); 868 var webview = new WebView();
858 webview.request.onBeforeRequest.addListener(function(e) { 869 webview.request.onBeforeRequest.addListener(function(e) {
859 embedder.test.succeed(); 870 embedder.test.succeed();
860 }, { urls: ['<all_urls>']}) ; 871 }, { urls: ['<all_urls>']}) ;
861 webview.src = embedder.windowOpenGuestURL; 872 webview.src = embedder.windowOpenGuestURL;
862 document.body.appendChild(webview); 873 document.body.appendChild(webview);
863 } 874 }
864 875
876 // This test verifies that the basic use cases of the declarative WebRequest API
877 // work as expected. This test demonstrates that rules can be added prior to
878 // navigation and attachment.
879 // 1. It adds a rule to block URLs that contain guest.
880 // 2. It attempts to navigate to a guest.html page.
881 // 3. It detects the appropriate loadabort message.
882 // 4. It removes the rule blocking the page and reloads.
883 // 5. The page loads successfully.
884 function testDeclarativeWebRequestAPI() {
885 var step = 1;
886 var webview = new WebView();
887 var rule = {
888 conditions: [
889 new chrome.webViewRequest.RequestMatcher(
890 {
891 url: { urlContains: 'guest' }
892 }
893 )
894 ],
895 actions: [
896 new chrome.webViewRequest.CancelRequest()
897 ]
898 };
899 webview.request.onRequest.addRules([rule]);
900 webview.addEventListener('loadstop', function(e) {
901 embedder.test.assertEq(2, step);
902 embedder.test.succeed();
903 });
904 webview.addEventListener('loadabort', function(e) {
905 embedder.test.assertEq(1, step);
906 embedder.test.assertEq('ERR_BLOCKED_BY_CLIENT', e.reason);
907 step = 2;
908 webview.request.onRequest.removeRules();
909 });
910 webview.src = embedder.windowOpenGuestURL;
911 document.body.appendChild(webview);
912 }
913
865 // This test verifies that the WebRequest API onBeforeRequest event fires on 914 // This test verifies that the WebRequest API onBeforeRequest event fires on
866 // clients*.google.com URLs. 915 // clients*.google.com URLs.
867 function testWebRequestAPIGoogleProperty() { 916 function testWebRequestAPIGoogleProperty() {
868 var webview = new WebView(); 917 var webview = new WebView();
869 webview.request.onBeforeRequest.addListener(function(e) { 918 webview.request.onBeforeRequest.addListener(function(e) {
870 embedder.test.succeed(); 919 embedder.test.succeed();
871 return {cancel: true}; 920 return {cancel: true};
872 }, { urls: ['<all_urls>']}, ['blocking']) ; 921 }, { urls: ['<all_urls>']}, ['blocking']) ;
873 webview.src = 'http://clients6.google.com'; 922 webview.src = 'http://clients6.google.com';
874 document.body.appendChild(webview); 923 document.body.appendChild(webview);
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 'testNavOnSrcAttributeChange': testNavOnSrcAttributeChange, 1195 'testNavOnSrcAttributeChange': testNavOnSrcAttributeChange,
1147 'testReassignSrcAttribute': testReassignSrcAttribute, 1196 'testReassignSrcAttribute': testReassignSrcAttribute,
1148 'testRemoveSrcAttribute': testRemoveSrcAttribute, 1197 'testRemoveSrcAttribute': testRemoveSrcAttribute,
1149 'testBrowserPluginNotAllowed': testBrowserPluginNotAllowed, 1198 'testBrowserPluginNotAllowed': testBrowserPluginNotAllowed,
1150 'testPluginLoadPermission': testPluginLoadPermission, 1199 'testPluginLoadPermission': testPluginLoadPermission,
1151 'testNewWindow': testNewWindow, 1200 'testNewWindow': testNewWindow,
1152 'testNewWindowTwoListeners': testNewWindowTwoListeners, 1201 'testNewWindowTwoListeners': testNewWindowTwoListeners,
1153 'testNewWindowNoPreventDefault': testNewWindowNoPreventDefault, 1202 'testNewWindowNoPreventDefault': testNewWindowNoPreventDefault,
1154 'testNewWindowNoReferrerLink': testNewWindowNoReferrerLink, 1203 'testNewWindowNoReferrerLink': testNewWindowNoReferrerLink,
1155 'testContentLoadEvent': testContentLoadEvent, 1204 'testContentLoadEvent': testContentLoadEvent,
1205 'testDeclarativeWebRequestAPI': testDeclarativeWebRequestAPI,
1156 'testWebRequestAPI': testWebRequestAPI, 1206 'testWebRequestAPI': testWebRequestAPI,
1157 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty, 1207 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty,
1158 'testWebRequestListenerSurvivesReparenting': 1208 'testWebRequestListenerSurvivesReparenting':
1159 testWebRequestListenerSurvivesReparenting, 1209 testWebRequestListenerSurvivesReparenting,
1160 'testGetProcessId': testGetProcessId, 1210 'testGetProcessId': testGetProcessId,
1161 'testLoadStartLoadRedirect': testLoadStartLoadRedirect, 1211 'testLoadStartLoadRedirect': testLoadStartLoadRedirect,
1162 'testLoadAbortChromeExtensionURLWrongPartition': 1212 'testLoadAbortChromeExtensionURLWrongPartition':
1163 testLoadAbortChromeExtensionURLWrongPartition, 1213 testLoadAbortChromeExtensionURLWrongPartition,
1164 'testLoadAbortEmptyResponse': testLoadAbortEmptyResponse, 1214 'testLoadAbortEmptyResponse': testLoadAbortEmptyResponse,
1165 'testLoadAbortIllegalChromeURL': testLoadAbortIllegalChromeURL, 1215 'testLoadAbortIllegalChromeURL': testLoadAbortIllegalChromeURL,
1166 'testLoadAbortIllegalFileURL': testLoadAbortIllegalFileURL, 1216 'testLoadAbortIllegalFileURL': testLoadAbortIllegalFileURL,
1167 'testLoadAbortIllegalJavaScriptURL': testLoadAbortIllegalJavaScriptURL, 1217 'testLoadAbortIllegalJavaScriptURL': testLoadAbortIllegalJavaScriptURL,
1168 'testNavigationToExternalProtocol': testNavigationToExternalProtocol, 1218 'testNavigationToExternalProtocol': testNavigationToExternalProtocol,
1169 'testReload': testReload, 1219 'testReload': testReload,
1170 'testRemoveWebviewOnExit': testRemoveWebviewOnExit, 1220 'testRemoveWebviewOnExit': testRemoveWebviewOnExit,
1171 'testRemoveWebviewAfterNavigation': testRemoveWebviewAfterNavigation, 1221 'testRemoveWebviewAfterNavigation': testRemoveWebviewAfterNavigation,
1172 'testResizeWebviewResizesContent': testResizeWebviewResizesContent 1222 'testResizeWebviewResizesContent': testResizeWebviewResizesContent
1173 }; 1223 };
1174 1224
1175 onload = function() { 1225 onload = function() {
1176 chrome.test.getConfig(function(config) { 1226 chrome.test.getConfig(function(config) {
1177 embedder.setUp_(config); 1227 embedder.setUp_(config);
1178 chrome.test.sendMessage("Launched"); 1228 chrome.test.sendMessage("Launched");
1179 }); 1229 });
1180 }; 1230 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698