Index: chrome/test/data/extensions/platform_apps/web_view/geolocation/geolocation_access_guest.html |
diff --git a/chrome/test/data/extensions/platform_apps/web_view/geolocation/geolocation_access_guest.html b/chrome/test/data/extensions/platform_apps/web_view/geolocation/geolocation_access_guest.html |
index 05c42bd61fe66d81dcf142c812563711b6757c4e..2b6e31e99e804045a2b12cb47cb0870f79d43c24 100644 |
--- a/chrome/test/data/extensions/platform_apps/web_view/geolocation/geolocation_access_guest.html |
+++ b/chrome/test/data/extensions/platform_apps/web_view/geolocation/geolocation_access_guest.html |
@@ -14,42 +14,101 @@ |
// The window reference of the embedder to send post message reply. |
var embedderWindowChannel = null; |
+ // Url of the iframe, if set via postMessage, then the guest also loads an |
+ // <iframe>. |
+ var iframeURL; |
+ |
+ var g_testName = 'uninitialized'; |
+ var expectedTotalCallbackCount; |
+ var successCallbackCount; |
+ var totalCallbackCount; |
+ var lastLat = -181; |
+ var lastLng = -181; |
+ var lastLatLng = []; |
+ |
+ var maybeNotifyEmbedder = function() { |
+ console.log('maybeNotifyEmbedder' + |
+ ', expectedTotalCallbackCount: ' + expectedTotalCallbackCount + |
+ ', successCallbackCount: ' + successCallbackCount + |
+ ', totalCallbackCount: ' + totalCallbackCount); |
+ if (expectedTotalCallbackCount == totalCallbackCount) { |
+ var status = (expectedTotalCallbackCount == successCallbackCount) ? |
+ 'access-granted' : 'access-denied'; |
+ var responseArray = [g_testName, status]; |
+ if (lastLat != -181) { |
+ responseArray.push(lastLat); |
+ responseArray.push(lastLng); |
+ } |
+ notifyEmbedder(responseArray); |
+ } |
+ }; |
+ |
var notifyEmbedder = function(msg_array) { |
embedderWindowChannel.postMessage(JSON.stringify(msg_array), '*'); |
}; |
- var onGeolocationSuccess = function(testName, position) { |
- window.console.log('onGeolocationSuccess callback.'); |
- var latitude = position.coords.latitude; |
- var longitude = position.coords.longitude; |
- notifyEmbedder([testName, 'access-granted', latitude, longitude]); |
+ var startTest = function() { |
+ totalCallbackCount = 0; |
+ successCallbackCount = 0; |
+ expectedTotalCallbackCount = 1; |
+ if (iframeURL) { |
+ // The iframe will initiate another geolocation request. |
+ ++expectedTotalCallbackCount; |
+ } |
+ |
+ navigator.geolocation.getCurrentPosition(onGeolocationSuccess, |
+ onGeolocationFailure); |
}; |
- var onGeolocationFailure = function(testName, err) { |
- window.console.log('onGeolocationFailure callback.'); |
- notifyEmbedder([testName, 'access-denied']); |
+ |
+ var onGeolocationSuccess = function(position) { |
+ ++successCallbackCount; |
+ ++totalCallbackCount; |
+ console.log('onGeolocationSuccess, successCallbackCount: ' + |
+ successCallbackCount + |
+ 'totalCallbackCount: ' + totalCallbackCount); |
+ |
+ lastLat = position.coords.latitude; |
+ lastLng = position.coords.longitude; |
+ maybeNotifyEmbedder(); |
+ |
+ if (iframeURL) { |
+ document.querySelector('#iframe-container').innerHTML = |
+ '<iframe src="' + iframeURL + '" ' + |
+ ' width="100" height="100"></iframe>'; |
+ iframeURL = ''; |
+ } |
}; |
- var startTest = function(testName) { |
- navigator.geolocation.getCurrentPosition( |
- onGeolocationSuccess.bind(this, testName), |
- onGeolocationFailure.bind(this, testName)); |
+ var onGeolocationFailure = function(err) { |
+ ++totalCallbackCount; |
+ console.log('onGeolocationFailure, totalCallbackCount: ' + |
+ totalCallbackCount); |
+ maybeNotifyEmbedder(); |
}; |
+ // Callback entry points for the <iframe>. |
+ window['onIframeGeolocationSuccess'] = onGeolocationSuccess; |
+ window['onIframeGeolocationFailure'] = onGeolocationFailure; |
+ |
var onPostMessageReceived = function(e) { |
var data = JSON.parse(e.data); |
if (data[0] == 'check-geolocation-permission') { |
- var testName = data[1]; |
+ g_testName = data[1]; |
+ iframeURL = data[2]; |
embedderWindowChannel = e.source; |
// Start the test once we have |embedderWindowChannel|. |
- startTest(testName); |
+ startTest(); |
} |
}; |
- |
window.addEventListener('message', onPostMessageReceived, false); |
</script> |
</head> |
<body> |
<div>This is a guest that requests geolocation.</div> |
+ <div id="iframe-container"></div> |
+ <script> |
+ console.log('Guest loaded'); |
+ </script> |
</body> |
</html> |