Chromium Code Reviews| Index: chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/geo/GeolocationHeaderTest.java |
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/geo/GeolocationHeaderTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/geo/GeolocationHeaderTest.java |
| index 0e64155338abb55ecb4be26d69d8ec5dd0b7d9ab..8f585994beb85083b288051ca6ff15a77d0d8930 100644 |
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/geo/GeolocationHeaderTest.java |
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/omnibox/geo/GeolocationHeaderTest.java |
| @@ -13,10 +13,12 @@ import android.support.test.filters.SmallTest; |
| import org.chromium.base.ContextUtils; |
| import org.chromium.base.ThreadUtils; |
| import org.chromium.base.library_loader.ProcessInitException; |
| +import org.chromium.base.test.util.CommandLineFlags; |
| import org.chromium.base.test.util.Feature; |
| import org.chromium.chrome.browser.ChromeActivity; |
| import org.chromium.chrome.browser.preferences.website.ContentSetting; |
| import org.chromium.chrome.browser.preferences.website.GeolocationInfo; |
| +import org.chromium.chrome.browser.preferences.website.WebsitePreferenceBridge; |
| import org.chromium.chrome.browser.tab.Tab; |
| import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
| @@ -26,6 +28,10 @@ import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
| public class GeolocationHeaderTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
| private static final String SEARCH_URL_1 = "https://www.google.com/search?q=potatoes"; |
| private static final String SEARCH_URL_2 = "https://www.google.co.jp/webhp?#q=dinosaurs"; |
| + private static final String ENABLE_CONSISTENT_GEOLOCATION_GEATURE = |
|
raymes
2017/01/10 03:19:32
nit: GESTURE?
benwells
2017/01/11 05:35:32
Oops, FEATURE actually. Fixed.
|
| + "enable-features=ConsistentOmniboxGeolocation"; |
| + private static final String DISABLE_CONSISTENT_GEOLOCATION_GEATURE = |
|
raymes
2017/01/10 03:19:32
nit: GESTURE?
benwells
2017/01/11 05:35:32
Done.
|
| + "disable-features=ConsistentOmniboxGeolocation"; |
| public GeolocationHeaderTest() { |
| super(ChromeActivity.class); |
| @@ -33,6 +39,7 @@ public class GeolocationHeaderTest extends ChromeActivityTestCaseBase<ChromeActi |
| @SmallTest |
| @Feature({"Location"}) |
| + @CommandLineFlags.Add(DISABLE_CONSISTENT_GEOLOCATION_GEATURE) |
| public void testGeolocationHeader() throws ProcessInitException { |
| setMockLocation(20.3, 155.8, System.currentTimeMillis()); |
| @@ -52,7 +59,38 @@ public class GeolocationHeaderTest extends ChromeActivityTestCaseBase<ChromeActi |
| // X-Geo shouldn't be sent over HTTP. |
| assertNullHeader("http://www.google.com/search?q=potatoes", false); |
| assertNullHeader("http://www.google.com/webhp?#q=dinosaurs", false); |
| + } |
| + |
| + @SmallTest |
| + @Feature({"Location"}) |
| + @CommandLineFlags.Add(ENABLE_CONSISTENT_GEOLOCATION_GEATURE) |
| + public void testConsistentHeader() throws ProcessInitException { |
| + setMockLocation(20.3, 155.8, System.currentTimeMillis()); |
| + |
| + // X-Geo should be sent for Google search results page URLs. |
| + assertNonNullHeader(SEARCH_URL_1, false); |
| + |
| + // But only the current CCTLD. |
| + assertNullHeader(SEARCH_URL_2, false); |
| + |
| + // X-Geo shouldn't be sent in incognito mode. |
| + assertNullHeader(SEARCH_URL_1, true); |
| + assertNullHeader(SEARCH_URL_2, true); |
| + |
| + // X-Geo shouldn't be sent with URLs that aren't the Google search results page. |
| + assertNullHeader("invalid$url", false); |
| + assertNullHeader("https://www.chrome.fr/", false); |
| + assertNullHeader("https://www.google.com/", false); |
| + |
| + // X-Geo shouldn't be sent over HTTP. |
| + assertNullHeader("http://www.google.com/search?q=potatoes", false); |
| + assertNullHeader("http://www.google.com/webhp?#q=dinosaurs", false); |
| + } |
| + @SmallTest |
| + @Feature({"Location"}) |
| + @CommandLineFlags.Add(DISABLE_CONSISTENT_GEOLOCATION_GEATURE) |
| + public void testPermissions() throws ProcessInitException { |
| // X-Geo shouldn't be sent when location is disallowed for https origin. |
| // If https origin doesn't have a location setting, fall back to value for http origin. |
| checkHeaderWithPermissions(ContentSetting.ALLOW, ContentSetting.ALLOW, false); |
| @@ -64,7 +102,24 @@ public class GeolocationHeaderTest extends ChromeActivityTestCaseBase<ChromeActi |
| checkHeaderWithPermissions(ContentSetting.BLOCK, ContentSetting.ALLOW, true); |
| checkHeaderWithPermissions(ContentSetting.BLOCK, ContentSetting.DEFAULT, true); |
| checkHeaderWithPermissions(ContentSetting.BLOCK, ContentSetting.BLOCK, true); |
| + } |
| + @SmallTest |
| + @Feature({"Location"}) |
| + @CommandLineFlags.Add(ENABLE_CONSISTENT_GEOLOCATION_GEATURE) |
| + public void testPermissionAndSetting() throws ProcessInitException { |
| + // X-Geo shouldn't be sent when location is disallowed for the origin, or when the DSE |
| + // geolocation setting is off. |
| + checkHeaderWithPermissionAndSetting(ContentSetting.ALLOW, true, false); |
| + checkHeaderWithPermissionAndSetting(ContentSetting.DEFAULT, true, false); |
| + checkHeaderWithPermissionAndSetting(ContentSetting.DEFAULT, false, true); |
| + checkHeaderWithPermissionAndSetting(ContentSetting.BLOCK, false, true); |
| + } |
| + |
| + @SmallTest |
| + @Feature({"Location"}) |
| + @CommandLineFlags.Add(DISABLE_CONSISTENT_GEOLOCATION_GEATURE) |
| + public void testOnlyNonStale() throws ProcessInitException { |
| // X-Geo should be sent only with non-stale locations. |
| long now = System.currentTimeMillis(); |
| long oneHour = 60 * 60 * 1000; |
| @@ -94,6 +149,22 @@ public class GeolocationHeaderTest extends ChromeActivityTestCaseBase<ChromeActi |
| }); |
| } |
| + private void checkHeaderWithPermissionAndSetting(final ContentSetting httpsPermission, |
| + final boolean settingValue, final boolean shouldBeNull) { |
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| + @Override |
| + public void run() { |
| + GeolocationInfo infoHttps = |
| + new GeolocationInfo(SEARCH_URL_1, null, false); |
| + infoHttps.setContentSetting(httpsPermission); |
| + WebsitePreferenceBridge.nativeSetDSEGeolocationSetting(settingValue); |
| + String header = GeolocationHeader.getGeoHeader(ContextUtils.getApplicationContext(), |
| + SEARCH_URL_1, getActivity().getActivityTab()); |
| + assertHeaderState(header, shouldBeNull); |
| + } |
| + }); |
| + } |
| + |
| private void checkHeaderWithLocation(final double latitute, final double longitude, |
| final long time, final boolean shouldBeNull) { |
| ThreadUtils.runOnUiThreadBlocking(new Runnable() { |