blob: 5790d3e2273e0c271900c45db27686f6e3121774 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML5 Geo-location test</title>
<link rel="stylesheet" href="/filez/_main/third_party/js/qunit/qunit.css">
<script src="/filez/_main/third_party/js/qunit/qunit.js"></script>
<script src="/filez/_main/third_party/js/qunit/qunit_test_runner.js"></script>
<script type="text/javascript" src="../test_bootstrap.js"></script>
<script type="text/javascript">
goog.require('bot');
goog.require('bot.geolocation');
goog.require('bot.html5');
goog.require('bot.test');
goog.require('bot.userAgent');
goog.require('goog.Promise');
goog.require('goog.labs.userAgent.platform');
goog.require('goog.userAgent');
goog.require('goog.userAgent.product');
</script>
<script type="text/javascript">
// WebDriver does not enable geolocation for Android.
// WebDriver does not enable geolocation for Edge.
// WebDriver does not enable geolocation for Firefox.
// WebDriver does not enable geolocation for IE 9.
// WebDriver does not enable geolocation for Safari.
// Chrome 50+ disables geolocation APIs on insecure origins; see
// https://goo.gl/rStTGz.
var GEOLOCATION_NOT_WORKING =
!bot.html5.isSupported(bot.html5.API.GEOLOCATION) ||
goog.userAgent.product.ANDROID ||
goog.userAgent.product.EDGE ||
goog.userAgent.product.FIREFOX ||
goog.userAgent.product.SAFARI ||
goog.userAgent.product.CHROME ||
// Geolocation is blocked by user consent screen on Chrome for Android.
(goog.labs.userAgent.platform.isAndroid() &&
goog.userAgent.product.CHROME) ||
bot.userAgent.IE_DOC_9;
QUnit.config.testTimeout = 10000; // 10s
/**
* This method checks if the device location
* can be retrieved, i.e. non-null value of Position within the timeout
* period.
*/
QUnit.test('locationWithinDefaultInterval', function(assert) {
if (GEOLOCATION_NOT_WORKING) {
assert.ok(true, 'Skipping: geolocation not working');
return;
}
var done = assert.async();
try {
bot.geolocation.getCurrentPosition(function() {
assert.ok(true, 'Location retrieved');
done();
}, function(error) {
switch (error.code) {
case error.POSITION_UNAVAILABLE:
// Some test machines run on a private ip address range where
// location is not be available, so do not consider this case
// as an error.
assert.ok(true, 'Position unavailable - acceptable');
done();
return;
case error.PERMISSION_DENIED:
assert.ok(false, 'User denied the request for Geolocation.');
done();
return;
case error.TIMEOUT:
assert.ok(false, 'When enabled, location should be known within ' +
(bot.geolocation.DEFAULT_OPTIONS.timeout / 1000) + 's');
done();
return;
default:
assert.ok(false, 'An unknown error occurred. ' + error.message);
done();
return;
}
});
} catch (e) {
assert.strictEqual(e.code, bot.ErrorCode.UNKNOWN_ERROR);
done();
}
});
/**
* Tested with Chrome and Firefox. It checks if the device location cannot
* can be retrieved, i.e. null value of Position, when requested to
* retrieve the position with high accuracy and immediately (no cached).
* Note: Firefox seems to return the position even in this case.
* The HTML5 standard states If the value of the timeout variable is 0,
* invoke the errorCallback (if present) with a new PositionError object
* whose code attribute is set to TIMEOUT.
*/
QUnit.test('locationNoTimeout', function(assert) {
if (GEOLOCATION_NOT_WORKING) {
assert.ok(true, 'Skipping: geolocation not working');
return;
}
var posOptions = {
enableHighAccuracy: true,
maximumAge: 0,
timeout: 0
};
var done = assert.async();
try {
bot.geolocation.getCurrentPosition(
function() {
assert.ok(false, 'Location within 0s timeout interval and 0s max age fails');
done();
},
function() {
assert.ok(true, 'Expected timeout error');
done();
},
posOptions);
} catch (e) {
assert.strictEqual(e.code, bot.ErrorCode.UNKNOWN_ERROR);
done();
}
});
// TODO: Add more tests to check the returned value.
</script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>