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.firstrun; | 5 package org.chromium.chrome.browser.firstrun; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.app.Instrumentation; | 8 import android.app.Instrumentation; |
9 import android.app.Instrumentation.ActivityMonitor; | 9 import android.app.Instrumentation.ActivityMonitor; |
10 import android.content.Context; | 10 import android.content.Context; |
11 import android.content.Intent; | 11 import android.content.Intent; |
12 import android.net.Uri; | 12 import android.net.Uri; |
13 import android.os.Bundle; | 13 import android.os.Bundle; |
14 import android.support.customtabs.CustomTabsIntent; | 14 import android.support.customtabs.CustomTabsIntent; |
15 import android.support.test.InstrumentationRegistry; | 15 import android.support.test.InstrumentationRegistry; |
16 import android.support.test.filters.MediumTest; | 16 import android.support.test.filters.MediumTest; |
17 import android.support.test.filters.SmallTest; | 17 import android.support.test.filters.SmallTest; |
| 18 import android.view.ViewGroup; |
18 import android.widget.Button; | 19 import android.widget.Button; |
19 | 20 |
20 import org.junit.After; | 21 import org.junit.After; |
21 import org.junit.Assert; | 22 import org.junit.Assert; |
22 import org.junit.Before; | 23 import org.junit.Before; |
23 import org.junit.Rule; | 24 import org.junit.Rule; |
24 import org.junit.Test; | 25 import org.junit.Test; |
25 import org.junit.runner.RunWith; | 26 import org.junit.runner.RunWith; |
26 | 27 |
27 import org.chromium.base.ThreadUtils; | 28 import org.chromium.base.ThreadUtils; |
28 import org.chromium.base.annotations.SuppressFBWarnings; | 29 import org.chromium.base.annotations.SuppressFBWarnings; |
29 import org.chromium.chrome.R; | 30 import org.chromium.chrome.R; |
30 import org.chromium.chrome.browser.ChromeTabbedActivity; | 31 import org.chromium.chrome.browser.ChromeTabbedActivity; |
31 import org.chromium.chrome.browser.customtabs.CustomTabActivity; | 32 import org.chromium.chrome.browser.customtabs.CustomTabActivity; |
32 import org.chromium.chrome.browser.document.ChromeLauncherActivity; | 33 import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
| 34 import org.chromium.chrome.browser.locale.LocaleManager; |
| 35 import org.chromium.chrome.browser.locale.LocaleManager.SearchEnginePromoType; |
| 36 import org.chromium.chrome.browser.search_engines.TemplateUrlService; |
33 import org.chromium.chrome.browser.searchwidget.SearchActivity; | 37 import org.chromium.chrome.browser.searchwidget.SearchActivity; |
34 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; | 38 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
35 import org.chromium.chrome.test.MultiActivityTestRule; | 39 import org.chromium.chrome.test.MultiActivityTestRule; |
36 import org.chromium.content.browser.test.util.Criteria; | 40 import org.chromium.content.browser.test.util.Criteria; |
37 import org.chromium.content.browser.test.util.CriteriaHelper; | 41 import org.chromium.content.browser.test.util.CriteriaHelper; |
38 | 42 |
39 /** | 43 /** |
40 * Integration test suite for the first run experience. | 44 * Integration test suite for the first run experience. |
41 */ | 45 */ |
42 @RunWith(ChromeJUnit4ClassRunner.class) | 46 @RunWith(ChromeJUnit4ClassRunner.class) |
43 public class FirstRunIntegrationTest { | 47 public class FirstRunIntegrationTest { |
44 | 48 |
45 @Rule | 49 @Rule |
46 @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") | 50 @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") |
47 public MultiActivityTestRule mTestRule = new MultiActivityTestRule(); | 51 public MultiActivityTestRule mTestRule = new MultiActivityTestRule(); |
48 | 52 |
49 private FirstRunActivityTestObserver mTestObserver = new FirstRunActivityTes
tObserver(); | 53 private FirstRunActivityTestObserver mTestObserver = new FirstRunActivityTes
tObserver(); |
50 private Activity mActivity; | 54 private Activity mActivity; |
| 55 private String mSelectedEngine; |
51 | 56 |
52 @Before | 57 @Before |
53 public void setUp() throws Exception { | 58 public void setUp() throws Exception { |
54 FirstRunActivity.setObserverForTest(mTestObserver); | 59 FirstRunActivity.setObserverForTest(mTestObserver); |
55 } | 60 } |
56 | 61 |
57 @After | 62 @After |
58 public void tearDown() throws Exception { | 63 public void tearDown() throws Exception { |
59 if (mActivity != null) mActivity.finish(); | 64 if (mActivity != null) mActivity.finish(); |
60 } | 65 } |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 CriteriaHelper.pollInstrumentationThread(new Criteria() { | 229 CriteriaHelper.pollInstrumentationThread(new Criteria() { |
225 @Override | 230 @Override |
226 public boolean isSatisfied() { | 231 public boolean isSatisfied() { |
227 return mActivity.isFinishing(); | 232 return mActivity.isFinishing(); |
228 } | 233 } |
229 }); | 234 }); |
230 } | 235 } |
231 | 236 |
232 @Test | 237 @Test |
233 @MediumTest | 238 @MediumTest |
234 public void testClickThroughFirstRun() throws Exception { | 239 public void testDefaultSearchEngine_DontShow() throws Exception { |
| 240 runSearchEnginePromptTest(LocaleManager.SEARCH_ENGINE_PROMO_DONT_SHOW); |
| 241 } |
| 242 |
| 243 @Test |
| 244 @MediumTest |
| 245 public void testDefaultSearchEngine_ShowExisting() throws Exception { |
| 246 runSearchEnginePromptTest(LocaleManager.SEARCH_ENGINE_PROMO_SHOW_EXISTIN
G); |
| 247 } |
| 248 |
| 249 private void runSearchEnginePromptTest(@SearchEnginePromoType final int sear
chPromoType) |
| 250 throws Exception { |
| 251 // Force the LocaleManager into a specific state. |
| 252 LocaleManager mockManager = new LocaleManager() { |
| 253 @Override |
| 254 public int getSearchEnginePromoShowType() { |
| 255 return searchPromoType; |
| 256 } |
| 257 }; |
| 258 LocaleManager.setInstanceForTest(mockManager); |
| 259 |
235 final ActivityMonitor freMonitor = | 260 final ActivityMonitor freMonitor = |
236 new ActivityMonitor(FirstRunActivity.class.getName(), null, fals
e); | 261 new ActivityMonitor(FirstRunActivity.class.getName(), null, fals
e); |
237 Instrumentation instrumentation = InstrumentationRegistry.getInstrumenta
tion(); | 262 Instrumentation instrumentation = InstrumentationRegistry.getInstrumenta
tion(); |
238 instrumentation.addMonitor(freMonitor); | 263 instrumentation.addMonitor(freMonitor); |
239 | 264 |
240 final Context context = instrumentation.getTargetContext(); | 265 final Context context = instrumentation.getTargetContext(); |
241 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://test.co
m")); | 266 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://test.co
m")); |
242 intent.setPackage(context.getPackageName()); | 267 intent.setPackage(context.getPackageName()); |
243 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 268 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
244 context.startActivity(intent); | 269 context.startActivity(intent); |
245 | 270 |
246 // Because the AsyncInitializationActivity notices that the FRE hasn't b
een run yet, it | 271 // Because the AsyncInitializationActivity notices that the FRE hasn't b
een run yet, it |
247 // redirects to it. Once the user closes the FRE, the user should be ki
cked back into the | 272 // redirects to it. Once the user closes the FRE, the user should be ki
cked back into the |
248 // startup flow where they were interrupted. | 273 // startup flow where they were interrupted. |
249 mActivity = instrumentation.waitForMonitorWithTimeout( | 274 mActivity = instrumentation.waitForMonitorWithTimeout( |
250 freMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL); | 275 freMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL); |
251 instrumentation.removeMonitor(freMonitor); | 276 instrumentation.removeMonitor(freMonitor); |
252 ActivityMonitor activityMonitor = | 277 ActivityMonitor activityMonitor = |
253 new ActivityMonitor(ChromeTabbedActivity.class.getName(), null,
false); | 278 new ActivityMonitor(ChromeTabbedActivity.class.getName(), null,
false); |
254 instrumentation.addMonitor(activityMonitor); | 279 instrumentation.addMonitor(activityMonitor); |
255 | 280 |
256 mTestObserver.flowIsKnownCallback.waitForCallback("Failed to finalize th
e flow", 0); | 281 mTestObserver.flowIsKnownCallback.waitForCallback("Failed to finalize th
e flow", 0); |
257 Bundle freProperties = mTestObserver.freProperties; | 282 Bundle freProperties = mTestObserver.freProperties; |
258 Assert.assertEquals(0, mTestObserver.updateCachedEngineCallback.getCallC
ount()); | 283 Assert.assertEquals(0, mTestObserver.updateCachedEngineCallback.getCallC
ount()); |
259 | 284 |
260 // Accept the ToS. | 285 // Accept the ToS. |
261 if (freProperties.getBoolean(FirstRunActivity.SHOW_WELCOME_PAGE)) { | 286 if (freProperties.getBoolean(FirstRunActivity.SHOW_WELCOME_PAGE)) { |
262 clickButton(mActivity, R.id.terms_accept, "Failed to accept ToS"); | 287 clickButton(mActivity, R.id.terms_accept, "Failed to accept ToS"); |
| 288 mTestObserver.jumpToPageCallback.waitForCallback( |
| 289 "Failed to try moving to the next screen", 0); |
263 mTestObserver.acceptTermsOfServiceCallback.waitForCallback( | 290 mTestObserver.acceptTermsOfServiceCallback.waitForCallback( |
264 "Failed to accept the ToS", 0); | 291 "Failed to accept the ToS", 0); |
265 mTestObserver.jumpToPageCallback.waitForCallback( | |
266 "Failed to try moving to the next screen", 0); | |
267 } | 292 } |
268 | 293 |
269 // Acknowledge that Data Saver will be enabled. | 294 // Acknowledge that Data Saver will be enabled. |
270 if (freProperties.getBoolean(FirstRunActivity.SHOW_DATA_REDUCTION_PAGE))
{ | 295 if (freProperties.getBoolean(FirstRunActivity.SHOW_DATA_REDUCTION_PAGE))
{ |
271 int jumpCallCount = mTestObserver.jumpToPageCallback.getCallCount(); | 296 int jumpCallCount = mTestObserver.jumpToPageCallback.getCallCount(); |
272 clickButton(mActivity, R.id.next_button, "Failed to skip data saver"
); | 297 clickButton(mActivity, R.id.next_button, "Failed to skip data saver"
); |
273 mTestObserver.jumpToPageCallback.waitForCallback( | 298 mTestObserver.jumpToPageCallback.waitForCallback( |
274 "Failed to try moving to next screen", jumpCallCount); | 299 "Failed to try moving to next screen", jumpCallCount); |
275 } | 300 } |
276 | 301 |
| 302 // Select a default search engine. |
| 303 if (searchPromoType == LocaleManager.SEARCH_ENGINE_PROMO_DONT_SHOW) { |
| 304 Assert.assertFalse("Search engine page was shown.", |
| 305 freProperties.getBoolean(FirstRunActivity.SHOW_SEARCH_ENGINE
_PAGE)); |
| 306 } else { |
| 307 Assert.assertTrue("Search engine page wasn't shown.", |
| 308 freProperties.getBoolean(FirstRunActivity.SHOW_SEARCH_ENGINE
_PAGE)); |
| 309 int jumpCallCount = mTestObserver.jumpToPageCallback.getCallCount(); |
| 310 |
| 311 // Click on the first search engine option available. |
| 312 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 313 @Override |
| 314 public void run() { |
| 315 ViewGroup options = (ViewGroup) mActivity.findViewById(R.id.
engine_controls); |
| 316 options.getChildAt(0).performClick(); |
| 317 mSelectedEngine = (String) (options.getChildAt(0).getTag()); |
| 318 } |
| 319 }); |
| 320 |
| 321 clickButton(mActivity, R.id.button_primary, "Failed to select defaul
t search engine"); |
| 322 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 323 @Override |
| 324 public void run() { |
| 325 Assert.assertEquals("Search engine wasn't set", |
| 326 TemplateUrlService.getInstance() |
| 327 .getDefaultSearchEngineTemplateUrl() |
| 328 .getKeyword(), |
| 329 mSelectedEngine); |
| 330 } |
| 331 }); |
| 332 |
| 333 mTestObserver.jumpToPageCallback.waitForCallback( |
| 334 "Failed to try moving to next screen", jumpCallCount); |
| 335 } |
| 336 |
277 // Don't sign in the user. | 337 // Don't sign in the user. |
278 if (freProperties.getBoolean(FirstRunActivity.SHOW_SIGNIN_PAGE)) { | 338 if (freProperties.getBoolean(FirstRunActivity.SHOW_SIGNIN_PAGE)) { |
279 int jumpCallCount = mTestObserver.jumpToPageCallback.getCallCount(); | 339 int jumpCallCount = mTestObserver.jumpToPageCallback.getCallCount(); |
280 clickButton(mActivity, R.id.negative_button, "Failed to skip signing
-in"); | 340 clickButton(mActivity, R.id.negative_button, "Failed to skip signing
-in"); |
281 mTestObserver.jumpToPageCallback.waitForCallback( | 341 mTestObserver.jumpToPageCallback.waitForCallback( |
282 "Failed to try moving to next screen", jumpCallCount); | 342 "Failed to try moving to next screen", jumpCallCount); |
283 } | 343 } |
284 | 344 |
285 // FRE should be completed now, which will kick the user back into the i
nterrupted flow. | 345 // FRE should be completed now, which will kick the user back into the i
nterrupted flow. |
286 // In this case, the user gets sent to the ChromeTabbedActivity after a
View Intent is | 346 // In this case, the user gets sent to the ChromeTabbedActivity after a
View Intent is |
(...skipping 16 matching lines...) Expand all Loading... |
303 ThreadUtils.runOnUiThread(new Runnable() { | 363 ThreadUtils.runOnUiThread(new Runnable() { |
304 @Override | 364 @Override |
305 public void run() { | 365 public void run() { |
306 Button button = (Button) activity.findViewById(id); | 366 Button button = (Button) activity.findViewById(id); |
307 Assert.assertNotNull(message, button); | 367 Assert.assertNotNull(message, button); |
308 button.performClick(); | 368 button.performClick(); |
309 } | 369 } |
310 }); | 370 }); |
311 } | 371 } |
312 } | 372 } |
OLD | NEW |