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

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

Issue 2702503002: Block renderer-initiated main frame navigations to data URLs (Closed)
Patch Set: nasko comments, fix most tests Created 3 years, 8 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 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 } 1306 }
1307 1307
1308 // This test verifies that the call to executeScript will fail and return null 1308 // This test verifies that the call to executeScript will fail and return null
1309 // if the webview has been navigated between the time the call was made and the 1309 // if the webview has been navigated between the time the call was made and the
1310 // time it arrives in the guest process. 1310 // time it arrives in the guest process.
1311 function testExecuteScriptIsAbortedWhenWebViewSourceIsChanged() { 1311 function testExecuteScriptIsAbortedWhenWebViewSourceIsChanged() {
1312 var webview = document.createElement('webview'); 1312 var webview = document.createElement('webview');
1313 webview.addEventListener('loadstop', function onLoadStop(e) { 1313 webview.addEventListener('loadstop', function onLoadStop(e) {
1314 window.console.log('2. Inject script to trigger a guest-initiated ' + 1314 window.console.log('2. Inject script to trigger a guest-initiated ' +
1315 'navigation.'); 1315 'navigation.');
1316 var navUrl = 'data:text/html,trigger nav'; 1316 var navUrl = 'data:text/html, trigger nav';
1317 webview.executeScript({ 1317 webview.executeScript({
1318 code: 'window.location.href = "' + navUrl + '";' 1318 code: 'window.location.href = "' + navUrl + '";'
1319 }); 1319 });
1320 1320
1321 window.console.log('3. Listening for the load that will be started as a ' + 1321 window.console.log('3. Listening for the load that will be started as a ' +
1322 'result of 2.'); 1322 'result of 2.');
1323 webview.addEventListener('loadstart', function onLoadStart(e) { 1323 webview.addEventListener('loadstart', function onLoadStart(e) {
1324 embedder.test.assertEq('about:blank', webview.src); 1324 embedder.test.assertEq('data:text/html, initial page', webview.src);
1325 window.console.log('4. Attempting to inject script into about:blank. ' + 1325 window.console.log('4. Attempting to inject script into about:blank. ' +
1326 'This is expected to fail.'); 1326 'This is expected to fail.');
1327 webview.executeScript( 1327 webview.executeScript(
1328 { code: 'document.body.style.backgroundColor = "red";' }, 1328 { code: 'document.body.style.backgroundColor = "red";' },
1329 function(results) { 1329 function(results) {
1330 window.console.log( 1330 window.console.log(
1331 '5. Verify that executeScript has, indeed, failed.'); 1331 '5. Verify that executeScript has, indeed, failed.');
1332 embedder.test.assertEq(null, results); 1332 embedder.test.assertEq(null, results);
1333 embedder.test.assertEq(navUrl, webview.src); 1333 embedder.test.assertEq(navUrl, webview.src);
1334 embedder.test.succeed(); 1334 embedder.test.succeed();
1335 } 1335 }
1336 ); 1336 );
1337 webview.removeEventListener('loadstart', onLoadStart); 1337 webview.removeEventListener('loadstart', onLoadStart);
1338 }); 1338 });
1339 webview.removeEventListener('loadstop', onLoadStop); 1339 webview.removeEventListener('loadstop', onLoadStop);
1340 }); 1340 });
1341 1341
1342 window.console.log('1. Performing initial navigation.'); 1342 window.console.log('1. Performing initial navigation.');
1343 webview.setAttribute('src', 'about:blank'); 1343 webview.setAttribute('src', 'data:text/html, initial page');
1344 document.body.appendChild(webview); 1344 document.body.appendChild(webview);
1345 } 1345 }
1346 1346
1347 // This test verifies that, in the case where the WebView is set up with a 1347 // This test verifies that, in the case where the WebView is set up with a
1348 // 'loadabort' handler that calls executeScript() with a script that sets 1348 // 'loadabort' handler that calls executeScript() with a script that sets
1349 // the WebView's 'src' to an invalid URL, and the caller then calls 1349 // the WebView's 'src' to an invalid URL, and the caller then calls
1350 // executeScript() on that WebView with that same script (that sets 'src' 1350 // executeScript() on that WebView with that same script (that sets 'src'
1351 // to an invalid URL), that loadabort will get called in both cases (and 1351 // to an invalid URL), that loadabort will get called in both cases (and
1352 // that the browser does not crash during the second call to executeScript()). 1352 // that the browser does not crash during the second call to executeScript()).
1353 function testExecuteScriptIsAbortedWhenWebViewSourceIsInvalid() { 1353 function testExecuteScriptIsAbortedWhenWebViewSourceIsInvalid() {
(...skipping 1805 matching lines...) Expand 10 before | Expand all | Expand 10 after
3159 testRendererNavigationRedirectWhileUnattached, 3159 testRendererNavigationRedirectWhileUnattached,
3160 'testBlobURL': testBlobURL 3160 'testBlobURL': testBlobURL
3161 }; 3161 };
3162 3162
3163 onload = function() { 3163 onload = function() {
3164 chrome.test.getConfig(function(config) { 3164 chrome.test.getConfig(function(config) {
3165 embedder.setUp_(config); 3165 embedder.setUp_(config);
3166 chrome.test.sendMessage("Launched"); 3166 chrome.test.sendMessage("Launched");
3167 }); 3167 });
3168 }; 3168 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698