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