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 private class DialogShownCriteria extends Criteria { | |
91 private AlertDialog mDialog; | |
92 | |
93 public DialogShownCriteria(String error) { | |
94 super(error); | |
95 } | |
96 | |
97 public AlertDialog getDialog() { | |
98 return mDialog; | |
99 } | |
100 | |
101 @Override | |
102 public boolean isSatisfied() { | |
103 try { | |
104 return ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>() { | |
105 @Override | |
106 public Boolean call() { | |
107 mDialog = PermissionDialogController.getInstance() | |
108 .getCurrentDialogForTesting(); | |
109 return mDialog != null; | |
110 } | |
111 }); | |
112 } catch (ExecutionException e) { | |
113 return false; | |
114 } | |
115 } | |
116 } | |
117 | |
76 public GeolocationTest() { | 118 public GeolocationTest() { |
77 super(ChromeActivity.class); | 119 super(ChromeActivity.class); |
78 } | 120 } |
79 | 121 |
80 @Override | 122 @Override |
81 protected void setUp() throws Exception { | 123 protected void setUp() throws Exception { |
82 super.setUp(); | 124 super.setUp(); |
83 | 125 |
84 LocationSettingsTestUtil.setSystemLocationSettingEnabled(true); | 126 LocationSettingsTestUtil.setSystemLocationSettingEnabled(true); |
85 | 127 |
86 InfoBarContainer container = | 128 InfoBarContainer container = |
87 getActivity().getTabModelSelector().getCurrentTab().getInfoBarCo ntainer(); | 129 getActivity().getTabModelSelector().getCurrentTab().getInfoBarCo ntainer(); |
88 mListener = new InfoBarTestAnimationListener(); | 130 mListener = new InfoBarTestAnimationListener(); |
89 container.setAnimationListener(mListener); | 131 container.setAnimationListener(mListener); |
90 | 132 |
91 LocationProviderFactory.setLocationProviderImpl(new MockLocationProvider ()); | 133 LocationProviderFactory.setLocationProviderImpl(new MockLocationProvider ()); |
92 | 134 |
93 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation ().getContext()); | 135 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation ().getContext()); |
94 } | 136 } |
95 | 137 |
96 @Override | 138 @Override |
97 protected void tearDown() throws Exception { | 139 protected void tearDown() throws Exception { |
98 mTestServer.stopAndDestroyServer(); | 140 mTestServer.stopAndDestroyServer(); |
99 super.tearDown(); | 141 super.tearDown(); |
100 } | 142 } |
101 | 143 |
102 /** | 144 /** |
145 * Simulates clicking a button on an AlertDialog. | |
146 */ | |
147 private void clickButton(final AlertDialog dialog, final int button) { | |
148 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
149 @Override | |
150 public void run() { | |
151 dialog.getButton(button).performClick(); | |
152 } | |
153 }); | |
154 } | |
155 | |
156 /** | |
157 * Runs a geolocation test that permits location access. | |
158 * @param updateWaiter The update waiter to wait for callbacks. | |
159 * @param javascript The JS function to run in the current tab to execute the test. | |
160 * @param nUpdates How many updates to wait for. | |
161 * @param withGeature True if we require a user gesture to trigger the pro mpt. | |
162 * @param isDialog True if we are expecting a permission dialog, false for an infobar. | |
163 * @param hasSwitch True if we are expecting a persistence switch, false otherwise. | |
164 * @param toggleSwitch True if we should toggle the switch off, false other wise. | |
165 * @throws Exception | |
166 */ | |
167 private void runAllowTest(GeolocationUpdateWaiter updateWaiter, String javas cript, int nUpdates, | |
168 boolean withGesture, boolean isDialog, boolean hasSwitch, boolean to ggleSwitch) | |
169 throws Exception { | |
170 final String url = mTestServer.getURL(TEST_FILE); | |
171 loadUrl(url); | |
172 | |
173 if (withGesture) { | |
174 runJavaScriptCodeInCurrentTab("functionToRun = '" + javascript + "'" ); | |
175 singleClickView(getActivity().getActivityTab().getView()); | |
176 } else { | |
177 runJavaScriptCodeInCurrentTab(javascript); | |
178 } | |
179 | |
180 if (isDialog) { | |
181 // We need to have a user gesture for the modal to appear. Use a cli ck listener to | |
182 // trigger the JavaScript. | |
183 DialogShownCriteria criteria = new DialogShownCriteria("Dialog not s hown"); | |
184 CriteriaHelper.pollInstrumentationThread(criteria); | |
185 replyToDialogAndWaitForUpdates( | |
186 updateWaiter, criteria.getDialog(), nUpdates, true, hasSwitc h, toggleSwitch); | |
187 } else { | |
188 replyToInfoBarAndWaitForUpdates(updateWaiter, nUpdates, true, hasSwi tch, toggleSwitch); | |
189 } | |
190 } | |
191 | |
192 private void replyToInfoBarAndWaitForUpdates(GeolocationUpdateWaiter updateW aiter, int nUpdates, | |
193 boolean allow, boolean hasSwitch, boolean toggleSwitch) throws Excep tion { | |
194 assertTrue("InfoBar not added.", mListener.addInfoBarAnimationFinished() ); | |
195 InfoBar infobar = getInfoBars().get(0); | |
196 assertNotNull(infobar); | |
197 | |
198 if (hasSwitch) { | |
199 SwitchCompat persistSwitch = (SwitchCompat) infobar.getView().findVi ewById( | |
200 R.id.permission_infobar_persist_toggle); | |
201 assertNotNull(persistSwitch); | |
202 assertTrue(persistSwitch.isChecked()); | |
203 if (toggleSwitch) { | |
204 singleClickView(persistSwitch); | |
205 waitForCheckedState(persistSwitch, false); | |
206 } | |
207 } | |
208 | |
209 if (allow) { | |
210 assertTrue("Allow button wasn't found", InfoBarUtil.clickPrimaryButt on(infobar)); | |
211 } else { | |
212 assertTrue("Block button wasn't found", InfoBarUtil.clickSecondaryBu tton(infobar)); | |
213 } | |
214 updateWaiter.waitForNumUpdates(nUpdates); | |
215 } | |
216 | |
217 private void replyToDialogAndWaitForUpdates(GeolocationUpdateWaiter updateWa iter, | |
218 AlertDialog dialog, int nUpdates, boolean allow, boolean hasSwitch, | |
219 boolean toggleSwitch) throws Exception { | |
220 if (hasSwitch) { | |
221 SwitchCompat persistSwitch = | |
222 (SwitchCompat) dialog.findViewById(R.id.permission_dialog_pe rsist_toggle); | |
223 assertNotNull(persistSwitch); | |
224 assertTrue(persistSwitch.isChecked()); | |
225 if (toggleSwitch) { | |
226 singleClickView(persistSwitch); | |
227 waitForCheckedState(persistSwitch, false); | |
228 } | |
229 } | |
230 | |
231 if (allow) { | |
232 clickButton(dialog, DialogInterface.BUTTON_POSITIVE); | |
233 } else { | |
234 clickButton(dialog, DialogInterface.BUTTON_NEGATIVE); | |
235 } | |
236 updateWaiter.waitForNumUpdates(nUpdates); | |
237 } | |
238 | |
239 private void waitForCheckedState(final SwitchCompat persistSwitch, boolean i sChecked) | |
240 throws InterruptedException { | |
241 CriteriaHelper.pollUiThread(Criteria.equals(isChecked, new Callable<Bool ean>() { | |
242 @Override | |
243 public Boolean call() { | |
244 return persistSwitch.isChecked(); | |
245 } | |
246 })); | |
247 } | |
248 | |
249 /** | |
103 * Verify Geolocation creates an InfoBar and receives a mock location. | 250 * Verify Geolocation creates an InfoBar and receives a mock location. |
104 * @throws Exception | 251 * @throws Exception |
105 */ | 252 */ |
106 @Smoke | 253 @Smoke |
107 @MediumTest | 254 @MediumTest |
108 @Feature({"Location", "Main"}) | 255 @Feature({"Location", "Main"}) |
109 public void testGeolocationPlumbing() throws Exception { | 256 public void testGeolocationPlumbingAllowedInfoBar() throws Exception { |
110 final String url = mTestServer.getURL(TEST_FILE); | |
111 | |
112 Tab tab = getActivity().getActivityTab(); | 257 Tab tab = getActivity().getActivityTab(); |
113 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); | 258 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); |
114 tab.addObserver(updateWaiter); | 259 tab.addObserver(updateWaiter); |
115 | 260 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); | 261 tab.removeObserver(updateWaiter); |
123 } | 262 } |
124 | 263 |
264 /** | |
265 * Verify Geolocation creates a dialog and receives a mock location. | |
266 * @throws Exception | |
267 */ | |
268 @Smoke | |
269 @MediumTest | |
270 @CommandLineFlags.Add("enable-features=" + MODAL_FLAG) | |
271 @Feature({"Location", "Main"}) | |
272 public void testGeolocationPlumbingAllowedDialog() throws Exception { | |
273 Tab tab = getActivity().getActivityTab(); | |
274 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); | |
275 tab.addObserver(updateWaiter); | |
276 runAllowTest(updateWaiter, "initiate_getCurrentPosition()", 1, true, tru e, false, false); | |
277 tab.removeObserver(updateWaiter); | |
278 } | |
279 | |
280 /** | |
281 * Verify Geolocation creates a dialog and receives a mock location when dia logs are explicitly | |
282 * enabled and permitted to trigger without a gesture. | |
283 * @throws Exception | |
284 */ | |
285 @Smoke | |
286 @MediumTest | |
287 @CommandLineFlags.Add({NO_GESTURE_FEATURE, FORCE_FIELDTRIAL, FORCE_FIELDTRIA L_PARAMS}) | |
288 @Feature({"Location", "Main"}) | |
289 public void testGeolocationPlumbingAllowedDialogNoGesture() throws Exception { | |
290 Tab tab = getActivity().getActivityTab(); | |
291 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); | |
292 tab.addObserver(updateWaiter); | |
293 runAllowTest(updateWaiter, "initiate_getCurrentPosition()", 1, false, tr ue, false, false); | |
294 tab.removeObserver(updateWaiter); | |
295 } | |
296 | |
297 /** | |
298 * Verify Geolocation shows an infobar and receives a mock location if the m odal flag is on but | |
299 * no user gesture is specified. | |
300 * @throws Exception | |
301 */ | |
302 @Smoke | |
303 @MediumTest | |
304 @CommandLineFlags.Add("enable-features=" + MODAL_FLAG) | |
305 @Feature({"Location", "Main"}) | |
306 public void testGeolocationPlumbingAllowedNoGestureShowsInfoBar() throws Exc eption { | |
307 Tab tab = getActivity().getActivityTab(); | |
308 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); | |
309 tab.addObserver(updateWaiter); | |
310 runAllowTest(updateWaiter, "initiate_getCurrentPosition()", 1, false, fa lse, false, false); | |
311 tab.removeObserver(updateWaiter); | |
312 } | |
313 | |
125 /** | 314 /** |
126 * Verify Geolocation creates an InfoBar and receives multiple locations. | 315 * Verify Geolocation creates an InfoBar and receives multiple locations. |
127 * @throws Exception | 316 * @throws Exception |
128 */ | 317 */ |
129 @MediumTest | 318 @MediumTest |
130 @Feature({"Location"}) | 319 @Feature({"Location"}) |
131 public void testGeolocationWatch() throws Exception { | 320 public void testGeolocationWatchInfoBar() throws Exception { |
132 final String url = mTestServer.getURL(TEST_FILE); | |
133 | |
134 Tab tab = getActivity().getActivityTab(); | 321 Tab tab = getActivity().getActivityTab(); |
135 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); | 322 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); |
136 tab.addObserver(updateWaiter); | 323 tab.addObserver(updateWaiter); |
137 | 324 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); | 325 tab.removeObserver(updateWaiter); |
145 } | 326 } |
146 | 327 |
147 /** | 328 /** |
148 * Verify Geolocation prompts with a persistence toggle if that feature is e nabled. Check the | 329 * Verify Geolocation creates a dialog and receives multiple locations. |
149 * switch appears and that permission is granted with it toggled on. | |
150 * @throws Exception | 330 * @throws Exception |
151 */ | 331 */ |
152 @MediumTest | 332 @MediumTest |
153 @CommandLineFlags.Add("enable-features=DisplayPersistenceToggleInPermissionP rompts") | 333 @CommandLineFlags.Add("enable-features=" + MODAL_FLAG) |
154 @Feature({"Location"}) | 334 @Feature({"Location"}) |
155 public void testGeolocationPersistence() throws Exception { | 335 public void testGeolocationWatchDialog() throws Exception { |
156 final String url = mTestServer.getURL(TEST_FILE); | |
157 | |
158 Tab tab = getActivity().getActivityTab(); | 336 Tab tab = getActivity().getActivityTab(); |
159 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); | 337 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); |
160 tab.addObserver(updateWaiter); | 338 tab.addObserver(updateWaiter); |
161 | 339 runAllowTest(updateWaiter, "initiate_watchPosition()", 2, true, true, fa lse, false); |
gone
2016/10/27 20:33:35
The number of updates is only 1 on line 172, isn't
dominickn
2016/10/27 23:37:13
Not quite sure what you mean?
gone
2016/10/27 23:52:20
Clarified over chat; I meant line 172 in the old f
| |
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); | 340 tab.removeObserver(updateWaiter); |
175 } | 341 } |
176 | 342 |
177 /** | 343 /** |
178 * Verify Geolocation prompts with a persistence toggle if that feature is e nabled. Check the | 344 * Verify Geolocation creates an infobar with a persistence toggle if that f eature is enabled. |
179 * switch toggled off. | 345 * Check the switch appears and that permission is granted with it toggled o n. |
180 * @throws Exception | 346 * @throws Exception |
181 */ | 347 */ |
182 @MediumTest | 348 @MediumTest |
183 @CommandLineFlags.Add("enable-features=DisplayPersistenceToggleInPermissionP rompts") | 349 @CommandLineFlags.Add("enable-features=" + TOGGLE_FLAG) |
184 @Feature({"Location"}) | 350 @Feature({"Location"}) |
185 public void testGeolocationPersistenceOff() throws Exception { | 351 public void testGeolocationPersistenceAllowedInfoBar() throws Exception { |
186 final String url = mTestServer.getURL(TEST_FILE); | |
187 | |
188 Tab tab = getActivity().getActivityTab(); | 352 Tab tab = getActivity().getActivityTab(); |
189 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); | 353 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); |
190 tab.addObserver(updateWaiter); | 354 tab.addObserver(updateWaiter); |
355 runAllowTest(updateWaiter, "initiate_getCurrentPosition()", 1, false, fa lse, true, false); | |
356 tab.removeObserver(updateWaiter); | |
357 } | |
191 | 358 |
192 loadUrl(url); | 359 /** |
193 runJavaScriptCodeInCurrentTab("initiate_getCurrentPosition()"); | 360 * Verify Geolocation creates a dialog with a persistence toggle if both fea tures are enabled. |
194 assertTrue("InfoBar not added.", mListener.addInfoBarAnimationFinished() ); | 361 * Check the switch appears and that permission is granted with it toggled o n. |
195 InfoBar infobar = getInfoBars().get(0); | 362 * @throws Exception |
196 SwitchCompat persistSwitch = (SwitchCompat) infobar.getView().findViewBy Id( | 363 */ |
197 R.id.permission_infobar_persist_toggle); | 364 @MediumTest |
198 assertNotNull(persistSwitch); | 365 @CommandLineFlags.Add("enable-features=" + MODAL_TOGGLE_FLAG) |
199 assertTrue(persistSwitch.isChecked()); | 366 @Feature({"Location"}) |
367 public void testGeolocationPersistenceAllowedDialog() throws Exception { | |
368 Tab tab = getActivity().getActivityTab(); | |
369 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); | |
370 tab.addObserver(updateWaiter); | |
371 runAllowTest(updateWaiter, "initiate_getCurrentPosition()", 1, true, tru e, true, false); | |
372 tab.removeObserver(updateWaiter); | |
373 } | |
200 | 374 |
201 // Uncheck the switch | 375 /** |
202 TouchCommon.singleClickView(persistSwitch); | 376 * Verify Geolocation creates an infobar with a persistence toggle if that f eature is enabled. |
203 waitForCheckedState(persistSwitch, false); | 377 * Check the switch toggled off. |
204 | 378 * @throws Exception |
205 assertTrue("OK button wasn't found", InfoBarUtil.clickPrimaryButton(info bar)); | 379 */ |
206 updateWaiter.waitForNumUpdates(1); | 380 @MediumTest |
381 @CommandLineFlags.Add("enable-features=" + TOGGLE_FLAG) | |
382 @Feature({"Location"}) | |
383 public void testGeolocationPersistenceOffAllowedInfoBar() throws Exception { | |
384 Tab tab = getActivity().getActivityTab(); | |
385 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); | |
386 tab.addObserver(updateWaiter); | |
387 runAllowTest(updateWaiter, "initiate_getCurrentPosition()", 1, false, fa lse, true, true); | |
207 | 388 |
208 // Ask for permission again and make sure it doesn't prompt again (grant is cached in the | 389 // Ask for permission again and make sure it doesn't prompt again (grant is cached in the |
209 // blink layer). | 390 // Blink layer). |
210 runJavaScriptCodeInCurrentTab("initiate_getCurrentPosition()"); | 391 runJavaScriptCodeInCurrentTab("initiate_getCurrentPosition()"); |
211 updateWaiter.waitForNumUpdates(2); | 392 updateWaiter.waitForNumUpdates(2); |
212 | 393 |
213 // Ask for permission a third time and make sure it doesn't prompt again . | 394 // Ask for permission a third time and make sure it doesn't prompt again . |
214 runJavaScriptCodeInCurrentTab("initiate_getCurrentPosition()"); | 395 runJavaScriptCodeInCurrentTab("initiate_getCurrentPosition()"); |
215 updateWaiter.waitForNumUpdates(3); | 396 updateWaiter.waitForNumUpdates(3); |
216 | 397 |
217 tab.removeObserver(updateWaiter); | 398 tab.removeObserver(updateWaiter); |
218 } | 399 } |
219 | 400 |
220 /** | 401 /** |
402 * Verify Geolocation creates a dialog with a persistence toggle if that fea ture is enabled. | |
403 * Check the switch toggled off. | |
404 * @throws Exception | |
405 */ | |
406 @MediumTest | |
407 @CommandLineFlags.Add("enable-features=" + MODAL_TOGGLE_FLAG) | |
408 @Feature({"Location"}) | |
409 public void testGeolocationPersistenceOffAllowedDialog() throws Exception { | |
410 Tab tab = getActivity().getActivityTab(); | |
411 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); | |
412 tab.addObserver(updateWaiter); | |
413 runAllowTest(updateWaiter, "initiate_getCurrentPosition()", 1, true, tru e, true, true); | |
414 | |
415 // Ask for permission again and make sure it doesn't prompt again (grant is cached in the | |
416 // Blink layer). | |
417 singleClickView(getActivity().getActivityTab().getView()); | |
418 updateWaiter.waitForNumUpdates(2); | |
419 | |
420 // Ask for permission a third time and make sure it doesn't prompt again . | |
421 singleClickView(getActivity().getActivityTab().getView()); | |
422 updateWaiter.waitForNumUpdates(3); | |
423 | |
424 tab.removeObserver(updateWaiter); | |
425 } | |
426 | |
427 /** | |
221 * Verify Geolocation prompts once and sends multiple locations with a persi stence toggle if | 428 * Verify Geolocation prompts once and sends multiple locations with a persi stence toggle if |
222 * that feature is enabled. | 429 * that feature is enabled. Use an infobar. |
223 * @throws Exception | 430 * @throws Exception |
224 */ | 431 */ |
225 @MediumTest | 432 @LargeTest |
226 @CommandLineFlags.Add("enable-features=DisplayPersistenceToggleInPermissionP rompts") | 433 @CommandLineFlags.Add("enable-features=" + TOGGLE_FLAG) |
227 @Feature({"Location"}) | 434 @Feature({"Location"}) |
228 public void testGeolocationWatchPersistenceOff() throws Exception { | 435 public void testGeolocationWatchPersistenceOffAllowedInfoBar() throws Except ion { |
229 final String url = mTestServer.getURL(TEST_FILE); | |
230 | |
231 Tab tab = getActivity().getActivityTab(); | 436 Tab tab = getActivity().getActivityTab(); |
232 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); | 437 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); |
233 tab.addObserver(updateWaiter); | 438 tab.addObserver(updateWaiter); |
234 | 439 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); | 440 tab.removeObserver(updateWaiter); |
253 } | 441 } |
254 | 442 |
255 private void waitForCheckedState(final SwitchCompat persistSwitch, boolean i sChecked) | 443 /** |
256 throws InterruptedException { | 444 * Verify Geolocation prompts once and sends multiple locations with a persi stence toggle if |
257 CriteriaHelper.pollUiThread(Criteria.equals(isChecked, new Callable<Bool ean>() { | 445 * that feature is enabled. Use a dialog. |
258 @Override | 446 * @throws Exception |
259 public Boolean call() { | 447 */ |
260 return persistSwitch.isChecked(); | 448 @LargeTest |
261 } | 449 @CommandLineFlags.Add("enable-features=" + MODAL_TOGGLE_FLAG) |
262 })); | 450 @Feature({"Location"}) |
451 public void testGeolocationWatchPersistenceOffAllowedDialog() throws Excepti on { | |
452 Tab tab = getActivity().getActivityTab(); | |
453 GeolocationUpdateWaiter updateWaiter = new GeolocationUpdateWaiter(); | |
454 tab.addObserver(updateWaiter); | |
455 runAllowTest(updateWaiter, "initiate_watchPosition()", 2, true, true, tr ue, true); | |
456 tab.removeObserver(updateWaiter); | |
263 } | 457 } |
264 | 458 |
265 @Override | 459 @Override |
266 public void startMainActivity() throws InterruptedException { | 460 public void startMainActivity() throws InterruptedException { |
267 startMainActivityOnBlankPage(); | 461 startMainActivityOnBlankPage(); |
268 } | 462 } |
269 } | 463 } |
OLD | NEW |