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.support.customtabs.CustomTabsIntent; | 13 import android.support.customtabs.CustomTabsIntent; |
| 14 import android.support.test.filters.MediumTest; |
14 import android.support.test.filters.SmallTest; | 15 import android.support.test.filters.SmallTest; |
15 import android.test.InstrumentationTestCase; | 16 import android.widget.Button; |
16 | 17 |
| 18 import org.chromium.base.ThreadUtils; |
17 import org.chromium.base.test.util.CommandLineFlags; | 19 import org.chromium.base.test.util.CommandLineFlags; |
| 20 import org.chromium.chrome.R; |
18 import org.chromium.chrome.browser.ChromeSwitches; | 21 import org.chromium.chrome.browser.ChromeSwitches; |
19 import org.chromium.chrome.browser.ChromeTabbedActivity; | 22 import org.chromium.chrome.browser.ChromeTabbedActivity; |
20 import org.chromium.chrome.browser.customtabs.CustomTabActivity; | 23 import org.chromium.chrome.browser.customtabs.CustomTabActivity; |
21 import org.chromium.chrome.browser.document.ChromeLauncherActivity; | 24 import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
22 import org.chromium.chrome.browser.searchwidget.SearchActivity; | 25 import org.chromium.chrome.browser.searchwidget.SearchActivity; |
23 import org.chromium.chrome.test.util.ApplicationTestUtils; | 26 import org.chromium.chrome.test.MultiActivityTestBase; |
24 import org.chromium.content.browser.test.util.Criteria; | 27 import org.chromium.content.browser.test.util.Criteria; |
25 import org.chromium.content.browser.test.util.CriteriaHelper; | 28 import org.chromium.content.browser.test.util.CriteriaHelper; |
26 | 29 |
27 /** | 30 /** |
28 * Integration test suite for the first run experience. | 31 * Integration test suite for the first run experience. |
29 */ | 32 */ |
30 @CommandLineFlags.Remove(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE) | 33 @CommandLineFlags.Remove(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE) |
31 public class FirstRunIntegrationTest extends InstrumentationTestCase { | 34 public class FirstRunIntegrationTest extends MultiActivityTestBase { |
| 35 private FirstRunActivityTestObserver mTestObserver = new FirstRunActivityTes
tObserver(); |
| 36 private Activity mActivity; |
| 37 |
32 @Override | 38 @Override |
33 public void setUp() throws Exception { | 39 public void setUp() throws Exception { |
34 super.setUp(); | 40 super.setUp(); |
35 ApplicationTestUtils.setUp(getInstrumentation().getTargetContext(), true
); | 41 FirstRunActivity.setObserverForTest(mTestObserver); |
36 } | 42 } |
37 | 43 |
38 @Override | 44 @Override |
39 public void tearDown() throws Exception { | 45 public void tearDown() throws Exception { |
40 ApplicationTestUtils.tearDown(getInstrumentation().getTargetContext()); | 46 if (mActivity != null) mActivity.finish(); |
41 super.tearDown(); | 47 super.tearDown(); |
42 } | 48 } |
43 | 49 |
44 @SmallTest | 50 @SmallTest |
45 public void testGenericViewIntentGoesToFirstRun() { | 51 public void testGenericViewIntentGoesToFirstRun() { |
46 final String asyncClassName = ChromeLauncherActivity.class.getName(); | 52 final String asyncClassName = ChromeLauncherActivity.class.getName(); |
47 runFirstRunRedirectTestForActivity(asyncClassName, new Runnable() { | 53 runFirstRunRedirectTestForActivity(asyncClassName, new Runnable() { |
48 @Override | 54 @Override |
49 public void run() { | 55 public void run() { |
50 final Context context = getInstrumentation().getTargetContext(); | 56 final Context context = getInstrumentation().getTargetContext(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // The original activity should be started because it's a "help page". | 163 // The original activity should be started because it's a "help page". |
158 final Activity original = instrumentation.waitForMonitorWithTimeout( | 164 final Activity original = instrumentation.waitForMonitorWithTimeout( |
159 customTabActivityMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POL
L); | 165 customTabActivityMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POL
L); |
160 assertNotNull(original); | 166 assertNotNull(original); |
161 assertFalse(original.isFinishing()); | 167 assertFalse(original.isFinishing()); |
162 | 168 |
163 // First run should be skipped for this Activity. | 169 // First run should be skipped for this Activity. |
164 assertEquals(0, freMonitor.getHits()); | 170 assertEquals(0, freMonitor.getHits()); |
165 } | 171 } |
166 | 172 |
| 173 @SmallTest |
| 174 public void testAbortFirstRun() throws Exception { |
| 175 final ActivityMonitor freMonitor = |
| 176 new ActivityMonitor(FirstRunActivity.class.getName(), null, fals
e); |
| 177 Instrumentation instrumentation = getInstrumentation(); |
| 178 instrumentation.addMonitor(freMonitor); |
| 179 |
| 180 final Context context = instrumentation.getTargetContext(); |
| 181 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://test.co
m")); |
| 182 intent.setPackage(context.getPackageName()); |
| 183 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 184 context.startActivity(intent); |
| 185 |
| 186 // Because the AsyncInitializationActivity notices that the FRE hasn't b
een run yet, it |
| 187 // redirects to it. Once the user closes the FRE, the user should be ki
cked back into the |
| 188 // startup flow where they were interrupted. |
| 189 mActivity = instrumentation.waitForMonitorWithTimeout( |
| 190 freMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL); |
| 191 instrumentation.removeMonitor(freMonitor); |
| 192 ActivityMonitor activityMonitor = |
| 193 new ActivityMonitor(ChromeLauncherActivity.class.getName(), null
, false); |
| 194 instrumentation.addMonitor(activityMonitor); |
| 195 |
| 196 assertEquals(0, mTestObserver.abortFirstRunExperienceCallback.getCallCou
nt()); |
| 197 mActivity.onBackPressed(); |
| 198 mTestObserver.abortFirstRunExperienceCallback.waitForCallback( |
| 199 "FirstRunActivity didn't abort", 0); |
| 200 |
| 201 mActivity = instrumentation.waitForMonitorWithTimeout( |
| 202 activityMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL); |
| 203 CriteriaHelper.pollInstrumentationThread(new Criteria() { |
| 204 @Override |
| 205 public boolean isSatisfied() { |
| 206 return mActivity.isFinishing(); |
| 207 } |
| 208 }); |
| 209 } |
| 210 |
| 211 @MediumTest |
| 212 public void testClickThroughFirstRun() throws Exception { |
| 213 final ActivityMonitor freMonitor = |
| 214 new ActivityMonitor(FirstRunActivity.class.getName(), null, fals
e); |
| 215 Instrumentation instrumentation = getInstrumentation(); |
| 216 instrumentation.addMonitor(freMonitor); |
| 217 |
| 218 final Context context = instrumentation.getTargetContext(); |
| 219 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://test.co
m")); |
| 220 intent.setPackage(context.getPackageName()); |
| 221 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 222 context.startActivity(intent); |
| 223 |
| 224 // Because the AsyncInitializationActivity notices that the FRE hasn't b
een run yet, it |
| 225 // redirects to it. Once the user closes the FRE, the user should be ki
cked back into the |
| 226 // startup flow where they were interrupted. |
| 227 mActivity = instrumentation.waitForMonitorWithTimeout( |
| 228 freMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL); |
| 229 instrumentation.removeMonitor(freMonitor); |
| 230 ActivityMonitor activityMonitor = |
| 231 new ActivityMonitor(ChromeTabbedActivity.class.getName(), null,
false); |
| 232 instrumentation.addMonitor(activityMonitor); |
| 233 |
| 234 // Accept the ToS. |
| 235 mTestObserver.flowIsKnownCallback.waitForCallback("Failed to finalize th
e flow", 0); |
| 236 clickButton(mActivity, R.id.terms_accept); |
| 237 mTestObserver.acceptTermsOfServiceCallback.waitForCallback("Failed to ac
cept the ToS", 0); |
| 238 mTestObserver.jumpToPageCallback.waitForCallback( |
| 239 "Failed to try moving to the next screen", 0); |
| 240 |
| 241 // Acknowledge that Data Saver will be enabled. |
| 242 int jumpCallCount = mTestObserver.jumpToPageCallback.getCallCount(); |
| 243 clickButton(mActivity, R.id.next_button); |
| 244 mTestObserver.jumpToPageCallback.waitForCallback( |
| 245 "Failed to try moving to next screen", jumpCallCount); |
| 246 |
| 247 // Don't sign in the user. |
| 248 assertEquals(0, mTestObserver.updateCachedEngineCallback.getCallCount())
; |
| 249 jumpCallCount = mTestObserver.jumpToPageCallback.getCallCount(); |
| 250 clickButton(mActivity, R.id.negative_button); |
| 251 mTestObserver.jumpToPageCallback.waitForCallback( |
| 252 "Failed to try moving to next screen", jumpCallCount); |
| 253 mTestObserver.updateCachedEngineCallback.waitForCallback( |
| 254 "Failed to alert search widgets that an update is necessary", 0)
; |
| 255 |
| 256 // FRE should be completed now, which will kick the user back into the i
nterrupted flow. |
| 257 // In this case, the user gets sent to the ChromeTabbedActivity after a
View Intent is |
| 258 // processed by ChromeLauncherActivity. |
| 259 mActivity = instrumentation.waitForMonitorWithTimeout( |
| 260 activityMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL); |
| 261 assertNotNull(mActivity); |
| 262 } |
| 263 |
| 264 private void clickButton(final Activity activity, final int id) { |
| 265 ThreadUtils.runOnUiThread(new Runnable() { |
| 266 @Override |
| 267 public void run() { |
| 268 Button button = (Button) activity.findViewById(id); |
| 269 assertNotNull(button); |
| 270 button.performClick(); |
| 271 } |
| 272 }); |
| 273 } |
167 } | 274 } |
OLD | NEW |