Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5504)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/GeolocationTest.java

Issue 2251673002: Add tests for the geolocation prompt with persistence switch on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission-infobar-remember-decision
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 05cc17ca4f9fa9492a74b997dab3091cd2366482..457d73d713e6ebc8964a4c90c63dcf7f09fb9c99 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/GeolocationTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/GeolocationTest.java
@@ -5,10 +5,14 @@
package org.chromium.chrome.browser;
import android.os.Environment;
+import android.support.v7.widget.SwitchCompat;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.Smoke;
+import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
+import org.chromium.chrome.R;
+import org.chromium.chrome.browser.infobar.InfoBar;
import org.chromium.chrome.browser.infobar.InfoBarContainer;
import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab;
@@ -17,10 +21,15 @@ import org.chromium.chrome.test.util.InfoBarTestAnimationListener;
import org.chromium.chrome.test.util.InfoBarUtil;
import org.chromium.chrome.test.util.browser.LocationSettingsTestUtil;
import org.chromium.content.browser.test.util.CallbackHelper;
+import org.chromium.content.browser.test.util.Criteria;
+import org.chromium.content.browser.test.util.CriteriaHelper;
+import org.chromium.content.browser.test.util.TouchCommon;
import org.chromium.device.geolocation.LocationProviderFactory;
import org.chromium.device.geolocation.MockLocationProvider;
import org.chromium.net.test.EmbeddedTestServer;
+import java.util.concurrent.Callable;
+
/**
* Test suite for Geo-Location functionality.
*
@@ -135,6 +144,124 @@ public class GeolocationTest extends ChromeActivityTestCaseBase<ChromeActivity>
tab.removeObserver(updateWaiter);
}
+ /**
+ * Verify Geolocation prompts with a persistence toggle if that feature is enabled. Check the
+ * switch appears and that permission is granted with it toggled on.
+ * @throws Exception
+ */
+ @MediumTest
+ @CommandLineFlags.Add("enable-features=DisplayPersistenceToggleInPermissionPrompts")
+ @Feature({"Location"})
+ public void testGeolocationPersistence() throws Exception {
+ final String url = mTestServer.getURL(TEST_FILE);
+
+ Tab tab = getActivity().getActivityTab();
+ GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter();
+ tab.addObserver(updateWaiter);
+
+ loadUrl(url);
+ runJavaScriptCodeInCurrentTab("initiate_getCurrentPosition()");
+ assertTrue("InfoBar not added.", mListener.addInfoBarAnimationFinished());
+ InfoBar infobar = getInfoBars().get(0);
+ SwitchCompat persistSwitch = (SwitchCompat) infobar.getView().findViewById(
+ R.id.permission_infobar_persist_toggle);
+ assertNotNull(persistSwitch);
+ assertTrue(persistSwitch.isChecked());
+
+ assertTrue("OK button wasn't found", InfoBarUtil.clickPrimaryButton(infobar));
+ updateWaiter.waitForNumUpdates(1);
+
+ tab.removeObserver(updateWaiter);
+ }
+
+ /**
+ * Verify Geolocation prompts with a persistence toggle if that feature is enabled. Check the
+ * switch toggled off.
+ * @throws Exception
+ */
+ @MediumTest
+ @CommandLineFlags.Add("enable-features=DisplayPersistenceToggleInPermissionPrompts")
+ @Feature({"Location"})
+ public void testGeolocationPersistenceOff() throws Exception {
+ final String url = mTestServer.getURL(TEST_FILE);
+
+ Tab tab = getActivity().getActivityTab();
+ GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter();
+ tab.addObserver(updateWaiter);
+
+ loadUrl(url);
+ runJavaScriptCodeInCurrentTab("initiate_getCurrentPosition()");
+ assertTrue("InfoBar not added.", mListener.addInfoBarAnimationFinished());
+ InfoBar infobar = getInfoBars().get(0);
+ SwitchCompat persistSwitch = (SwitchCompat) infobar.getView().findViewById(
+ R.id.permission_infobar_persist_toggle);
+ assertNotNull(persistSwitch);
+ assertTrue(persistSwitch.isChecked());
+
+ // Uncheck the switch
+ TouchCommon.singleClickView(persistSwitch);
+ waitForCheckedState(persistSwitch, false);
+
+ assertTrue("OK button wasn't found", InfoBarUtil.clickPrimaryButton(infobar));
+ updateWaiter.waitForNumUpdates(1);
+
+ // Ask for permission again and make sure it doesn't prompt again (grant is cached in the
+ // blink layer).
+ runJavaScriptCodeInCurrentTab("initiate_getCurrentPosition()");
+ updateWaiter.waitForNumUpdates(2);
+
+ // Ask for permission a third time and make sure it doesn't prompt again.
+ runJavaScriptCodeInCurrentTab("initiate_getCurrentPosition()");
+ updateWaiter.waitForNumUpdates(3);
+
+ tab.removeObserver(updateWaiter);
+ }
+
+ /**
+ * Verify Geolocation prompts once and sends multiple locations with a persistence toggle if
+ * that feature is enabled.
+ * @throws Exception
+ */
+ @MediumTest
+ @CommandLineFlags.Add("enable-features=DisplayPersistenceToggleInPermissionPrompts")
+ @Feature({"Location"})
+ public void testGeolocationWatchPersistenceOff() throws Exception {
+ final String url = mTestServer.getURL(TEST_FILE);
+
+ Tab tab = getActivity().getActivityTab();
+ GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter();
+ tab.addObserver(updateWaiter);
+
+ loadUrl(url);
+ runJavaScriptCodeInCurrentTab("initiate_watchPosition()");
+ assertTrue("InfoBar not added.", mListener.addInfoBarAnimationFinished());
+ InfoBar infobar = getInfoBars().get(0);
+ SwitchCompat persistSwitch = (SwitchCompat) infobar.getView().findViewById(
+ R.id.permission_infobar_persist_toggle);
+ assertNotNull(persistSwitch);
+ assertTrue(persistSwitch.isChecked());
+
+ // Uncheck the switch
+ TouchCommon.singleClickView(persistSwitch);
+ waitForCheckedState(persistSwitch, false);
+
+ // Make sure we get multiple updates without another prompt.
+ assertTrue("OK button wasn't found", InfoBarUtil.clickPrimaryButton(infobar));
+ updateWaiter.waitForNumUpdates(4);
+
+ tab.removeObserver(updateWaiter);
+ }
+
+ private void waitForCheckedState(final SwitchCompat persistSwitch, boolean isChecked)
+ throws InterruptedException {
+ CriteriaHelper.pollUiThread(Criteria.equals(isChecked, new Callable<Boolean>() {
+ @Override
+ public Boolean call() {
+ return persistSwitch.isChecked();
+ }
+ }));
+ }
+
@Override
public void startMainActivity() throws InterruptedException {
startMainActivityOnBlankPage();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698