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; |
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 embedder.test.succeed(); | 957 embedder.test.succeed(); |
958 }); | 958 }); |
959 webview.setAttribute('src', embedder.closeSocketURL); | 959 webview.setAttribute('src', embedder.closeSocketURL); |
960 document.body.appendChild(webview); | 960 document.body.appendChild(webview); |
961 } | 961 } |
962 | 962 |
963 // This test verifies that the loadabort event fires as expected when an illegal | 963 // This test verifies that the loadabort event fires as expected when an illegal |
964 // chrome URL is provided. | 964 // chrome URL is provided. |
965 function testLoadAbortIllegalChromeURL() { | 965 function testLoadAbortIllegalChromeURL() { |
966 var webview = document.createElement('webview'); | 966 var webview = document.createElement('webview'); |
967 var onFirstLoadStop = function(e) { | |
968 webview.removeEventListener('loadstop', onFirstLoadStop); | |
969 webview.setAttribute('src', 'chrome://newtab'); | |
970 }; | |
971 webview.addEventListener('loadstop', onFirstLoadStop); | |
972 webview.addEventListener('loadabort', function(e) { | 967 webview.addEventListener('loadabort', function(e) { |
973 embedder.test.assertEq('ERR_ABORTED', e.reason); | 968 embedder.test.assertEq('ERR_ABORTED', e.reason); |
| 969 }); |
| 970 webview.addEventListener('loadstop', function(e) { |
| 971 embedder.test.assertEq('about:blank', webview.src); |
974 embedder.test.succeed(); | 972 embedder.test.succeed(); |
975 }); | 973 }); |
976 webview.setAttribute('src', 'about:blank'); | 974 webview.src = 'chrome://newtab'; |
977 document.body.appendChild(webview); | 975 document.body.appendChild(webview); |
978 } | 976 } |
979 | 977 |
980 function testLoadAbortIllegalFileURL() { | 978 function testLoadAbortIllegalFileURL() { |
981 var webview = document.createElement('webview'); | 979 var webview = document.createElement('webview'); |
982 webview.addEventListener('loadabort', function(e) { | 980 webview.addEventListener('loadabort', function(e) { |
983 embedder.test.assertEq('ERR_ABORTED', e.reason); | 981 embedder.test.assertEq('ERR_ABORTED', e.reason); |
| 982 }); |
| 983 webview.addEventListener('loadstop', function(e) { |
| 984 embedder.test.assertEq('about:blank', webview.src); |
984 embedder.test.succeed(); | 985 embedder.test.succeed(); |
985 }); | 986 }); |
986 webview.setAttribute('src', 'file://foo'); | 987 webview.src = 'file://foo'; |
987 document.body.appendChild(webview); | 988 document.body.appendChild(webview); |
988 } | 989 } |
989 | 990 |
990 function testLoadAbortIllegalJavaScriptURL() { | 991 function testLoadAbortIllegalJavaScriptURL() { |
991 var webview = document.createElement('webview'); | 992 var webview = document.createElement('webview'); |
992 webview.addEventListener('loadabort', function(e) { | 993 webview.addEventListener('loadabort', function(e) { |
993 embedder.test.assertEq('ERR_ABORTED', e.reason); | 994 embedder.test.assertEq('ERR_ABORTED', e.reason); |
| 995 }); |
| 996 webview.addEventListener('loadstop', function(e) { |
| 997 embedder.test.assertEq('about:blank', webview.src); |
994 embedder.test.succeed(); | 998 embedder.test.succeed(); |
995 }); | 999 }); |
996 webview.setAttribute('src', 'javascript:void(document.bgColor="#0000FF")'); | 1000 webview.setAttribute('src', 'javascript:void(document.bgColor="#0000FF")'); |
997 document.body.appendChild(webview); | 1001 document.body.appendChild(webview); |
998 } | 1002 } |
999 | 1003 |
1000 // Verifies that navigating to invalid URL (e.g. 'http:') doesn't cause a crash. | 1004 // Verifies that navigating to invalid URL (e.g. 'http:') doesn't cause a crash. |
1001 function testLoadAbortInvalidNavigation() { | 1005 function testLoadAbortInvalidNavigation() { |
1002 var webview = document.createElement('webview'); | 1006 var webview = document.createElement('webview'); |
1003 var validSchemeWithEmptyURL = 'http:'; | |
1004 webview.addEventListener('loadabort', function(e) { | 1007 webview.addEventListener('loadabort', function(e) { |
1005 embedder.test.assertEq('ERR_ABORTED', e.reason); | 1008 embedder.test.assertEq('ERR_ABORTED', e.reason); |
1006 embedder.test.assertEq('', e.url); | 1009 embedder.test.assertEq('', e.url); |
| 1010 }); |
| 1011 webview.addEventListener('loadstop', function(e) { |
| 1012 embedder.test.assertEq('about:blank', webview.src); |
1007 embedder.test.succeed(); | 1013 embedder.test.succeed(); |
1008 }); | 1014 }); |
1009 webview.addEventListener('exit', function(e) { | 1015 webview.addEventListener('exit', function(e) { |
1010 // We should not crash. | 1016 // We should not crash. |
1011 embedder.test.fail(); | 1017 embedder.test.fail(); |
1012 }); | 1018 }); |
1013 webview.setAttribute('src', validSchemeWithEmptyURL); | 1019 webview.src = 'http:'; |
1014 document.body.appendChild(webview); | 1020 document.body.appendChild(webview); |
1015 } | 1021 } |
1016 | 1022 |
1017 // Verifies that navigation to a URL that is valid but not web-safe or | 1023 // Verifies that navigation to a URL that is valid but not web-safe or |
1018 // pseudo-scheme fires loadabort and doesn't cause a crash. | 1024 // pseudo-scheme fires loadabort and doesn't cause a crash. |
1019 function testLoadAbortNonWebSafeScheme() { | 1025 function testLoadAbortNonWebSafeScheme() { |
1020 var webview = document.createElement('webview'); | 1026 var webview = document.createElement('webview'); |
1021 var chromeGuestURL = 'chrome-guest://abc123'; | 1027 var chromeGuestURL = 'chrome-guest://abc123/'; |
1022 webview.addEventListener('loadabort', function(e) { | 1028 webview.addEventListener('loadabort', function(e) { |
1023 embedder.test.assertEq('ERR_ABORTED', e.reason); | 1029 embedder.test.assertEq('ERR_ABORTED', e.reason); |
1024 embedder.test.assertEq('chrome-guest://abc123/', e.url); | 1030 embedder.test.assertEq(chromeGuestURL, e.url); |
| 1031 }); |
| 1032 webview.addEventListener('loadstop', function(e) { |
| 1033 embedder.test.assertEq('about:blank', webview.src); |
1025 embedder.test.succeed(); | 1034 embedder.test.succeed(); |
1026 }); | 1035 }); |
1027 webview.addEventListener('exit', function(e) { | 1036 webview.addEventListener('exit', function(e) { |
1028 // We should not crash. | 1037 // We should not crash. |
1029 embedder.test.fail(); | 1038 embedder.test.fail(); |
1030 }); | 1039 }); |
1031 webview.setAttribute('src', chromeGuestURL); | 1040 webview.src = chromeGuestURL; |
1032 document.body.appendChild(webview); | 1041 document.body.appendChild(webview); |
1033 }; | 1042 }; |
1034 | 1043 |
1035 // Tests that the 'loadprogress' event is triggered correctly. | 1044 // Tests that the 'loadprogress' event is triggered correctly. |
1036 function testLoadProgressEvent() { | 1045 function testLoadProgressEvent() { |
1037 var webview = document.createElement('webview'); | 1046 var webview = document.createElement('webview'); |
1038 var progress = 0; | 1047 var progress = 0; |
1039 | 1048 |
1040 webview.addEventListener('loadstop', function(evt) { | 1049 webview.addEventListener('loadstop', function(evt) { |
1041 embedder.test.assertEq(1, progress); | 1050 embedder.test.assertEq(1, progress); |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1736 'testWebRequestAPIExistence': testWebRequestAPIExistence, | 1745 'testWebRequestAPIExistence': testWebRequestAPIExistence, |
1737 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty | 1746 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty |
1738 }; | 1747 }; |
1739 | 1748 |
1740 onload = function() { | 1749 onload = function() { |
1741 chrome.test.getConfig(function(config) { | 1750 chrome.test.getConfig(function(config) { |
1742 embedder.setUp_(config); | 1751 embedder.setUp_(config); |
1743 chrome.test.sendMessage('LAUNCHED'); | 1752 chrome.test.sendMessage('LAUNCHED'); |
1744 }); | 1753 }); |
1745 }; | 1754 }; |
OLD | NEW |