| OLD | NEW |
| 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 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 function(results) { | 801 function(results) { |
| 802 embedder.test.assertEq(1, results.length); | 802 embedder.test.assertEq(1, results.length); |
| 803 embedder.test.assertEq('red', results[0]); | 803 embedder.test.assertEq('red', results[0]); |
| 804 embedder.test.succeed(); | 804 embedder.test.succeed(); |
| 805 }); | 805 }); |
| 806 }); | 806 }); |
| 807 webview.setAttribute('src', 'data:text/html,trigger navigation'); | 807 webview.setAttribute('src', 'data:text/html,trigger navigation'); |
| 808 document.body.appendChild(webview); | 808 document.body.appendChild(webview); |
| 809 } | 809 } |
| 810 | 810 |
| 811 // This test verifies that the call of executeScript will fail and return null | 811 // This test verifies that the call to executeScript will fail and return null |
| 812 // if the webview has been navigated to another source. | 812 // if the webview has been navigated between the time the call was made and the |
| 813 // time it arrives in the guest process. |
| 813 function testExecuteScriptIsAbortedWhenWebViewSourceIsChanged() { | 814 function testExecuteScriptIsAbortedWhenWebViewSourceIsChanged() { |
| 814 var webview = document.createElement('webview'); | 815 var webview = document.createElement('webview'); |
| 815 var initial = true; | 816 webview.addEventListener('loadstop', function onLoadStop(e) { |
| 816 var navigationOccur = false; | 817 window.console.log('2. Inject script to trigger a guest-initiated ' + |
| 817 var newSrc = 'data:text/html,trigger navigation'; | 818 'navigation.'); |
| 818 webview.addEventListener('loadstart', function() { | 819 var navUrl = 'data:text/html,trigger nav'; |
| 819 if (initial) { | 820 webview.executeScript({ |
| 820 webview.setAttribute('src', newSrc); | 821 code: 'window.location.href = "' + navUrl + '";' |
| 821 navigationOccur = true; | 822 }); |
| 822 } | 823 |
| 823 initial = false; | 824 window.console.log('3. Listening for the load that will be started as a ' + |
| 824 }); | 825 'result of 2.'); |
| 825 webview.addEventListener('loadstop', function() { | 826 webview.addEventListener('loadstart', function onLoadStart(e) { |
| 826 webview.executeScript( | 827 embedder.test.assertEq('about:blank', webview.src); |
| 827 {code:'document.body.style.backgroundColor = "red";'}, | 828 window.console.log('4. Attempting to inject script into about:blank. ' + |
| 828 function(results) { | 829 'This is expected to fail.'); |
| 829 if (navigationOccur) { | 830 webview.executeScript( |
| 830 // Expect a null results because the executeScript failed; | 831 { code: 'document.body.style.backgroundColor = "red";' }, |
| 831 // return "red", otherwise. | 832 function(results) { |
| 833 window.console.log( |
| 834 '5. Verify that executeScript has, indeed, failed.'); |
| 832 embedder.test.assertEq(null, results); | 835 embedder.test.assertEq(null, results); |
| 836 embedder.test.assertEq(navUrl, webview.src); |
| 833 embedder.test.succeed(); | 837 embedder.test.succeed(); |
| 834 } | 838 } |
| 835 navigationOccur = false; | 839 ); |
| 836 } | 840 webview.removeEventListener('loadstart', onLoadStart); |
| 837 ); | 841 }); |
| 842 webview.removeEventListener('loadstop', onLoadStop); |
| 838 }); | 843 }); |
| 839 webview.setAttribute('src', "about:blank"); | 844 |
| 845 window.console.log('1. Performing initial navigation.'); |
| 846 webview.setAttribute('src', 'about:blank'); |
| 840 document.body.appendChild(webview); | 847 document.body.appendChild(webview); |
| 841 } | 848 } |
| 842 | 849 |
| 843 // This test calls terminate() on guest after it has already been | 850 // This test calls terminate() on guest after it has already been |
| 844 // terminated. This makes sure we ignore the call gracefully. | 851 // terminated. This makes sure we ignore the call gracefully. |
| 845 function testTerminateAfterExit() { | 852 function testTerminateAfterExit() { |
| 846 var webview = document.createElement('webview'); | 853 var webview = document.createElement('webview'); |
| 847 webview.setAttribute('partition', arguments.callee.name); | 854 webview.setAttribute('partition', arguments.callee.name); |
| 848 var loadstopSucceedsTest = false; | 855 var loadstopSucceedsTest = false; |
| 849 webview.addEventListener('loadstop', function(evt) { | 856 webview.addEventListener('loadstop', function(evt) { |
| (...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2123 'testFindAPI_findupdate': testFindAPI, | 2130 'testFindAPI_findupdate': testFindAPI, |
| 2124 'testLoadDataAPI': testLoadDataAPI | 2131 'testLoadDataAPI': testLoadDataAPI |
| 2125 }; | 2132 }; |
| 2126 | 2133 |
| 2127 onload = function() { | 2134 onload = function() { |
| 2128 chrome.test.getConfig(function(config) { | 2135 chrome.test.getConfig(function(config) { |
| 2129 embedder.setUp_(config); | 2136 embedder.setUp_(config); |
| 2130 chrome.test.sendMessage("Launched"); | 2137 chrome.test.sendMessage("Launched"); |
| 2131 }); | 2138 }); |
| 2132 }; | 2139 }; |
| OLD | NEW |