| Index: chrome/android/javatests/src/org/chromium/chrome/browser/GeolocationTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/GeolocationTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/GeolocationTest.java
|
| index 9515b1a44394f77ba60e5c1468ee5d09a88c9488..ea5182c6cbcfa9fdb97b09bb3b6537a7170b9d6a 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/GeolocationTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/GeolocationTest.java
|
| @@ -4,20 +4,22 @@
|
|
|
| package org.chromium.chrome.browser;
|
|
|
| -import android.test.suitebuilder.annotation.MediumTest;
|
| -import android.test.suitebuilder.annotation.Smoke;
|
| +import android.location.Location;
|
| +import android.test.FlakyTest;
|
|
|
| -import org.chromium.base.test.util.Feature;
|
| +import org.chromium.base.ThreadUtils;
|
| import org.chromium.chrome.browser.infobar.InfoBarContainer;
|
| import org.chromium.chrome.browser.tab.EmptyTabObserver;
|
| import org.chromium.chrome.browser.tab.Tab;
|
| +import org.chromium.chrome.browser.tab.TabObserver;
|
| import org.chromium.chrome.test.ChromeActivityTestCaseBase;
|
| import org.chromium.chrome.test.util.InfoBarTestAnimationListener;
|
| import org.chromium.chrome.test.util.InfoBarUtil;
|
| import org.chromium.chrome.test.util.TestHttpServerClient;
|
| +import org.chromium.content.browser.LocationProviderAdapter;
|
| import org.chromium.content.browser.LocationProviderFactory;
|
| +import org.chromium.content.browser.LocationProviderFactory.LocationProvider;
|
| import org.chromium.content.browser.test.util.CallbackHelper;
|
| -import org.chromium.content.browser.test.util.MockLocationProvider;
|
|
|
| /**
|
| * Test suite for Geo-Location functionality.
|
| @@ -31,34 +33,8 @@
|
| private static final double LATITUDE = 51.01;
|
| private static final double LONGITUDE = 0.23;
|
| private static final float ACCURACY = 10;
|
| - private static final String TEST_FILE = "content/test/data/android/geolocation.html";
|
|
|
| private InfoBarTestAnimationListener mListener;
|
| -
|
| - /**
|
| - * Waits till the geolocation JavaScript callback is called the specified number of times.
|
| - */
|
| - private class GeolocationUpdateWaiter extends EmptyTabObserver {
|
| - private CallbackHelper mCallbackHelper;
|
| - private int mExpectedCount;
|
| -
|
| - public GeolocationUpdateWaiter() {
|
| - mCallbackHelper = new CallbackHelper();
|
| - }
|
| -
|
| - @Override
|
| - public void onTitleUpdated(Tab tab) {
|
| - String expectedTitle = "Count:" + mExpectedCount;
|
| - if (getActivity().getActivityTab().getTitle().equals(expectedTitle)) {
|
| - mCallbackHelper.notifyCalled();
|
| - }
|
| - }
|
| -
|
| - public void waitForNumUpdates(int numUpdates) throws Exception {
|
| - mExpectedCount = numUpdates;
|
| - mCallbackHelper.waitForCallback(0);
|
| - }
|
| - }
|
|
|
| public GeolocationTest() {
|
| super(ChromeActivity.class);
|
| @@ -73,58 +49,143 @@
|
| mListener = new InfoBarTestAnimationListener();
|
| container.setAnimationListener(mListener);
|
|
|
| - LocationProviderFactory.setLocationProviderImpl(new MockLocationProvider());
|
| + LocationProviderFactory.setLocationProviderImpl(new LocationProvider() {
|
| + private boolean mIsRunning;
|
| +
|
| + @Override
|
| + public boolean isRunning() {
|
| + return mIsRunning;
|
| + }
|
| +
|
| + @Override
|
| + public void start(boolean gpsEnabled) {
|
| + mIsRunning = true;
|
| + }
|
| +
|
| + @Override
|
| + public void stop() {
|
| + mIsRunning = false;
|
| + }
|
| + });
|
| }
|
|
|
| /**
|
| * Verify Geolocation creates an InfoBar and receives a mock location.
|
| + *
|
| + * Fails frequently.
|
| + * Bug 141518
|
| + * @Smoke
|
| + * @MediumTest
|
| + * @Feature({"Location", "Main"})
|
| + *
|
| * @throws Exception
|
| */
|
| - @Smoke
|
| - @MediumTest
|
| - @Feature({"Location", "Main"})
|
| + @FlakyTest
|
| public void testGeolocationPlumbing() throws Exception {
|
| final String url = TestHttpServerClient.getUrl(
|
| - "content/test/data/android/geolocation.html");
|
| + "chrome/test/data/geolocation/geolocation_on_load.html");
|
|
|
| Tab tab = getActivity().getActivityTab();
|
| - GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter();
|
| - tab.addObserver(updateWaiter);
|
| -
|
| + final CallbackHelper loadCallback = new CallbackHelper();
|
| + TabObserver observer = new EmptyTabObserver() {
|
| + @Override
|
| + public void onLoadStopped(Tab tab, boolean toDifferentDocument) {
|
| + // If the device has a cached non-mock location, we won't get back our
|
| + // lat/long, so checking that it has "#pass" is sufficient.
|
| + if (tab.getUrl().startsWith(url + "#pass|")) {
|
| + loadCallback.notifyCalled();
|
| + }
|
| + }
|
| + };
|
| + tab.addObserver(observer);
|
| loadUrl(url);
|
| - runJavaScriptCodeInCurrentTab("initiate_getCurrentPosition()");
|
| assertTrue("InfoBar not added.", mListener.addInfoBarAnimationFinished());
|
| assertTrue("OK button wasn't found", InfoBarUtil.clickPrimaryButton(getInfoBars().get(0)));
|
| - updateWaiter.waitForNumUpdates(1);
|
|
|
| - tab.removeObserver(updateWaiter);
|
| + sendLocation(createMockLocation(LATITUDE, LONGITUDE, ACCURACY));
|
| + loadCallback.waitForCallback(0);
|
| + tab.removeObserver(observer);
|
| }
|
|
|
| /**
|
| * Verify Geolocation creates an InfoBar and receives multiple locations.
|
| + *
|
| + * Bug 141518
|
| + * @MediumTest
|
| + * @Feature({"Location"})
|
| + *
|
| * @throws Exception
|
| */
|
| - @MediumTest
|
| - @Feature({"Location"})
|
| + @FlakyTest
|
| public void testGeolocationWatch() throws Exception {
|
| final String url = TestHttpServerClient.getUrl(
|
| - "content/test/data/android/geolocation.html");
|
| + "chrome/test/data/geolocation/geolocation_on_load.html");
|
|
|
| Tab tab = getActivity().getActivityTab();
|
| - GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter();
|
| - tab.addObserver(updateWaiter);
|
| + final CallbackHelper loadCallback0 = new CallbackHelper();
|
| + TabObserver observer = new EmptyTabObserver() {
|
| + @Override
|
| + public void onLoadStopped(Tab tab, boolean toDifferentDocument) {
|
| + // If the device has a cached non-mock location, we won't get back our
|
| + // lat/long, so checking that it has "#pass" is sufficient.
|
| + if (tab.getUrl().startsWith(url + "#pass|0|")) {
|
| + loadCallback0.notifyCalled();
|
| + }
|
| + }
|
| + };
|
| + tab.addObserver(observer);
|
| + loadUrl(url);
|
| + assertTrue("InfoBar not added.", mListener.addInfoBarAnimationFinished());
|
|
|
| - loadUrl(url);
|
| - runJavaScriptCodeInCurrentTab("initiate_watchPosition()");
|
| - assertTrue("InfoBar not added.", mListener.addInfoBarAnimationFinished());
|
| assertTrue("OK button wasn't found", InfoBarUtil.clickPrimaryButton(getInfoBars().get(0)));
|
| - updateWaiter.waitForNumUpdates(2);
|
| + sendLocation(createMockLocation(LATITUDE, LONGITUDE, ACCURACY));
|
| + loadCallback0.waitForCallback(0);
|
| + tab.removeObserver(observer);
|
|
|
| - tab.removeObserver(updateWaiter);
|
| + // Send another location: it'll update the URL again, so increase the count.
|
| + final CallbackHelper loadCallback1 = new CallbackHelper();
|
| + observer = new EmptyTabObserver() {
|
| + @Override
|
| + public void onLoadStopped(Tab tab, boolean toDifferentDocument) {
|
| + // If the device has a cached non-mock location, we won't get back our
|
| + // lat/long, so checking that it has "#pass" is sufficient.
|
| + if (tab.getUrl().startsWith(url + "#pass|1|")) {
|
| + loadCallback1.notifyCalled();
|
| + }
|
| + }
|
| + };
|
| + tab.addObserver(observer);
|
| + sendLocation(createMockLocation(LATITUDE + 1, LONGITUDE - 1, ACCURACY - 1));
|
| + loadCallback1.waitForCallback(0);
|
| + tab.removeObserver(observer);
|
| }
|
|
|
| @Override
|
| public void startMainActivity() throws InterruptedException {
|
| startMainActivityOnBlankPage();
|
| }
|
| +
|
| + private Location createMockLocation(double latitude, double longitude, float accuracy) {
|
| + Location mockLocation = new Location(LOCATION_PROVIDER_MOCK);
|
| + mockLocation.setLatitude(latitude);
|
| + mockLocation.setLongitude(longitude);
|
| + mockLocation.setAccuracy(accuracy);
|
| + mockLocation.setTime(System.currentTimeMillis());
|
| + return mockLocation;
|
| + }
|
| +
|
| + private void sendLocation(final Location location) {
|
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + LocationProviderAdapter.newLocationAvailable(
|
| + location.getLatitude(), location.getLongitude(),
|
| + location.getTime() / 1000.0,
|
| + location.hasAltitude(), location.getAltitude(),
|
| + location.hasAccuracy(), location.getAccuracy(),
|
| + location.hasBearing(), location.getBearing(),
|
| + location.hasSpeed(), location.getSpeed());
|
| + }
|
| + });
|
| + }
|
| }
|
|
|