OLD | NEW |
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; |
11 } | 11 } |
12 embedder.baseGuestURL = 'http://localhost:' + config.testServer.port; | 12 embedder.baseGuestURL = 'http://localhost:' + config.testServer.port; |
13 embedder.closeSocketURL = embedder.baseGuestURL + '/close-socket'; | 13 embedder.closeSocketURL = embedder.baseGuestURL + '/close-socket'; |
14 embedder.emptyGuestURL = embedder.baseGuestURL + '/empty_guest.html'; | 14 embedder.emptyGuestURL = embedder.baseGuestURL + '/empty_guest.html'; |
15 embedder.noReferrerGuestURL = | 15 embedder.noReferrerGuestURL = |
16 embedder.baseGuestURL + '/guest_noreferrer.html'; | 16 embedder.baseGuestURL + '/guest_noreferrer.html'; |
17 embedder.detectUserAgentURL = embedder.baseGuestURL + '/detect-user-agent'; | 17 embedder.detectUserAgentURL = embedder.baseGuestURL + '/detect-user-agent'; |
18 embedder.redirectGuestURL = embedder.baseGuestURL + '/server-redirect'; | 18 embedder.redirectGuestURL = embedder.baseGuestURL + '/server-redirect'; |
19 embedder.redirectGuestURLDest = | 19 embedder.redirectGuestURLDest = |
20 embedder.baseGuestURL + '/guest_redirect.html'; | 20 embedder.baseGuestURL + '/guest_redirect.html'; |
21 embedder.windowOpenGuestURL = embedder.baseGuestURL + '/guest.html'; | 21 embedder.windowOpenGuestURL = embedder.baseGuestURL + '/guest.html'; |
| 22 embedder.windowOpenGuestDataURL = |
| 23 embedder.baseGuestURL + '/guest_data_url.html'; |
22 embedder.sameDocumentNavigationURL = | 24 embedder.sameDocumentNavigationURL = |
23 embedder.baseGuestURL + '/guest_same_document_navigation.html'; | 25 embedder.baseGuestURL + '/guest_same_document_navigation.html'; |
24 }; | 26 }; |
25 | 27 |
26 window.runTest = function(testName) { | 28 window.runTest = function(testName) { |
27 if (!embedder.test.testList[testName]) { | 29 if (!embedder.test.testList[testName]) { |
28 window.console.warn('Incorrect testName: ' + testName); | 30 window.console.warn('Incorrect testName: ' + testName); |
29 embedder.test.fail(); | 31 embedder.test.fail(); |
30 return; | 32 return; |
31 } | 33 } |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 webview.addEventListener('loadabort', function(e) { | 460 webview.addEventListener('loadabort', function(e) { |
459 embedder.test.fail(); | 461 embedder.test.fail(); |
460 }); | 462 }); |
461 webview.addEventListener('loadstop', function(e) { | 463 webview.addEventListener('loadstop', function(e) { |
462 embedder.test.succeed(); | 464 embedder.test.succeed(); |
463 }); | 465 }); |
464 webview.setAttribute('src', localResource); | 466 webview.setAttribute('src', localResource); |
465 document.body.appendChild(webview); | 467 document.body.appendChild(webview); |
466 } | 468 } |
467 | 469 |
| 470 // This test verifies that guests are blocked from navigating the webview to a |
| 471 // data URL. |
| 472 function testContentInitiatedNavigationToDataUrlBlocked() { |
| 473 var navUrl = "data:text/html,foo"; |
| 474 var webview = document.createElement('webview'); |
| 475 webview.addEventListener('consolemessage', function(e) { |
| 476 if (e.message.startsWith( |
| 477 'Not allowed to top-level navigate to resource:')) { |
| 478 embedder.test.succeed(); |
| 479 } |
| 480 }); |
| 481 webview.addEventListener('loadstop', function(e) { |
| 482 if (webview.getAttribute('src') == navUrl) { |
| 483 embedder.test.fail(); |
| 484 } |
| 485 }); |
| 486 webview.setAttribute('src', |
| 487 'data:text/html,<script>window.location.href = "' + navUrl + |
| 488 '";</scr' + 'ipt>'); |
| 489 document.body.appendChild(webview); |
| 490 } |
| 491 |
468 // This test verifies that the load event fires when the a new page is | 492 // This test verifies that the load event fires when the a new page is |
469 // loaded. | 493 // loaded. |
470 // TODO(fsamuel): Add a test to verify that subframe loads within a guest | 494 // TODO(fsamuel): Add a test to verify that subframe loads within a guest |
471 // do not fire the 'contentload' event. | 495 // do not fire the 'contentload' event. |
472 function testContentLoadEvent() { | 496 function testContentLoadEvent() { |
473 var webview = document.createElement('webview'); | 497 var webview = document.createElement('webview'); |
474 webview.addEventListener('contentload', function(e) { | 498 webview.addEventListener('contentload', function(e) { |
475 embedder.test.succeed(); | 499 embedder.test.succeed(); |
476 }); | 500 }); |
477 webview.setAttribute('src', 'data:text/html,trigger navigation'); | 501 webview.setAttribute('src', 'data:text/html,trigger navigation'); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 } | 711 } |
688 | 712 |
689 // This test verifies that the call to executeScript will fail and return null | 713 // This test verifies that the call to executeScript will fail and return null |
690 // if the webview has been navigated between the time the call was made and the | 714 // if the webview has been navigated between the time the call was made and the |
691 // time it arrives in the guest process. | 715 // time it arrives in the guest process. |
692 function testExecuteScriptIsAbortedWhenWebViewSourceIsChanged() { | 716 function testExecuteScriptIsAbortedWhenWebViewSourceIsChanged() { |
693 var webview = document.createElement('webview'); | 717 var webview = document.createElement('webview'); |
694 webview.addEventListener('loadstop', function onLoadStop(e) { | 718 webview.addEventListener('loadstop', function onLoadStop(e) { |
695 window.console.log('2. Inject script to trigger a guest-initiated ' + | 719 window.console.log('2. Inject script to trigger a guest-initiated ' + |
696 'navigation.'); | 720 'navigation.'); |
697 var navUrl = 'data:text/html,trigger nav'; | 721 var navUrl = embedder.baseGuestURL + "/empty.html"; |
698 webview.executeScript({ | 722 webview.executeScript({ |
699 code: 'window.location.href = "' + navUrl + '";' | 723 code: 'window.location.href = "' + navUrl + '";' |
700 }); | 724 }); |
701 | 725 |
702 window.console.log('3. Listening for the load that will be started as a ' + | 726 window.console.log('3. Listening for the load that will be started as a ' + |
703 'result of 2.'); | 727 'result of 2.'); |
704 webview.addEventListener('loadstart', function onLoadStart(e) { | 728 webview.addEventListener('loadstart', function onLoadStart(e) { |
705 embedder.test.assertEq('about:blank', webview.src); | 729 embedder.test.assertEq('data:text/html, initial page', webview.src); |
706 window.console.log('4. Attempting to inject script into about:blank. ' + | 730 window.console.log('4. Attempting to inject script into about:blank. ' + |
707 'This is expected to fail.'); | 731 'This is expected to fail.'); |
708 webview.executeScript( | 732 webview.executeScript( |
709 { code: 'document.body.style.backgroundColor = "red";' }, | 733 { code: 'document.body.style.backgroundColor = "red";' }, |
710 function(results) { | 734 function(results) { |
711 window.console.log( | 735 window.console.log( |
712 '5. Verify that executeScript has, indeed, failed.'); | 736 '5. Verify that executeScript has, indeed, failed.'); |
713 embedder.test.assertEq(null, results); | 737 embedder.test.assertEq(null, results); |
714 embedder.test.assertEq(navUrl, webview.src); | 738 embedder.test.assertEq(navUrl, webview.src); |
715 embedder.test.succeed(); | 739 embedder.test.succeed(); |
716 } | 740 } |
717 ); | 741 ); |
718 webview.removeEventListener('loadstart', onLoadStart); | 742 webview.removeEventListener('loadstart', onLoadStart); |
719 }); | 743 }); |
720 webview.removeEventListener('loadstop', onLoadStop); | 744 webview.removeEventListener('loadstop', onLoadStop); |
721 }); | 745 }); |
722 | 746 |
723 window.console.log('1. Performing initial navigation.'); | 747 window.console.log('1. Performing initial navigation.'); |
724 webview.setAttribute('src', 'about:blank'); | 748 webview.setAttribute('src', 'data:text/html, initial page'); |
725 document.body.appendChild(webview); | 749 document.body.appendChild(webview); |
726 } | 750 } |
727 | 751 |
728 function testFindAPI() { | 752 function testFindAPI() { |
729 var webview = new WebView(); | 753 var webview = new WebView(); |
730 webview.src = 'data:text/html,Dog dog dog Dog dog dogcatDog dogDogdog<br>' + | 754 webview.src = 'data:text/html,Dog dog dog Dog dog dogcatDog dogDogdog<br>' + |
731 'Dog dog dog Dog dog dogcatDog dogDogdog<br>' + | 755 'Dog dog dog Dog dog dogcatDog dogDogdog<br>' + |
732 'Dog dog dog Dog dog dogcatDog dogDogdog<br>' + | 756 'Dog dog dog Dog dog dogcatDog dogDogdog<br>' + |
733 'Dog dog dog Dog dog dogcatDog dogDogdog<br>' + | 757 'Dog dog dog Dog dog dogcatDog dogDogdog<br>' + |
734 'Dog dog dog Dog dog dogcatDog dogDogdog<br>' + | 758 'Dog dog dog Dog dog dogcatDog dogDogdog<br>' + |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 embedder.test.fail(); | 1246 embedder.test.fail(); |
1223 } else { | 1247 } else { |
1224 webview.src = tests[loadCommitCount]; | 1248 webview.src = tests[loadCommitCount]; |
1225 } | 1249 } |
1226 }); | 1250 }); |
1227 webview.src = tests[0]; | 1251 webview.src = tests[0]; |
1228 document.body.appendChild(webview); | 1252 document.body.appendChild(webview); |
1229 } | 1253 } |
1230 | 1254 |
1231 // This test verifies that new window attachment functions as expected. | 1255 // This test verifies that new window attachment functions as expected. |
| 1256 // |
| 1257 // TODO(crbug.com/594215) Test that opening a new window with a data URL is |
| 1258 // blocked. There is currently no way to test this, as the block message is |
| 1259 // printed on the new window which never gets created, so the message is lost. |
| 1260 // Also test that opening a new window with a data URL when the webview is |
| 1261 // already on a data URL is allowed. |
1232 function testNewWindow() { | 1262 function testNewWindow() { |
1233 var webview = document.createElement('webview'); | 1263 var webview = document.createElement('webview'); |
1234 webview.addEventListener('newwindow', function(e) { | 1264 webview.addEventListener('newwindow', function(e) { |
1235 e.preventDefault(); | 1265 e.preventDefault(); |
1236 var newwebview = document.createElement('webview'); | 1266 var newwebview = document.createElement('webview'); |
1237 newwebview.addEventListener('loadstop', function(evt) { | 1267 newwebview.addEventListener('loadstop', function(evt) { |
1238 // If the new window finishes loading, the test is successful. | 1268 // If the new window finishes loading, the test is successful. |
1239 embedder.test.succeed(); | 1269 embedder.test.succeed(); |
1240 }); | 1270 }); |
1241 document.body.appendChild(newwebview); | 1271 document.body.appendChild(newwebview); |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1746 'testAPIMethodExistence': testAPIMethodExistence, | 1776 'testAPIMethodExistence': testAPIMethodExistence, |
1747 'testAssignSrcAfterCrash': testAssignSrcAfterCrash, | 1777 'testAssignSrcAfterCrash': testAssignSrcAfterCrash, |
1748 'testAutosizeAfterNavigation': testAutosizeAfterNavigation, | 1778 'testAutosizeAfterNavigation': testAutosizeAfterNavigation, |
1749 'testAutosizeBeforeNavigation': testAutosizeBeforeNavigation, | 1779 'testAutosizeBeforeNavigation': testAutosizeBeforeNavigation, |
1750 'testAutosizeHeight': testAutosizeHeight, | 1780 'testAutosizeHeight': testAutosizeHeight, |
1751 'testAutosizeRemoveAttributes': testAutosizeRemoveAttributes, | 1781 'testAutosizeRemoveAttributes': testAutosizeRemoveAttributes, |
1752 'testAutosizeWithPartialAttributes': testAutosizeWithPartialAttributes, | 1782 'testAutosizeWithPartialAttributes': testAutosizeWithPartialAttributes, |
1753 'testCannotMutateEventName': testCannotMutateEventName, | 1783 'testCannotMutateEventName': testCannotMutateEventName, |
1754 'testChromeExtensionRelativePath': testChromeExtensionRelativePath, | 1784 'testChromeExtensionRelativePath': testChromeExtensionRelativePath, |
1755 'testChromeExtensionURL': testChromeExtensionURL, | 1785 'testChromeExtensionURL': testChromeExtensionURL, |
| 1786 'testContentInitiatedNavigationToDataUrlBlocked': |
| 1787 testContentInitiatedNavigationToDataUrlBlocked, |
1756 'testContentLoadEvent': testContentLoadEvent, | 1788 'testContentLoadEvent': testContentLoadEvent, |
1757 'testDeclarativeWebRequestAPI': testDeclarativeWebRequestAPI, | 1789 'testDeclarativeWebRequestAPI': testDeclarativeWebRequestAPI, |
1758 'testDeclarativeWebRequestAPISendMessage': | 1790 'testDeclarativeWebRequestAPISendMessage': |
1759 testDeclarativeWebRequestAPISendMessage, | 1791 testDeclarativeWebRequestAPISendMessage, |
1760 'testDestroyOnEventListener': testDestroyOnEventListener, | 1792 'testDestroyOnEventListener': testDestroyOnEventListener, |
1761 'testDisplayNoneWebviewLoad': testDisplayNoneWebviewLoad, | 1793 'testDisplayNoneWebviewLoad': testDisplayNoneWebviewLoad, |
1762 'testDisplayNoneWebviewRemoveChild': testDisplayNoneWebviewRemoveChild, | 1794 'testDisplayNoneWebviewRemoveChild': testDisplayNoneWebviewRemoveChild, |
1763 'testEventName': testEventName, | 1795 'testEventName': testEventName, |
1764 'testExecuteScript': testExecuteScript, | 1796 'testExecuteScript': testExecuteScript, |
1765 'testExecuteScriptFail': testExecuteScriptFail, | 1797 'testExecuteScriptFail': testExecuteScriptFail, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1810 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty, | 1842 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty, |
1811 'testCaptureVisibleRegion': testCaptureVisibleRegion | 1843 'testCaptureVisibleRegion': testCaptureVisibleRegion |
1812 }; | 1844 }; |
1813 | 1845 |
1814 onload = function() { | 1846 onload = function() { |
1815 chrome.test.getConfig(function(config) { | 1847 chrome.test.getConfig(function(config) { |
1816 embedder.setUp_(config); | 1848 embedder.setUp_(config); |
1817 chrome.test.sendMessage('LAUNCHED'); | 1849 chrome.test.sendMessage('LAUNCHED'); |
1818 }); | 1850 }); |
1819 }; | 1851 }; |
OLD | NEW |