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

Side by Side Diff: extensions/test/data/web_view/apitest/main.js

Issue 2702503002: Block renderer-initiated main frame navigations to data URLs (Closed)
Patch Set: Fix Android PDF tests where PDFs should be downloaded 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 embedder = {}; 5 var embedder = {};
6 6
7 // TODO(lfg) Move these functions to a common js. 7 // TODO(lfg) Move these functions to a common js.
8 embedder.setUp_ = function(config) { 8 embedder.setUp_ = function(config) {
9 if (!config || !config.testServer) { 9 if (!config || !config.testServer) {
10 return; 10 return;
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 webview.addEventListener('loadabort', function(e) { 458 webview.addEventListener('loadabort', function(e) {
459 embedder.test.fail(); 459 embedder.test.fail();
460 }); 460 });
461 webview.addEventListener('loadstop', function(e) { 461 webview.addEventListener('loadstop', function(e) {
462 embedder.test.succeed(); 462 embedder.test.succeed();
463 }); 463 });
464 webview.setAttribute('src', localResource); 464 webview.setAttribute('src', localResource);
465 document.body.appendChild(webview); 465 document.body.appendChild(webview);
466 } 466 }
467 467
468 // This test verifies that guests are blocked from navigating the webview to a
469 // data URL.
470 function testContentInitiatedNavigationToDataUrlBlocked() {
471 var navUrl = "data:text/html,foo";
472 var webview = document.createElement('webview');
473 webview.addEventListener('consolemessage', function(e) {
474 if (e.message.startsWith(
475 'Not allowed to navigate top frame to data URL:')) {
476 embedder.test.succeed();
477 }
478 });
479 webview.addEventListener('loadstop', function(e) {
480 if (webview.getAttribute('src') == navUrl) {
481 embedder.test.fail();
482 }
483 });
484 webview.setAttribute('src',
485 'data:text/html,<script>window.location.href = "' + navUrl +
486 '";</scr' + 'ipt>');
487 document.body.appendChild(webview);
488 }
489
468 // This test verifies that the load event fires when the a new page is 490 // This test verifies that the load event fires when the a new page is
469 // loaded. 491 // loaded.
470 // TODO(fsamuel): Add a test to verify that subframe loads within a guest 492 // TODO(fsamuel): Add a test to verify that subframe loads within a guest
471 // do not fire the 'contentload' event. 493 // do not fire the 'contentload' event.
472 function testContentLoadEvent() { 494 function testContentLoadEvent() {
473 var webview = document.createElement('webview'); 495 var webview = document.createElement('webview');
474 webview.addEventListener('contentload', function(e) { 496 webview.addEventListener('contentload', function(e) {
475 embedder.test.succeed(); 497 embedder.test.succeed();
476 }); 498 });
477 webview.setAttribute('src', 'data:text/html,trigger navigation'); 499 webview.setAttribute('src', 'data:text/html,trigger navigation');
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 embedder.test.fail(); 1244 embedder.test.fail();
1223 } else { 1245 } else {
1224 webview.src = tests[loadCommitCount]; 1246 webview.src = tests[loadCommitCount];
1225 } 1247 }
1226 }); 1248 });
1227 webview.src = tests[0]; 1249 webview.src = tests[0];
1228 document.body.appendChild(webview); 1250 document.body.appendChild(webview);
1229 } 1251 }
1230 1252
1231 // This test verifies that new window attachment functions as expected. 1253 // This test verifies that new window attachment functions as expected.
1254 //
1255 // TODO(crbug.com/594215) Test that opening a new window with a data URL is
1256 // blocked. There is currently no way to test this, as the block message is
1257 // printed on the new window which never gets created, so the message is lost.
1258 // Also test that opening a new window with a data URL when the webview is
1259 // already on a data URL is allowed.
1232 function testNewWindow() { 1260 function testNewWindow() {
1233 var webview = document.createElement('webview'); 1261 var webview = document.createElement('webview');
1234 webview.addEventListener('newwindow', function(e) { 1262 webview.addEventListener('newwindow', function(e) {
1235 e.preventDefault(); 1263 e.preventDefault();
1236 var newwebview = document.createElement('webview'); 1264 var newwebview = document.createElement('webview');
1237 newwebview.addEventListener('loadstop', function(evt) { 1265 newwebview.addEventListener('loadstop', function(evt) {
1238 // If the new window finishes loading, the test is successful. 1266 // If the new window finishes loading, the test is successful.
1239 embedder.test.succeed(); 1267 embedder.test.succeed();
1240 }); 1268 });
1241 document.body.appendChild(newwebview); 1269 document.body.appendChild(newwebview);
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 'testAPIMethodExistence': testAPIMethodExistence, 1774 'testAPIMethodExistence': testAPIMethodExistence,
1747 'testAssignSrcAfterCrash': testAssignSrcAfterCrash, 1775 'testAssignSrcAfterCrash': testAssignSrcAfterCrash,
1748 'testAutosizeAfterNavigation': testAutosizeAfterNavigation, 1776 'testAutosizeAfterNavigation': testAutosizeAfterNavigation,
1749 'testAutosizeBeforeNavigation': testAutosizeBeforeNavigation, 1777 'testAutosizeBeforeNavigation': testAutosizeBeforeNavigation,
1750 'testAutosizeHeight': testAutosizeHeight, 1778 'testAutosizeHeight': testAutosizeHeight,
1751 'testAutosizeRemoveAttributes': testAutosizeRemoveAttributes, 1779 'testAutosizeRemoveAttributes': testAutosizeRemoveAttributes,
1752 'testAutosizeWithPartialAttributes': testAutosizeWithPartialAttributes, 1780 'testAutosizeWithPartialAttributes': testAutosizeWithPartialAttributes,
1753 'testCannotMutateEventName': testCannotMutateEventName, 1781 'testCannotMutateEventName': testCannotMutateEventName,
1754 'testChromeExtensionRelativePath': testChromeExtensionRelativePath, 1782 'testChromeExtensionRelativePath': testChromeExtensionRelativePath,
1755 'testChromeExtensionURL': testChromeExtensionURL, 1783 'testChromeExtensionURL': testChromeExtensionURL,
1784 'testContentInitiatedNavigationToDataUrlBlocked':
1785 testContentInitiatedNavigationToDataUrlBlocked,
1756 'testContentLoadEvent': testContentLoadEvent, 1786 'testContentLoadEvent': testContentLoadEvent,
1757 'testDeclarativeWebRequestAPI': testDeclarativeWebRequestAPI, 1787 'testDeclarativeWebRequestAPI': testDeclarativeWebRequestAPI,
1758 'testDeclarativeWebRequestAPISendMessage': 1788 'testDeclarativeWebRequestAPISendMessage':
1759 testDeclarativeWebRequestAPISendMessage, 1789 testDeclarativeWebRequestAPISendMessage,
1760 'testDestroyOnEventListener': testDestroyOnEventListener, 1790 'testDestroyOnEventListener': testDestroyOnEventListener,
1761 'testDisplayNoneWebviewLoad': testDisplayNoneWebviewLoad, 1791 'testDisplayNoneWebviewLoad': testDisplayNoneWebviewLoad,
1762 'testDisplayNoneWebviewRemoveChild': testDisplayNoneWebviewRemoveChild, 1792 'testDisplayNoneWebviewRemoveChild': testDisplayNoneWebviewRemoveChild,
1763 'testEventName': testEventName, 1793 'testEventName': testEventName,
1764 'testExecuteScript': testExecuteScript, 1794 'testExecuteScript': testExecuteScript,
1765 'testExecuteScriptFail': testExecuteScriptFail, 1795 'testExecuteScriptFail': testExecuteScriptFail,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1810 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty, 1840 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty,
1811 'testCaptureVisibleRegion': testCaptureVisibleRegion 1841 'testCaptureVisibleRegion': testCaptureVisibleRegion
1812 }; 1842 };
1813 1843
1814 onload = function() { 1844 onload = function() {
1815 chrome.test.getConfig(function(config) { 1845 chrome.test.getConfig(function(config) {
1816 embedder.setUp_(config); 1846 embedder.setUp_(config);
1817 chrome.test.sendMessage('LAUNCHED'); 1847 chrome.test.sendMessage('LAUNCHED');
1818 }); 1848 });
1819 }; 1849 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698