| 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 744 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 |