Chromium Code Reviews| Index: chrome/android/javatests/src/org/chromium/chrome/browser/firstrun/FirstRunIntegrationTest.java |
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/firstrun/FirstRunIntegrationTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/firstrun/FirstRunIntegrationTest.java |
| index df5bf024cee399ad568a479bf270aae5b1245f4a..1009849623fa99d0291d0b74befa1b2e85184493 100644 |
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/firstrun/FirstRunIntegrationTest.java |
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/firstrun/FirstRunIntegrationTest.java |
| @@ -12,15 +12,17 @@ import android.content.Intent; |
| import android.net.Uri; |
| import android.support.customtabs.CustomTabsIntent; |
| import android.support.test.filters.SmallTest; |
| -import android.test.InstrumentationTestCase; |
| +import android.widget.Button; |
| +import org.chromium.base.ThreadUtils; |
| import org.chromium.base.test.util.CommandLineFlags; |
| +import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.ChromeSwitches; |
| import org.chromium.chrome.browser.ChromeTabbedActivity; |
| import org.chromium.chrome.browser.customtabs.CustomTabActivity; |
| import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
| import org.chromium.chrome.browser.searchwidget.SearchActivity; |
| -import org.chromium.chrome.test.util.ApplicationTestUtils; |
| +import org.chromium.chrome.test.MultiActivityTestBase; |
| import org.chromium.content.browser.test.util.Criteria; |
| import org.chromium.content.browser.test.util.CriteriaHelper; |
| @@ -28,16 +30,19 @@ import org.chromium.content.browser.test.util.CriteriaHelper; |
| * Integration test suite for the first run experience. |
| */ |
| @CommandLineFlags.Remove(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE) |
| -public class FirstRunIntegrationTest extends InstrumentationTestCase { |
| +public class FirstRunIntegrationTest extends MultiActivityTestBase { |
| + private FirstRunActivityTestObserver mTestObserver = new FirstRunActivityTestObserver(); |
| + private Activity mActivity; |
| + |
| @Override |
| public void setUp() throws Exception { |
| super.setUp(); |
| - ApplicationTestUtils.setUp(getInstrumentation().getTargetContext(), true); |
| + FirstRunActivity.setObserverForTest(mTestObserver); |
| } |
| @Override |
| public void tearDown() throws Exception { |
| - ApplicationTestUtils.tearDown(getInstrumentation().getTargetContext()); |
| + if (mActivity != null) mActivity.finish(); |
| super.tearDown(); |
| } |
| @@ -164,4 +169,100 @@ public class FirstRunIntegrationTest extends InstrumentationTestCase { |
| assertEquals(0, freMonitor.getHits()); |
| } |
| + @SmallTest |
| + public void testAbortFirstRun() throws Exception { |
| + final ActivityMonitor freMonitor = |
| + new ActivityMonitor(FirstRunActivity.class.getName(), null, false); |
| + Instrumentation instrumentation = getInstrumentation(); |
| + instrumentation.addMonitor(freMonitor); |
| + |
| + final Context context = instrumentation.getTargetContext(); |
| + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://test.com")); |
| + intent.setPackage(context.getPackageName()); |
| + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| + context.startActivity(intent); |
| + |
| + // Because the AsyncInitializationActivity notices that the FRE hasn't been run yet, it |
| + // redirects to it. Once the user closes the FRE, the user should be kicked back into the |
| + // startup flow where they were interrupted. |
| + mActivity = instrumentation.waitForMonitorWithTimeout( |
| + freMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL); |
| + instrumentation.removeMonitor(freMonitor); |
| + ActivityMonitor activityMonitor = |
| + new ActivityMonitor(ChromeLauncherActivity.class.getName(), null, false); |
| + instrumentation.addMonitor(activityMonitor); |
| + |
| + assertEquals(0, mTestObserver.abortFirstRunExperienceCallback.getCallCount()); |
| + mActivity.onBackPressed(); |
| + mTestObserver.abortFirstRunExperienceCallback.waitForCallback(0); |
| + |
| + mActivity = instrumentation.waitForMonitorWithTimeout( |
| + activityMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL); |
| + CriteriaHelper.pollInstrumentationThread(new Criteria() { |
| + @Override |
| + public boolean isSatisfied() { |
| + return mActivity.isFinishing(); |
| + } |
| + }); |
| + } |
| + |
| + @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.
|
| + public void testClickThroughFirstRun() throws Exception { |
| + final ActivityMonitor freMonitor = |
| + new ActivityMonitor(FirstRunActivity.class.getName(), null, false); |
| + Instrumentation instrumentation = getInstrumentation(); |
| + instrumentation.addMonitor(freMonitor); |
| + |
| + final Context context = instrumentation.getTargetContext(); |
| + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://test.com")); |
| + intent.setPackage(context.getPackageName()); |
| + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| + context.startActivity(intent); |
| + |
| + // Because the AsyncInitializationActivity notices that the FRE hasn't been run yet, it |
| + // redirects to it. Once the user closes the FRE, the user should be kicked back into the |
| + // startup flow where they were interrupted. |
| + mActivity = instrumentation.waitForMonitorWithTimeout( |
| + freMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL); |
| + instrumentation.removeMonitor(freMonitor); |
| + ActivityMonitor activityMonitor = |
| + new ActivityMonitor(ChromeTabbedActivity.class.getName(), null, false); |
| + instrumentation.addMonitor(activityMonitor); |
| + |
| + // Accept the ToS. |
| + mTestObserver.flowIsKnownCallback.waitForCallback(0); |
| + clickButton(mActivity, R.id.terms_accept); |
| + mTestObserver.acceptTermsOfServiceCallback.waitForCallback(0); |
| + 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.
|
| + |
| + // Acknowledge that Data Saver will be enabled. |
| + int jumpCallCount = mTestObserver.jumpToPageCallback.getCallCount(); |
| + clickButton(mActivity, R.id.next_button); |
| + mTestObserver.jumpToPageCallback.waitForCallback(jumpCallCount); |
| + |
| + // Don't sign in the user. |
| + assertEquals(0, mTestObserver.updateCachedEngineCallback.getCallCount()); |
| + jumpCallCount = mTestObserver.jumpToPageCallback.getCallCount(); |
| + clickButton(mActivity, R.id.negative_button); |
| + mTestObserver.jumpToPageCallback.waitForCallback(jumpCallCount); |
| + mTestObserver.updateCachedEngineCallback.waitForCallback(0); |
| + |
| + // FRE should be completed now, which will kick the user back into the interrupted flow. |
| + // In this case, the user gets sent to the ChromeTabbedActivity after a View Intent is |
| + // processed by ChromeLauncherActivity. |
| + mActivity = instrumentation.waitForMonitorWithTimeout( |
| + activityMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL); |
| + assertNotNull(mActivity); |
| + } |
| + |
| + private void clickButton(final Activity activity, final int id) { |
| + ThreadUtils.runOnUiThread(new Runnable() { |
| + @Override |
| + public void run() { |
| + Button button = (Button) activity.findViewById(id); |
| + assertNotNull(button); |
| + button.performClick(); |
| + } |
| + }); |
| + } |
| } |