| 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; | |
| 15 import android.support.test.filters.SmallTest; | 14 import android.support.test.filters.SmallTest; |
| 16 import android.widget.Button; | 15 import android.test.InstrumentationTestCase; |
| 17 | 16 |
| 18 import org.chromium.base.ThreadUtils; | |
| 19 import org.chromium.base.test.util.CommandLineFlags; | 17 import org.chromium.base.test.util.CommandLineFlags; |
| 20 import org.chromium.chrome.R; | |
| 21 import org.chromium.chrome.browser.ChromeSwitches; | 18 import org.chromium.chrome.browser.ChromeSwitches; |
| 22 import org.chromium.chrome.browser.ChromeTabbedActivity; | 19 import org.chromium.chrome.browser.ChromeTabbedActivity; |
| 23 import org.chromium.chrome.browser.customtabs.CustomTabActivity; | 20 import org.chromium.chrome.browser.customtabs.CustomTabActivity; |
| 24 import org.chromium.chrome.browser.document.ChromeLauncherActivity; | 21 import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
| 25 import org.chromium.chrome.browser.searchwidget.SearchActivity; | 22 import org.chromium.chrome.browser.searchwidget.SearchActivity; |
| 26 import org.chromium.chrome.test.MultiActivityTestBase; | 23 import org.chromium.chrome.test.util.ApplicationTestUtils; |
| 27 import org.chromium.content.browser.test.util.Criteria; | 24 import org.chromium.content.browser.test.util.Criteria; |
| 28 import org.chromium.content.browser.test.util.CriteriaHelper; | 25 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 29 | 26 |
| 30 /** | 27 /** |
| 31 * Integration test suite for the first run experience. | 28 * Integration test suite for the first run experience. |
| 32 */ | 29 */ |
| 33 @CommandLineFlags.Remove(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE) | 30 @CommandLineFlags.Remove(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE) |
| 34 public class FirstRunIntegrationTest extends MultiActivityTestBase { | 31 public class FirstRunIntegrationTest extends InstrumentationTestCase { |
| 35 private FirstRunActivityTestObserver mTestObserver = new FirstRunActivityTes
tObserver(); | |
| 36 private Activity mActivity; | |
| 37 | |
| 38 @Override | 32 @Override |
| 39 public void setUp() throws Exception { | 33 public void setUp() throws Exception { |
| 40 super.setUp(); | 34 super.setUp(); |
| 41 FirstRunActivity.setObserverForTest(mTestObserver); | 35 ApplicationTestUtils.setUp(getInstrumentation().getTargetContext(), true
); |
| 42 } | 36 } |
| 43 | 37 |
| 44 @Override | 38 @Override |
| 45 public void tearDown() throws Exception { | 39 public void tearDown() throws Exception { |
| 46 if (mActivity != null) mActivity.finish(); | 40 ApplicationTestUtils.tearDown(getInstrumentation().getTargetContext()); |
| 47 super.tearDown(); | 41 super.tearDown(); |
| 48 } | 42 } |
| 49 | 43 |
| 50 @SmallTest | 44 @SmallTest |
| 51 public void testGenericViewIntentGoesToFirstRun() { | 45 public void testGenericViewIntentGoesToFirstRun() { |
| 52 final String asyncClassName = ChromeLauncherActivity.class.getName(); | 46 final String asyncClassName = ChromeLauncherActivity.class.getName(); |
| 53 runFirstRunRedirectTestForActivity(asyncClassName, new Runnable() { | 47 runFirstRunRedirectTestForActivity(asyncClassName, new Runnable() { |
| 54 @Override | 48 @Override |
| 55 public void run() { | 49 public void run() { |
| 56 final Context context = getInstrumentation().getTargetContext(); | 50 final Context context = getInstrumentation().getTargetContext(); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 // The original activity should be started because it's a "help page". | 157 // The original activity should be started because it's a "help page". |
| 164 final Activity original = instrumentation.waitForMonitorWithTimeout( | 158 final Activity original = instrumentation.waitForMonitorWithTimeout( |
| 165 customTabActivityMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POL
L); | 159 customTabActivityMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POL
L); |
| 166 assertNotNull(original); | 160 assertNotNull(original); |
| 167 assertFalse(original.isFinishing()); | 161 assertFalse(original.isFinishing()); |
| 168 | 162 |
| 169 // First run should be skipped for this Activity. | 163 // First run should be skipped for this Activity. |
| 170 assertEquals(0, freMonitor.getHits()); | 164 assertEquals(0, freMonitor.getHits()); |
| 171 } | 165 } |
| 172 | 166 |
| 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 } | |
| 274 } | 167 } |
| OLD | NEW |