Commit a5cce3fa authored by Andy Paicu's avatar Andy Paicu Committed by Commit Bot

Correctly mock geolocation for some flaky tests

This is an "educated guess" fix for flaky tests that I was unable to
reproduce locally.

Bug: 1092176, 1094585
Change-Id: I2789c903b96443b7004f578dff14b8e6ac522c11
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2257326Reviewed-by: default avatarAndy Paicu <andypaicu@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Commit-Queue: Andy Paicu <andypaicu@chromium.org>
Commit-Queue: Balazs Engedy <engedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780863}
parent 033395fd
...@@ -29,6 +29,7 @@ import org.chromium.chrome.browser.flags.ChromeSwitches; ...@@ -29,6 +29,7 @@ import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.permissions.PermissionTestRule.PermissionUpdateWaiter; import org.chromium.chrome.browser.permissions.PermissionTestRule.PermissionUpdateWaiter;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.LocationSettingsTestUtil;
import org.chromium.components.offline_items_collection.ContentId; import org.chromium.components.offline_items_collection.ContentId;
import org.chromium.components.permissions.R; import org.chromium.components.permissions.R;
import org.chromium.content_public.browser.test.util.Criteria; import org.chromium.content_public.browser.test.util.Criteria;
...@@ -155,6 +156,11 @@ public class RuntimePermissionTest { ...@@ -155,6 +156,11 @@ public class RuntimePermissionTest {
}); });
} }
private void setupGeolocationSystemMock() {
LocationSettingsTestUtil.setSystemLocationSettingEnabled(true);
LocationProviderOverrider.setLocationProviderImpl(new MockLocationProvider());
}
/** /**
* Run a test related to the runtime permission prompt, based on the specified parameters. * Run a test related to the runtime permission prompt, based on the specified parameters.
* @param testUrl The URL of the test page to load in order to run the text. * @param testUrl The URL of the test page to load in order to run the text.
...@@ -235,7 +241,7 @@ public class RuntimePermissionTest { ...@@ -235,7 +241,7 @@ public class RuntimePermissionTest {
@MediumTest @MediumTest
@Feature({"RuntimePermissions", "Location"}) @Feature({"RuntimePermissions", "Location"})
public void testAllowRuntimeLocation() throws Exception { public void testAllowRuntimeLocation() throws Exception {
LocationProviderOverrider.setLocationProviderImpl(new MockLocationProvider()); setupGeolocationSystemMock();
runTest(GEOLOCATION_TEST, true /* expectPermissionAllowed */, runTest(GEOLOCATION_TEST, true /* expectPermissionAllowed */,
true /* permissionPromptAllow */, RuntimePromptResponse.GRANT, true /* permissionPromptAllow */, RuntimePromptResponse.GRANT,
...@@ -272,7 +278,7 @@ public class RuntimePermissionTest { ...@@ -272,7 +278,7 @@ public class RuntimePermissionTest {
@MediumTest @MediumTest
@Feature({"RuntimePermissions", "Location"}) @Feature({"RuntimePermissions", "Location"})
public void testDenyRuntimeLocation() throws Exception { public void testDenyRuntimeLocation() throws Exception {
LocationProviderOverrider.setLocationProviderImpl(new MockLocationProvider()); setupGeolocationSystemMock();
runTest(GEOLOCATION_TEST, false /* expectPermissionAllowed */, runTest(GEOLOCATION_TEST, false /* expectPermissionAllowed */,
true /* permissionPromptAllow */, RuntimePromptResponse.DENY, true /* permissionPromptAllow */, RuntimePromptResponse.DENY,
...@@ -343,7 +349,7 @@ public class RuntimePermissionTest { ...@@ -343,7 +349,7 @@ public class RuntimePermissionTest {
@MediumTest @MediumTest
@Feature({"RuntimePermissions", "Location"}) @Feature({"RuntimePermissions", "Location"})
public void testDenyTriggersNoRuntime() throws Exception { public void testDenyTriggersNoRuntime() throws Exception {
LocationProviderOverrider.setLocationProviderImpl(new MockLocationProvider()); setupGeolocationSystemMock();
runTest(GEOLOCATION_TEST, false /* expectPermissionAllowed */, runTest(GEOLOCATION_TEST, false /* expectPermissionAllowed */,
false /* permissionPromptAllow */, RuntimePromptResponse.ASSERT_NEVER_ASKED, false /* permissionPromptAllow */, RuntimePromptResponse.ASSERT_NEVER_ASKED,
...@@ -400,7 +406,7 @@ public class RuntimePermissionTest { ...@@ -400,7 +406,7 @@ public class RuntimePermissionTest {
@MediumTest @MediumTest
@Feature({"RuntimePermissions", "Location"}) @Feature({"RuntimePermissions", "Location"})
public void testAlreadyGrantedRuntimeLocation() throws Exception { public void testAlreadyGrantedRuntimeLocation() throws Exception {
LocationProviderOverrider.setLocationProviderImpl(new MockLocationProvider()); setupGeolocationSystemMock();
runTest(GEOLOCATION_TEST, true /* expectPermissionAllowed */, runTest(GEOLOCATION_TEST, true /* expectPermissionAllowed */,
true /* permissionPromptAllow */, RuntimePromptResponse.ALREADY_GRANTED, true /* permissionPromptAllow */, RuntimePromptResponse.ALREADY_GRANTED,
...@@ -414,7 +420,7 @@ public class RuntimePermissionTest { ...@@ -414,7 +420,7 @@ public class RuntimePermissionTest {
@MediumTest @MediumTest
@Feature({"RuntimePermissions", "Location"}) @Feature({"RuntimePermissions", "Location"})
public void testAllowRuntimeLocationIncognito() throws Exception { public void testAllowRuntimeLocationIncognito() throws Exception {
LocationProviderOverrider.setLocationProviderImpl(new MockLocationProvider()); setupGeolocationSystemMock();
mPermissionTestRule.newIncognitoTabFromMenu(); mPermissionTestRule.newIncognitoTabFromMenu();
runTest(GEOLOCATION_TEST, true /* expectPermissionAllowed */, runTest(GEOLOCATION_TEST, true /* expectPermissionAllowed */,
......
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