OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser; | 5 package org.chromium.chrome.browser; |
6 | 6 |
| 7 import android.content.DialogInterface; |
| 8 import android.support.v7.app.AlertDialog; |
7 import android.support.v7.widget.SwitchCompat; | 9 import android.support.v7.widget.SwitchCompat; |
| 10 import android.test.suitebuilder.annotation.LargeTest; |
8 import android.test.suitebuilder.annotation.MediumTest; | 11 import android.test.suitebuilder.annotation.MediumTest; |
9 import android.test.suitebuilder.annotation.Smoke; | 12 import android.test.suitebuilder.annotation.Smoke; |
10 | 13 |
| 14 import org.chromium.base.ThreadUtils; |
11 import org.chromium.base.test.util.CallbackHelper; | 15 import org.chromium.base.test.util.CallbackHelper; |
12 import org.chromium.base.test.util.CommandLineFlags; | 16 import org.chromium.base.test.util.CommandLineFlags; |
13 import org.chromium.base.test.util.Feature; | 17 import org.chromium.base.test.util.Feature; |
14 import org.chromium.base.test.util.RetryOnFailure; | 18 import org.chromium.base.test.util.RetryOnFailure; |
15 import org.chromium.chrome.R; | 19 import org.chromium.chrome.R; |
16 import org.chromium.chrome.browser.infobar.InfoBar; | 20 import org.chromium.chrome.browser.infobar.InfoBar; |
17 import org.chromium.chrome.browser.infobar.InfoBarContainer; | 21 import org.chromium.chrome.browser.infobar.InfoBarContainer; |
| 22 import org.chromium.chrome.browser.permissions.PermissionDialogController; |
18 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 23 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
19 import org.chromium.chrome.browser.tab.Tab; | 24 import org.chromium.chrome.browser.tab.Tab; |
20 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 25 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
21 import org.chromium.chrome.test.util.InfoBarTestAnimationListener; | 26 import org.chromium.chrome.test.util.InfoBarTestAnimationListener; |
22 import org.chromium.chrome.test.util.InfoBarUtil; | 27 import org.chromium.chrome.test.util.InfoBarUtil; |
23 import org.chromium.chrome.test.util.browser.LocationSettingsTestUtil; | 28 import org.chromium.chrome.test.util.browser.LocationSettingsTestUtil; |
24 import org.chromium.content.browser.test.util.Criteria; | 29 import org.chromium.content.browser.test.util.Criteria; |
25 import org.chromium.content.browser.test.util.CriteriaHelper; | 30 import org.chromium.content.browser.test.util.CriteriaHelper; |
26 import org.chromium.content.browser.test.util.TouchCommon; | |
27 import org.chromium.device.geolocation.LocationProviderFactory; | 31 import org.chromium.device.geolocation.LocationProviderFactory; |
28 import org.chromium.device.geolocation.MockLocationProvider; | 32 import org.chromium.device.geolocation.MockLocationProvider; |
29 import org.chromium.net.test.EmbeddedTestServer; | 33 import org.chromium.net.test.EmbeddedTestServer; |
30 | 34 |
31 import java.util.concurrent.Callable; | 35 import java.util.concurrent.Callable; |
| 36 import java.util.concurrent.ExecutionException; |
32 | 37 |
33 /** | 38 /** |
34 * Test suite for Geo-Location functionality. | 39 * Test suite for Geo-Location functionality. |
35 * | 40 * |
36 * These tests rely on the device being specially setup (which the bots do autom
atically): | 41 * These tests rely on the device being specially setup (which the bots do autom
atically): |
37 * - Global location is enabled. | 42 * - Global location is enabled. |
38 * - Google location is enabled. | 43 * - Google location is enabled. |
39 */ | 44 */ |
40 @RetryOnFailure | 45 @RetryOnFailure |
41 public class GeolocationTest extends ChromeActivityTestCaseBase<ChromeActivity>
{ | 46 public class GeolocationTest extends ChromeActivityTestCaseBase<ChromeActivity>
{ |
42 private static final String LOCATION_PROVIDER_MOCK = "locationProviderMock"; | 47 private static final String LOCATION_PROVIDER_MOCK = "locationProviderMock"; |
43 private static final double LATITUDE = 51.01; | 48 private static final double LATITUDE = 51.01; |
44 private static final double LONGITUDE = 0.23; | 49 private static final double LONGITUDE = 0.23; |
45 private static final float ACCURACY = 10; | 50 private static final float ACCURACY = 10; |
46 private static final String TEST_FILE = "/content/test/data/android/geolocat
ion.html"; | 51 private static final String TEST_FILE = "/content/test/data/android/geolocat
ion.html"; |
47 | 52 |
| 53 private static final String MODAL_FLAG = "ModalPermissionPrompts"; |
| 54 private static final String TOGGLE_FLAG = "DisplayPersistenceToggleInPermiss
ionPrompts"; |
| 55 private static final String MODAL_TOGGLE_FLAG = MODAL_FLAG + "," + TOGGLE_FL
AG; |
| 56 private static final String NO_GESTURE_FEATURE = |
| 57 "enable-features=ModalPermissionPrompts<ModalPrompts"; |
| 58 private static final String FORCE_FIELDTRIAL = "force-fieldtrials=ModalPromp
ts/Group1"; |
| 59 private static final String FORCE_FIELDTRIAL_PARAMS = |
| 60 "force-fieldtrial-params=ModalPrompts.Group1:require_gesture/false"; |
| 61 |
48 private InfoBarTestAnimationListener mListener; | 62 private InfoBarTestAnimationListener mListener; |
49 private EmbeddedTestServer mTestServer; | 63 private EmbeddedTestServer mTestServer; |
50 | 64 |
51 /** | 65 /** |
52 * Waits till the geolocation JavaScript callback is called the specified nu
mber of times. | 66 * Waits till the geolocation JavaScript callback is called the specified nu
mber of times. |
53 */ | 67 */ |
54 private class GeolocationUpdateWaiter extends EmptyTabObserver { | 68 private class GeolocationUpdateWaiter extends EmptyTabObserver { |
55 private CallbackHelper mCallbackHelper; | 69 private CallbackHelper mCallbackHelper; |
56 private int mExpectedCount; | 70 private int mExpectedCount; |
57 | 71 |
58 public GeolocationUpdateWaiter() { | 72 public GeolocationUpdateWaiter() { |
59 mCallbackHelper = new CallbackHelper(); | 73 mCallbackHelper = new CallbackHelper(); |
60 } | 74 } |
61 | 75 |
62 @Override | 76 @Override |
63 public void onTitleUpdated(Tab tab) { | 77 public void onTitleUpdated(Tab tab) { |
64 String expectedTitle = "Count:" + mExpectedCount; | 78 String expectedTitle = "Count:" + mExpectedCount; |
65 if (getActivity().getActivityTab().getTitle().equals(expectedTitle))
{ | 79 if (getActivity().getActivityTab().getTitle().equals(expectedTitle))
{ |
66 mCallbackHelper.notifyCalled(); | 80 mCallbackHelper.notifyCalled(); |
67 } | 81 } |
68 } | 82 } |
69 | 83 |
70 public void waitForNumUpdates(int numUpdates) throws Exception { | 84 public void waitForNumUpdates(int numUpdates) throws Exception { |
71 mExpectedCount = numUpdates; | 85 mExpectedCount = numUpdates; |
72 mCallbackHelper.waitForCallback(0); | 86 mCallbackHelper.waitForCallback(0); |
73 } | 87 } |
74 } | 88 } |
75 | 89 |
| 90 /** |
| 91 * Criteria class to detect whether the permission dialog is shown. |
| 92 */ |
| 93 private static class DialogShownCriteria extends Criteria { |
| 94 private AlertDialog mDialog; |
| 95 |
| 96 public DialogShownCriteria(String error) { |
| 97 super(error); |
| 98 } |
| 99 |
| 100 public AlertDialog getDialog() { |
| 101 return mDialog; |
| 102 } |
| 103 |
| 104 @Override |
| 105 public boolean isSatisfied() { |
| 106 try { |
| 107 return ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>()
{ |
| 108 @Override |
| 109 public Boolean call() { |
| 110 mDialog = PermissionDialogController.getInstance() |
| 111 .getCurrentDialogForTesting(); |
| 112 return mDialog != null; |
| 113 } |
| 114 }); |
| 115 } catch (ExecutionException e) { |
| 116 return false; |
| 117 } |
| 118 } |
| 119 } |
| 120 |
76 public GeolocationTest() { | 121 public GeolocationTest() { |
77 super(ChromeActivity.class); | 122 super(ChromeActivity.class); |
78 } | 123 } |
79 | 124 |
80 @Override | 125 @Override |
81 protected void setUp() throws Exception { | 126 protected void setUp() throws Exception { |
82 super.setUp(); | 127 super.setUp(); |
83 | 128 |
84 LocationSettingsTestUtil.setSystemLocationSettingEnabled(true); | 129 LocationSettingsTestUtil.setSystemLocationSettingEnabled(true); |
85 | 130 |
86 InfoBarContainer container = | 131 InfoBarContainer container = |
87 getActivity().getTabModelSelector().getCurrentTab().getInfoBarCo
ntainer(); | 132 getActivity().getTabModelSelector().getCurrentTab().getInfoBarCo
ntainer(); |
88 mListener = new InfoBarTestAnimationListener(); | 133 mListener = new InfoBarTestAnimationListener(); |
89 container.setAnimationListener(mListener); | 134 container.setAnimationListener(mListener); |
90 | 135 |
91 LocationProviderFactory.setLocationProviderImpl(new MockLocationProvider
()); | 136 LocationProviderFactory.setLocationProviderImpl(new MockLocationProvider
()); |
92 | 137 |
93 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation
().getContext()); | 138 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation
().getContext()); |
94 } | 139 } |
95 | 140 |
96 @Override | 141 @Override |
97 protected void tearDown() throws Exception { | 142 protected void tearDown() throws Exception { |
98 mTestServer.stopAndDestroyServer(); | 143 mTestServer.stopAndDestroyServer(); |
99 super.tearDown(); | 144 super.tearDown(); |
100 } | 145 } |
101 | 146 |
102 /** | 147 /** |
| 148 * Simulates clicking a button on an AlertDialog. |
| 149 */ |
| 150 private void clickButton(final AlertDialog dialog, final int button) { |
| 151 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 152 @Override |
| 153 public void run() { |
| 154 dialog.getButton(button).performClick(); |
| 155 } |
| 156 }); |
| 157 } |
| 158 |
| 159 /** |
| 160 * Runs a geolocation test that permits location access. |
| 161 * @param updateWaiter The update waiter to wait for callbacks. |
| 162 * @param javascript The JS function to run in the current tab to execute
the test. |
| 163 * @param nUpdates How many updates to wait for. |
| 164 * @param withGeature True if we require a user gesture to trigger the pro
mpt. |
| 165 * @param isDialog True if we are expecting a permission dialog, false
for an infobar. |
| 166 * @param hasSwitch True if we are expecting a persistence switch, false
otherwise. |
| 167 * @param toggleSwitch True if we should toggle the switch off, false other
wise. |
| 168 * @throws Exception |
| 169 */ |
| 170 private void runAllowTest(GeolocationUpdateWaiter updateWaiter, String javas
cript, int nUpdates, |
| 171 boolean withGesture, boolean isDialog, boolean hasSwitch, boolean to
ggleSwitch) |
| 172 throws Exception { |
| 173 final String url = mTestServer.getURL(TEST_FILE); |
| 174 loadUrl(url); |
| 175 |
| 176 if (withGesture) { |
| 177 runJavaScriptCodeInCurrentTab("functionToRun = '" + javascript + "'"
); |
| 178 singleClickView(getActivity().getActivityTab().getView()); |
| 179 } else { |
| 180 runJavaScriptCodeInCurrentTab(javascript); |
| 181 } |
| 182 |
| 183 if (isDialog) { |
| 184 // We need to have a user gesture for the modal to appear. Use a cli
ck listener to |
| 185 // trigger the JavaScript. |
| 186 DialogShownCriteria criteria = new DialogShownCriteria("Dialog not s
hown"); |
| 187 CriteriaHelper.pollInstrumentationThread(criteria); |
| 188 replyToDialogAndWaitForUpdates( |
| 189 updateWaiter, criteria.getDialog(), nUpdates, true, hasSwitc
h, toggleSwitch); |
| 190 } else { |
| 191 replyToInfoBarAndWaitForUpdates(updateWaiter, nUpdates, true, hasSwi
tch, toggleSwitch); |
| 192 } |
| 193 } |
| 194 |
| 195 private void replyToInfoBarAndWaitForUpdates(GeolocationUpdateWaiter updateW
aiter, int nUpdates, |
| 196 boolean allow, boolean hasSwitch, boolean toggleSwitch) throws Excep
tion { |
| 197 assertTrue("InfoBar not added.", mListener.addInfoBarAnimationFinished()
); |
| 198 InfoBar infobar = getInfoBars().get(0); |
| 199 assertNotNull(infobar); |
| 200 |
| 201 if (hasSwitch) { |
| 202 SwitchCompat persistSwitch = (SwitchCompat) infobar.getView().findVi
ewById( |
| 203 R.id.permission_infobar_persist_toggle); |
| 204 assertNotNull(persistSwitch); |
| 205 assertTrue(persistSwitch.isChecked()); |
| 206 if (toggleSwitch) { |
| 207 singleClickView(persistSwitch); |
| 208 waitForCheckedState(persistSwitch, false); |
| 209 } |
| 210 } |
| 211 |
| 212 if (allow) { |
| 213 assertTrue("Allow button wasn't found", InfoBarUtil.clickPrimaryButt
on(infobar)); |
| 214 } else { |
| 215 assertTrue("Block button wasn't found", InfoBarUtil.clickSecondaryBu
tton(infobar)); |
| 216 } |
| 217 updateWaiter.waitForNumUpdates(nUpdates); |
| 218 } |
| 219 |
| 220 private void replyToDialogAndWaitForUpdates(GeolocationUpdateWaiter updateWa
iter, |
| 221 AlertDialog dialog, int nUpdates, boolean allow, boolean hasSwitch, |
| 222 boolean toggleSwitch) throws Exception { |
| 223 if (hasSwitch) { |
| 224 SwitchCompat persistSwitch = |
| 225 (SwitchCompat) dialog.findViewById(R.id.permission_dialog_pe
rsist_toggle); |
| 226 assertNotNull(persistSwitch); |
| 227 assertTrue(persistSwitch.isChecked()); |
| 228 if (toggleSwitch) { |
| 229 singleClickView(persistSwitch); |
| 230 waitForCheckedState(persistSwitch, false); |
| 231 } |
| 232 } |
| 233 |
| 234 if (allow) { |
| 235 clickButton(dialog, DialogInterface.BUTTON_POSITIVE); |
| 236 } else { |
| 237 clickButton(dialog, DialogInterface.BUTTON_NEGATIVE); |
| 238 } |
| 239 updateWaiter.waitForNumUpdates(nUpdates); |
| 240 } |
| 241 |
| 242 private void waitForCheckedState(final SwitchCompat persistSwitch, boolean i
sChecked) |
| 243 throws InterruptedException { |
| 244 CriteriaHelper.pollUiThread(Criteria.equals(isChecked, new Callable<Bool
ean>() { |
| 245 @Override |
| 246 public Boolean call() { |
| 247 return persistSwitch.isChecked(); |
| 248 } |
| 249 })); |
| 250 } |
| 251 |
| 252 /** |
103 * Verify Geolocation creates an InfoBar and receives a mock location. | 253 * Verify Geolocation creates an InfoBar and receives a mock location. |
104 * @throws Exception | 254 * @throws Exception |
105 */ | 255 */ |
106 @Smoke | 256 @Smoke |
107 @MediumTest | 257 @MediumTest |
108 @Feature({"Location", "Main"}) | 258 @Feature({"Location", "Main"}) |
109 public void testGeolocationPlumbing() throws Exception { | 259 public void testGeolocationPlumbingAllowedInfoBar() throws Exception { |
110 final String url = mTestServer.getURL(TEST_FILE); | |
111 | |
112 Tab tab = getActivity().getActivityTab(); | 260 Tab tab = getActivity().getActivityTab(); |
113 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); | 261 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); |
114 tab.addObserver(updateWaiter); | 262 tab.addObserver(updateWaiter); |
115 | 263 runAllowTest(updateWaiter, "initiate_getCurrentPosition()", 1, false, fa
lse, false, false); |
116 loadUrl(url); | |
117 runJavaScriptCodeInCurrentTab("initiate_getCurrentPosition()"); | |
118 assertTrue("InfoBar not added.", mListener.addInfoBarAnimationFinished()
); | |
119 assertTrue("OK button wasn't found", InfoBarUtil.clickPrimaryButton(getI
nfoBars().get(0))); | |
120 updateWaiter.waitForNumUpdates(1); | |
121 | |
122 tab.removeObserver(updateWaiter); | 264 tab.removeObserver(updateWaiter); |
123 } | 265 } |
124 | 266 |
| 267 /** |
| 268 * Verify Geolocation creates a dialog and receives a mock location. |
| 269 * @throws Exception |
| 270 */ |
| 271 @Smoke |
| 272 @MediumTest |
| 273 @CommandLineFlags.Add("enable-features=" + MODAL_FLAG) |
| 274 @Feature({"Location", "Main"}) |
| 275 public void testGeolocationPlumbingAllowedDialog() throws Exception { |
| 276 Tab tab = getActivity().getActivityTab(); |
| 277 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); |
| 278 tab.addObserver(updateWaiter); |
| 279 runAllowTest(updateWaiter, "initiate_getCurrentPosition()", 1, true, tru
e, false, false); |
| 280 tab.removeObserver(updateWaiter); |
| 281 } |
| 282 |
| 283 /** |
| 284 * Verify Geolocation creates a dialog and receives a mock location when dia
logs are explicitly |
| 285 * enabled and permitted to trigger without a gesture. |
| 286 * @throws Exception |
| 287 */ |
| 288 @Smoke |
| 289 @MediumTest |
| 290 @CommandLineFlags.Add({NO_GESTURE_FEATURE, FORCE_FIELDTRIAL, FORCE_FIELDTRIA
L_PARAMS}) |
| 291 @Feature({"Location", "Main"}) |
| 292 public void testGeolocationPlumbingAllowedDialogNoGesture() throws Exception
{ |
| 293 Tab tab = getActivity().getActivityTab(); |
| 294 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); |
| 295 tab.addObserver(updateWaiter); |
| 296 runAllowTest(updateWaiter, "initiate_getCurrentPosition()", 1, false, tr
ue, false, false); |
| 297 tab.removeObserver(updateWaiter); |
| 298 } |
| 299 |
| 300 /** |
| 301 * Verify Geolocation shows an infobar and receives a mock location if the m
odal flag is on but |
| 302 * no user gesture is specified. |
| 303 * @throws Exception |
| 304 */ |
| 305 @Smoke |
| 306 @MediumTest |
| 307 @CommandLineFlags.Add("enable-features=" + MODAL_FLAG) |
| 308 @Feature({"Location", "Main"}) |
| 309 public void testGeolocationPlumbingAllowedNoGestureShowsInfoBar() throws Exc
eption { |
| 310 Tab tab = getActivity().getActivityTab(); |
| 311 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); |
| 312 tab.addObserver(updateWaiter); |
| 313 runAllowTest(updateWaiter, "initiate_getCurrentPosition()", 1, false, fa
lse, false, false); |
| 314 tab.removeObserver(updateWaiter); |
| 315 } |
| 316 |
125 /** | 317 /** |
126 * Verify Geolocation creates an InfoBar and receives multiple locations. | 318 * Verify Geolocation creates an InfoBar and receives multiple locations. |
127 * @throws Exception | 319 * @throws Exception |
128 */ | 320 */ |
129 @MediumTest | 321 @MediumTest |
130 @Feature({"Location"}) | 322 @Feature({"Location"}) |
131 public void testGeolocationWatch() throws Exception { | 323 public void testGeolocationWatchInfoBar() throws Exception { |
132 final String url = mTestServer.getURL(TEST_FILE); | |
133 | |
134 Tab tab = getActivity().getActivityTab(); | 324 Tab tab = getActivity().getActivityTab(); |
135 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); | 325 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); |
136 tab.addObserver(updateWaiter); | 326 tab.addObserver(updateWaiter); |
137 | 327 runAllowTest(updateWaiter, "initiate_watchPosition()", 2, false, false,
false, false); |
138 loadUrl(url); | |
139 runJavaScriptCodeInCurrentTab("initiate_watchPosition()"); | |
140 assertTrue("InfoBar not added.", mListener.addInfoBarAnimationFinished()
); | |
141 assertTrue("OK button wasn't found", InfoBarUtil.clickPrimaryButton(getI
nfoBars().get(0))); | |
142 updateWaiter.waitForNumUpdates(2); | |
143 | |
144 tab.removeObserver(updateWaiter); | 328 tab.removeObserver(updateWaiter); |
145 } | 329 } |
146 | 330 |
147 /** | 331 /** |
148 * Verify Geolocation prompts with a persistence toggle if that feature is e
nabled. Check the | 332 * Verify Geolocation creates a dialog and receives multiple locations. |
149 * switch appears and that permission is granted with it toggled on. | |
150 * @throws Exception | 333 * @throws Exception |
151 */ | 334 */ |
152 @MediumTest | 335 @MediumTest |
153 @CommandLineFlags.Add("enable-features=DisplayPersistenceToggleInPermissionP
rompts") | 336 @CommandLineFlags.Add("enable-features=" + MODAL_FLAG) |
154 @Feature({"Location"}) | 337 @Feature({"Location"}) |
155 public void testGeolocationPersistence() throws Exception { | 338 public void testGeolocationWatchDialog() throws Exception { |
156 final String url = mTestServer.getURL(TEST_FILE); | |
157 | |
158 Tab tab = getActivity().getActivityTab(); | 339 Tab tab = getActivity().getActivityTab(); |
159 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); | 340 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); |
160 tab.addObserver(updateWaiter); | 341 tab.addObserver(updateWaiter); |
161 | 342 runAllowTest(updateWaiter, "initiate_watchPosition()", 2, true, true, fa
lse, false); |
162 loadUrl(url); | |
163 runJavaScriptCodeInCurrentTab("initiate_getCurrentPosition()"); | |
164 assertTrue("InfoBar not added.", mListener.addInfoBarAnimationFinished()
); | |
165 InfoBar infobar = getInfoBars().get(0); | |
166 SwitchCompat persistSwitch = (SwitchCompat) infobar.getView().findViewBy
Id( | |
167 R.id.permission_infobar_persist_toggle); | |
168 assertNotNull(persistSwitch); | |
169 assertTrue(persistSwitch.isChecked()); | |
170 | |
171 assertTrue("OK button wasn't found", InfoBarUtil.clickPrimaryButton(info
bar)); | |
172 updateWaiter.waitForNumUpdates(1); | |
173 | |
174 tab.removeObserver(updateWaiter); | 343 tab.removeObserver(updateWaiter); |
175 } | 344 } |
176 | 345 |
177 /** | 346 /** |
178 * Verify Geolocation prompts with a persistence toggle if that feature is e
nabled. Check the | 347 * Verify Geolocation creates an infobar with a persistence toggle if that f
eature is enabled. |
179 * switch toggled off. | 348 * Check the switch appears and that permission is granted with it toggled o
n. |
180 * @throws Exception | 349 * @throws Exception |
181 */ | 350 */ |
182 @MediumTest | 351 @MediumTest |
183 @CommandLineFlags.Add("enable-features=DisplayPersistenceToggleInPermissionP
rompts") | 352 @CommandLineFlags.Add("enable-features=" + TOGGLE_FLAG) |
184 @Feature({"Location"}) | 353 @Feature({"Location"}) |
185 public void testGeolocationPersistenceOff() throws Exception { | 354 public void testGeolocationPersistenceAllowedInfoBar() throws Exception { |
186 final String url = mTestServer.getURL(TEST_FILE); | |
187 | |
188 Tab tab = getActivity().getActivityTab(); | 355 Tab tab = getActivity().getActivityTab(); |
189 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); | 356 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); |
190 tab.addObserver(updateWaiter); | 357 tab.addObserver(updateWaiter); |
| 358 runAllowTest(updateWaiter, "initiate_getCurrentPosition()", 1, false, fa
lse, true, false); |
| 359 tab.removeObserver(updateWaiter); |
| 360 } |
191 | 361 |
192 loadUrl(url); | 362 /** |
193 runJavaScriptCodeInCurrentTab("initiate_getCurrentPosition()"); | 363 * Verify Geolocation creates a dialog with a persistence toggle if both fea
tures are enabled. |
194 assertTrue("InfoBar not added.", mListener.addInfoBarAnimationFinished()
); | 364 * Check the switch appears and that permission is granted with it toggled o
n. |
195 InfoBar infobar = getInfoBars().get(0); | 365 * @throws Exception |
196 SwitchCompat persistSwitch = (SwitchCompat) infobar.getView().findViewBy
Id( | 366 */ |
197 R.id.permission_infobar_persist_toggle); | 367 @MediumTest |
198 assertNotNull(persistSwitch); | 368 @CommandLineFlags.Add("enable-features=" + MODAL_TOGGLE_FLAG) |
199 assertTrue(persistSwitch.isChecked()); | 369 @Feature({"Location"}) |
| 370 public void testGeolocationPersistenceAllowedDialog() throws Exception { |
| 371 Tab tab = getActivity().getActivityTab(); |
| 372 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); |
| 373 tab.addObserver(updateWaiter); |
| 374 runAllowTest(updateWaiter, "initiate_getCurrentPosition()", 1, true, tru
e, true, false); |
| 375 tab.removeObserver(updateWaiter); |
| 376 } |
200 | 377 |
201 // Uncheck the switch | 378 /** |
202 TouchCommon.singleClickView(persistSwitch); | 379 * Verify Geolocation creates an infobar with a persistence toggle if that f
eature is enabled. |
203 waitForCheckedState(persistSwitch, false); | 380 * Check the switch toggled off. |
204 | 381 * @throws Exception |
205 assertTrue("OK button wasn't found", InfoBarUtil.clickPrimaryButton(info
bar)); | 382 */ |
206 updateWaiter.waitForNumUpdates(1); | 383 @MediumTest |
| 384 @CommandLineFlags.Add("enable-features=" + TOGGLE_FLAG) |
| 385 @Feature({"Location"}) |
| 386 public void testGeolocationPersistenceOffAllowedInfoBar() throws Exception { |
| 387 Tab tab = getActivity().getActivityTab(); |
| 388 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); |
| 389 tab.addObserver(updateWaiter); |
| 390 runAllowTest(updateWaiter, "initiate_getCurrentPosition()", 1, false, fa
lse, true, true); |
207 | 391 |
208 // Ask for permission again and make sure it doesn't prompt again (grant
is cached in the | 392 // Ask for permission again and make sure it doesn't prompt again (grant
is cached in the |
209 // blink layer). | 393 // Blink layer). |
210 runJavaScriptCodeInCurrentTab("initiate_getCurrentPosition()"); | 394 runJavaScriptCodeInCurrentTab("initiate_getCurrentPosition()"); |
211 updateWaiter.waitForNumUpdates(2); | 395 updateWaiter.waitForNumUpdates(2); |
212 | 396 |
213 // Ask for permission a third time and make sure it doesn't prompt again
. | 397 // Ask for permission a third time and make sure it doesn't prompt again
. |
214 runJavaScriptCodeInCurrentTab("initiate_getCurrentPosition()"); | 398 runJavaScriptCodeInCurrentTab("initiate_getCurrentPosition()"); |
215 updateWaiter.waitForNumUpdates(3); | 399 updateWaiter.waitForNumUpdates(3); |
216 | 400 |
217 tab.removeObserver(updateWaiter); | 401 tab.removeObserver(updateWaiter); |
218 } | 402 } |
219 | 403 |
220 /** | 404 /** |
| 405 * Verify Geolocation creates a dialog with a persistence toggle if that fea
ture is enabled. |
| 406 * Check the switch toggled off. |
| 407 * @throws Exception |
| 408 */ |
| 409 @MediumTest |
| 410 @CommandLineFlags.Add("enable-features=" + MODAL_TOGGLE_FLAG) |
| 411 @Feature({"Location"}) |
| 412 public void testGeolocationPersistenceOffAllowedDialog() throws Exception { |
| 413 Tab tab = getActivity().getActivityTab(); |
| 414 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); |
| 415 tab.addObserver(updateWaiter); |
| 416 runAllowTest(updateWaiter, "initiate_getCurrentPosition()", 1, true, tru
e, true, true); |
| 417 |
| 418 // Ask for permission again and make sure it doesn't prompt again (grant
is cached in the |
| 419 // Blink layer). |
| 420 singleClickView(getActivity().getActivityTab().getView()); |
| 421 updateWaiter.waitForNumUpdates(2); |
| 422 |
| 423 // Ask for permission a third time and make sure it doesn't prompt again
. |
| 424 singleClickView(getActivity().getActivityTab().getView()); |
| 425 updateWaiter.waitForNumUpdates(3); |
| 426 |
| 427 tab.removeObserver(updateWaiter); |
| 428 } |
| 429 |
| 430 /** |
221 * Verify Geolocation prompts once and sends multiple locations with a persi
stence toggle if | 431 * Verify Geolocation prompts once and sends multiple locations with a persi
stence toggle if |
222 * that feature is enabled. | 432 * that feature is enabled. Use an infobar. |
223 * @throws Exception | 433 * @throws Exception |
224 */ | 434 */ |
225 @MediumTest | 435 @LargeTest |
226 @CommandLineFlags.Add("enable-features=DisplayPersistenceToggleInPermissionP
rompts") | 436 @CommandLineFlags.Add("enable-features=" + TOGGLE_FLAG) |
227 @Feature({"Location"}) | 437 @Feature({"Location"}) |
228 public void testGeolocationWatchPersistenceOff() throws Exception { | 438 public void testGeolocationWatchPersistenceOffAllowedInfoBar() throws Except
ion { |
229 final String url = mTestServer.getURL(TEST_FILE); | |
230 | |
231 Tab tab = getActivity().getActivityTab(); | 439 Tab tab = getActivity().getActivityTab(); |
232 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); | 440 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); |
233 tab.addObserver(updateWaiter); | 441 tab.addObserver(updateWaiter); |
234 | 442 runAllowTest(updateWaiter, "initiate_watchPosition()", 2, false, false,
true, true); |
235 loadUrl(url); | |
236 runJavaScriptCodeInCurrentTab("initiate_watchPosition()"); | |
237 assertTrue("InfoBar not added.", mListener.addInfoBarAnimationFinished()
); | |
238 InfoBar infobar = getInfoBars().get(0); | |
239 SwitchCompat persistSwitch = (SwitchCompat) infobar.getView().findViewBy
Id( | |
240 R.id.permission_infobar_persist_toggle); | |
241 assertNotNull(persistSwitch); | |
242 assertTrue(persistSwitch.isChecked()); | |
243 | |
244 // Uncheck the switch | |
245 TouchCommon.singleClickView(persistSwitch); | |
246 waitForCheckedState(persistSwitch, false); | |
247 | |
248 // Make sure we get multiple updates without another prompt. | |
249 assertTrue("OK button wasn't found", InfoBarUtil.clickPrimaryButton(info
bar)); | |
250 updateWaiter.waitForNumUpdates(4); | |
251 | |
252 tab.removeObserver(updateWaiter); | 443 tab.removeObserver(updateWaiter); |
253 } | 444 } |
254 | 445 |
255 private void waitForCheckedState(final SwitchCompat persistSwitch, boolean i
sChecked) | 446 /** |
256 throws InterruptedException { | 447 * Verify Geolocation prompts once and sends multiple locations with a persi
stence toggle if |
257 CriteriaHelper.pollUiThread(Criteria.equals(isChecked, new Callable<Bool
ean>() { | 448 * that feature is enabled. Use a dialog. |
258 @Override | 449 * @throws Exception |
259 public Boolean call() { | 450 */ |
260 return persistSwitch.isChecked(); | 451 @LargeTest |
261 } | 452 @CommandLineFlags.Add("enable-features=" + MODAL_TOGGLE_FLAG) |
262 })); | 453 @Feature({"Location"}) |
| 454 public void testGeolocationWatchPersistenceOffAllowedDialog() throws Excepti
on { |
| 455 Tab tab = getActivity().getActivityTab(); |
| 456 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); |
| 457 tab.addObserver(updateWaiter); |
| 458 runAllowTest(updateWaiter, "initiate_watchPosition()", 2, true, true, tr
ue, true); |
| 459 tab.removeObserver(updateWaiter); |
263 } | 460 } |
264 | 461 |
265 @Override | 462 @Override |
266 public void startMainActivity() throws InterruptedException { | 463 public void startMainActivity() throws InterruptedException { |
267 startMainActivityOnBlankPage(); | 464 startMainActivityOnBlankPage(); |
268 } | 465 } |
269 } | 466 } |
OLD | NEW |