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 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1149 }); | 1149 }); |
1150 webview.executeScript({ | 1150 webview.executeScript({ |
1151 code: 'window.location.href = "tel:+12223334444";' | 1151 code: 'window.location.href = "tel:+12223334444";' |
1152 }, function(results) {}); | 1152 }, function(results) {}); |
1153 }); | 1153 }); |
1154 webview.setAttribute('src', 'data:text/html,navigate to external protocol'); | 1154 webview.setAttribute('src', 'data:text/html,navigate to external protocol'); |
1155 document.body.appendChild(webview); | 1155 document.body.appendChild(webview); |
1156 } | 1156 } |
1157 | 1157 |
1158 function testResizeWebviewResizesContent() { | 1158 function testResizeWebviewResizesContent() { |
1159 var triggerNavUrl = 'data:text/html,trigger navigation'; | |
1160 var webview = new WebView(); | 1159 var webview = new WebView(); |
1161 webview.src = triggerNavUrl; | 1160 webview.src = 'about:blank'; |
1162 webview.addEventListener('loadstop', function(e) { | 1161 webview.addEventListener('loadstop', function(e) { |
1163 webview.executeScript( | 1162 webview.executeScript( |
1164 {file: 'inject_resize_test.js'}, | 1163 {file: 'inject_resize_test.js'}, |
1165 function(results) { | 1164 function(results) { |
1166 console.log('Script has been injected into webview.'); | 1165 window.console.log('The resize test has been injected into webview.'); |
1166 } | |
1167 ); | |
1168 webview.executeScript( | |
1169 {file: 'inject_comm_channel.js'}, | |
1170 function(results) { | |
1171 window.console.log('The guest script for a two-way comm channel been ' + | |
1172 'injected into webview.'); | |
markusheintz_
2013/11/25 18:04:41
Same as below.
Fady Samuel
2013/11/25 21:54:02
Done.
| |
1167 // Establish a communication channel with the guest. | 1173 // Establish a communication channel with the guest. |
1168 var msg = ['connect']; | 1174 var msg = ['connect']; |
1169 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); | 1175 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); |
1170 } | 1176 } |
1171 ); | 1177 ); |
1172 }); | 1178 }); |
1173 window.addEventListener('message', function(e) { | 1179 window.addEventListener('message', function(e) { |
1174 var data = JSON.parse(e.data); | 1180 var data = JSON.parse(e.data); |
1175 if (data[0] == 'connected') { | 1181 if (data[0] == 'connected') { |
1176 console.log('A communication channel has been established with webview.'); | 1182 console.log('A communication channel has been established with webview.'); |
1177 console.log('Resizing <webview> width from 300px to 400px.'); | 1183 console.log('Resizing <webview> width from 300px to 400px.'); |
1178 webview.style.width = '400px'; | 1184 webview.style.width = '400px'; |
1179 return; | 1185 return; |
1180 } | 1186 } |
1181 if (data[0] == 'resize') { | 1187 if (data[0] == 'resize') { |
1182 var width = data[1]; | 1188 var width = data[1]; |
1183 var height = data[2]; | 1189 var height = data[2]; |
1184 embedder.test.assertEq(400, width); | 1190 embedder.test.assertEq(400, width); |
1185 embedder.test.assertEq(300, height); | 1191 embedder.test.assertEq(300, height); |
1186 embedder.test.succeed(); | 1192 embedder.test.succeed(); |
1187 return; | 1193 return; |
1188 } | 1194 } |
1189 console.log('Unexpected message: \'' + data[0] + '\''); | 1195 console.log('Unexpected message: \'' + data[0] + '\''); |
1190 embedder.test.fail(); | 1196 embedder.test.fail(); |
1191 }); | 1197 }); |
1192 document.body.appendChild(webview); | 1198 document.body.appendChild(webview); |
1193 } | 1199 } |
1194 | 1200 |
1201 function testPostMessageCommChannel() { | |
1202 var webview = new WebView(); | |
1203 webview.src = 'about:blank'; | |
1204 webview.addEventListener('loadstop', function(e) { | |
1205 webview.executeScript( | |
1206 {file: 'inject_comm_channel.js'}, | |
1207 function(results) { | |
1208 window.console.log('The guest script for a two-way comm channel been ' + | |
1209 'injected into webview.'); | |
markusheintz_
2013/11/25 18:04:41
nit: The log string doesn't sound like a correct p
Fady Samuel
2013/11/25 21:54:02
Done.
| |
1210 // Establish a communication channel with the guest. | |
1211 var msg = ['connect']; | |
1212 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); | |
1213 } | |
1214 ); | |
1215 }); | |
1216 window.addEventListener('message', function(e) { | |
1217 var data = JSON.parse(e.data); | |
1218 if (data[0] == 'connected') { | |
1219 console.log('A communication channel has been established with webview.'); | |
1220 embedder.test.succeed(); | |
1221 return; | |
1222 } | |
1223 console.log('Unexpected message: \'' + data[0] + '\''); | |
1224 embedder.test.fail(); | |
1225 }); | |
1226 document.body.appendChild(webview); | |
1227 } | |
1228 | |
1229 | |
1195 embedder.test.testList = { | 1230 embedder.test.testList = { |
1196 'testAutosizeAfterNavigation': testAutosizeAfterNavigation, | 1231 'testAutosizeAfterNavigation': testAutosizeAfterNavigation, |
1197 'testAutosizeBeforeNavigation': testAutosizeBeforeNavigation, | 1232 'testAutosizeBeforeNavigation': testAutosizeBeforeNavigation, |
1198 'testAutosizeRemoveAttributes': testAutosizeRemoveAttributes, | 1233 'testAutosizeRemoveAttributes': testAutosizeRemoveAttributes, |
1199 'testAutosizeWithPartialAttributes': testAutosizeWithPartialAttributes, | 1234 'testAutosizeWithPartialAttributes': testAutosizeWithPartialAttributes, |
1200 'testAPIMethodExistence': testAPIMethodExistence, | 1235 'testAPIMethodExistence': testAPIMethodExistence, |
1201 'testChromeExtensionURL': testChromeExtensionURL, | 1236 'testChromeExtensionURL': testChromeExtensionURL, |
1202 'testChromeExtensionRelativePath': testChromeExtensionRelativePath, | 1237 'testChromeExtensionRelativePath': testChromeExtensionRelativePath, |
1203 'testInvalidChromeExtensionURL': testInvalidChromeExtensionURL, | 1238 'testInvalidChromeExtensionURL': testInvalidChromeExtensionURL, |
1204 'testWebRequestAPIExistence': testWebRequestAPIExistence, | 1239 'testWebRequestAPIExistence': testWebRequestAPIExistence, |
(...skipping 29 matching lines...) Expand all Loading... | |
1234 'testLoadAbortChromeExtensionURLWrongPartition': | 1269 'testLoadAbortChromeExtensionURLWrongPartition': |
1235 testLoadAbortChromeExtensionURLWrongPartition, | 1270 testLoadAbortChromeExtensionURLWrongPartition, |
1236 'testLoadAbortEmptyResponse': testLoadAbortEmptyResponse, | 1271 'testLoadAbortEmptyResponse': testLoadAbortEmptyResponse, |
1237 'testLoadAbortIllegalChromeURL': testLoadAbortIllegalChromeURL, | 1272 'testLoadAbortIllegalChromeURL': testLoadAbortIllegalChromeURL, |
1238 'testLoadAbortIllegalFileURL': testLoadAbortIllegalFileURL, | 1273 'testLoadAbortIllegalFileURL': testLoadAbortIllegalFileURL, |
1239 'testLoadAbortIllegalJavaScriptURL': testLoadAbortIllegalJavaScriptURL, | 1274 'testLoadAbortIllegalJavaScriptURL': testLoadAbortIllegalJavaScriptURL, |
1240 'testNavigationToExternalProtocol': testNavigationToExternalProtocol, | 1275 'testNavigationToExternalProtocol': testNavigationToExternalProtocol, |
1241 'testReload': testReload, | 1276 'testReload': testReload, |
1242 'testRemoveWebviewOnExit': testRemoveWebviewOnExit, | 1277 'testRemoveWebviewOnExit': testRemoveWebviewOnExit, |
1243 'testRemoveWebviewAfterNavigation': testRemoveWebviewAfterNavigation, | 1278 'testRemoveWebviewAfterNavigation': testRemoveWebviewAfterNavigation, |
1244 'testResizeWebviewResizesContent': testResizeWebviewResizesContent | 1279 'testResizeWebviewResizesContent': testResizeWebviewResizesContent, |
1280 'testPostMessageCommChannel': testPostMessageCommChannel | |
1245 }; | 1281 }; |
1246 | 1282 |
1247 onload = function() { | 1283 onload = function() { |
1248 chrome.test.getConfig(function(config) { | 1284 chrome.test.getConfig(function(config) { |
1249 embedder.setUp_(config); | 1285 embedder.setUp_(config); |
1250 chrome.test.sendMessage("Launched"); | 1286 chrome.test.sendMessage("Launched"); |
1251 }); | 1287 }); |
1252 }; | 1288 }; |
OLD | NEW |