Commit 7eebce26 authored by Erik Luo's avatar Erik Luo Committed by Commit Bot

DevTools: fix clearing of geolocation override

The EmulationAgent can clear the existing geolocation override.
In the original implementation, it resets the geoposition_override_
https://codereview.chromium.org/603323004

During a later refactoring, it looks like this line was dropped
which led to newly created impls that reused the old override even
after it should have been cleared.
https://codereview.chromium.org/628773003

Bug: 639344
Change-Id: I0a76aa60b70265fc604fc87d68566ff815878433
Reviewed-on: https://chromium-review.googlesource.com/823276
Commit-Queue: Erik Luo <luoe@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524482}
parent ecef9073
......@@ -48,6 +48,7 @@ void GeolocationContext::SetOverride(mojom::GeopositionPtr geoposition) {
}
void GeolocationContext::ClearOverride() {
geoposition_override_.reset();
for (auto& impl : impls_) {
impl->ClearOverride();
}
......
......@@ -17,5 +17,8 @@ Running: testInvalidGeolocation
geolocation-emulation-tests.js:41 Latitude: 50 Longitude: 100
Running: testTimestampOfOverridenPosition
geolocation-emulation-tests.js:59 PASSED
geolocation-emulation-tests.js:79 PASSED
Running: testNoOverride
Override was cleared correctly.
......@@ -51,6 +51,26 @@
navigator.geolocation.getCurrentPosition(testSuccess, testFailed);
}
function getPositionPromise()
{
return new Promise((resolve, reject) => {
function testSuccess(position)
{
if (position && position.coords)
resolve("Latitude: " + position.coords.latitude + " Longitude: " + position.coords.longitude);
else
resolve("Unexpected error occured. Test failed.");
}
function testFailed(error)
{
resolve(serializeGeolocationError(error));
}
navigator.geolocation.getCurrentPosition(testSuccess, testFailed);
});
}
function overridenTimestampGeolocation()
{
function testSuccess(position)
......@@ -78,10 +98,18 @@
});
}
var positionBeforeOverride;
TestRunner.runTestSuite([
function testPermissionGranted(next) {
consoleSniffAndDump(next);
consoleSniffAndDump(savePositionBeforeOverride);
TestRunner.evaluateInPage('grantGeolocationPermission()');
async function savePositionBeforeOverride() {
positionBeforeOverride = await TestRunner.evaluateInPageAsync('getPositionPromise()');
Console.ConsoleView.clearConsole();
next();
}
},
function testGeolocationUnavailable(next) {
......@@ -112,5 +140,15 @@
consoleSniffAndDump(next);
TestRunner.evaluateInPage('overridenTimestampGeolocation()');
},
async function testNoOverride(next) {
TestRunner.EmulationAgent.clearGeolocationOverride();
var positionString = await TestRunner.evaluateInPageAsync('getPositionPromise()');
if (positionString === positionBeforeOverride)
TestRunner.addResult('Override was cleared correctly.');
else
TestRunner.addResult('Position differs from value before override.');
next();
}
]);
})();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment