| 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 b091a634cb4e2ceeb2526277e0199ef572dea09a..df5bf024cee399ad568a479bf270aae5b1245f4a 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
|
| @@ -4,17 +4,23 @@
|
|
|
| package org.chromium.chrome.browser.firstrun;
|
|
|
| -import android.annotation.TargetApi;
|
| -import android.os.Build;
|
| +import android.app.Activity;
|
| +import android.app.Instrumentation;
|
| +import android.app.Instrumentation.ActivityMonitor;
|
| +import android.content.Context;
|
| +import android.content.Intent;
|
| +import android.net.Uri;
|
| +import android.support.customtabs.CustomTabsIntent;
|
| import android.support.test.filters.SmallTest;
|
| -import android.view.KeyEvent;
|
| +import android.test.InstrumentationTestCase;
|
|
|
| import org.chromium.base.test.util.CommandLineFlags;
|
| -import org.chromium.base.test.util.Feature;
|
| -import org.chromium.base.test.util.RetryOnFailure;
|
| import org.chromium.chrome.browser.ChromeSwitches;
|
| -import org.chromium.chrome.browser.tabmodel.TabList;
|
| -import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
|
| +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.content.browser.test.util.Criteria;
|
| import org.chromium.content.browser.test.util.CriteriaHelper;
|
|
|
| @@ -22,43 +28,140 @@ 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 ChromeTabbedActivityTestBase {
|
| +public class FirstRunIntegrationTest extends InstrumentationTestCase {
|
| + @Override
|
| + public void setUp() throws Exception {
|
| + super.setUp();
|
| + ApplicationTestUtils.setUp(getInstrumentation().getTargetContext(), true);
|
| + }
|
| +
|
| + @Override
|
| + public void tearDown() throws Exception {
|
| + ApplicationTestUtils.tearDown(getInstrumentation().getTargetContext());
|
| + super.tearDown();
|
| + }
|
| +
|
| + @SmallTest
|
| + public void testGenericViewIntentGoesToFirstRun() {
|
| + final String asyncClassName = ChromeLauncherActivity.class.getName();
|
| + runFirstRunRedirectTestForActivity(asyncClassName, new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + final Context context = getInstrumentation().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);
|
| + }
|
| + });
|
| + }
|
| +
|
| + @SmallTest
|
| + public void testRedirectCustomTabActivityToFirstRun() {
|
| + final String asyncClassName = ChromeLauncherActivity.class.getName();
|
| + runFirstRunRedirectTestForActivity(asyncClassName, new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + Context context = getInstrumentation().getTargetContext();
|
| + CustomTabsIntent customTabIntent = new CustomTabsIntent.Builder().build();
|
| + customTabIntent.intent.setPackage(context.getPackageName());
|
| + customTabIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
| + customTabIntent.launchUrl(context, Uri.parse("http://test.com"));
|
| + }
|
| + });
|
| + }
|
| +
|
| + @SmallTest
|
| + public void testRedirectChromeTabbedActivityToFirstRun() {
|
| + final String asyncClassName = ChromeTabbedActivity.class.getName();
|
| + runFirstRunRedirectTestForActivity(asyncClassName, new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + final Context context = getInstrumentation().getTargetContext();
|
| + Intent intent = new Intent();
|
| + intent.setClassName(context, asyncClassName);
|
| + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
| + context.startActivity(intent);
|
| + }
|
| + });
|
| + }
|
| +
|
| + @SmallTest
|
| + public void testRedirectSearchActivityToFirstRun() {
|
| + final String asyncClassName = SearchActivity.class.getName();
|
| + runFirstRunRedirectTestForActivity(asyncClassName, new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + final Context context = getInstrumentation().getTargetContext();
|
| + Intent intent = new Intent();
|
| + intent.setClassName(context, asyncClassName);
|
| + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
| + context.startActivity(intent);
|
| + }
|
| + });
|
| + }
|
|
|
| /**
|
| - * Exiting the first run experience should close all tabs,
|
| - * finalize the tab closures and close Chrome.
|
| + * Tests that an AsyncInitializationActivity subclass that attempts to be run without first
|
| + * having gone through First Run kicks the user out into the FRE.
|
| + * @param asyncClassName Name of the class to expect.
|
| + * @param runnable Runnable that launches the Activity.
|
| */
|
| - @SmallTest
|
| - @Feature({"FirstRunExperience"})
|
| - @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
| - @RetryOnFailure
|
| - public void testExitFirstRunExperience() {
|
| - if (FirstRunStatus.getFirstRunFlowComplete()) {
|
| - return;
|
| - }
|
| + private void runFirstRunRedirectTestForActivity(String asyncClassName, Runnable runnable) {
|
| + final ActivityMonitor activityMonitor = new ActivityMonitor(asyncClassName, null, false);
|
| + final ActivityMonitor freMonitor =
|
| + new ActivityMonitor(FirstRunActivity.class.getName(), null, false);
|
|
|
| - sendKeys(KeyEvent.KEYCODE_BACK);
|
| + Instrumentation instrumentation = getInstrumentation();
|
| + instrumentation.addMonitor(activityMonitor);
|
| + instrumentation.addMonitor(freMonitor);
|
| + runnable.run();
|
|
|
| - CriteriaHelper.pollInstrumentationThread(new Criteria("Expected no tabs to be present") {
|
| + // The original activity should be started because it was directly specified.
|
| + final Activity original = instrumentation.waitForMonitorWithTimeout(
|
| + activityMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL);
|
| + assertNotNull(original);
|
| + CriteriaHelper.pollInstrumentationThread(new Criteria() {
|
| @Override
|
| public boolean isSatisfied() {
|
| - return 0 == getActivity().getCurrentTabModel().getCount();
|
| + return original.isFinishing();
|
| }
|
| });
|
| - TabList fullModel = getActivity().getCurrentTabModel().getComprehensiveModel();
|
| - assertEquals("Expected no tabs to be present in the comprehensive model",
|
| - 0, fullModel.getCount());
|
| - CriteriaHelper.pollInstrumentationThread(new Criteria("Activity was not closed.") {
|
| +
|
| + // Because the AsyncInitializationActivity notices that the FRE hasn't been run yet, it
|
| + // redirects to it. Ideally, we would grab the Activity here, but it seems that the
|
| + // First Run Activity doesn't live long enough to be grabbed.
|
| + CriteriaHelper.pollInstrumentationThread(new Criteria() {
|
| @Override
|
| public boolean isSatisfied() {
|
| - return getActivity().isFinishing() || getActivity().isDestroyed();
|
| + return freMonitor.getHits() == 1;
|
| }
|
| });
|
| }
|
|
|
| - @Override
|
| - public void startMainActivity() throws InterruptedException {
|
| - startMainActivityFromLauncher();
|
| + @SmallTest
|
| + public void testHelpPageSkipsFirstRun() {
|
| + final ActivityMonitor customTabActivityMonitor =
|
| + new ActivityMonitor(CustomTabActivity.class.getName(), null, false);
|
| + final ActivityMonitor freMonitor =
|
| + new ActivityMonitor(FirstRunActivity.class.getName(), null, false);
|
| +
|
| + Instrumentation instrumentation = getInstrumentation();
|
| + instrumentation.addMonitor(customTabActivityMonitor);
|
| + instrumentation.addMonitor(freMonitor);
|
| +
|
| + // Fire an Intent to load a generic URL.
|
| + final Context context = instrumentation.getTargetContext();
|
| + CustomTabActivity.showInfoPage(context, "http://google.com");
|
| +
|
| + // The original activity should be started because it's a "help page".
|
| + final Activity original = instrumentation.waitForMonitorWithTimeout(
|
| + customTabActivityMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL);
|
| + assertNotNull(original);
|
| + assertFalse(original.isFinishing());
|
| +
|
| + // First run should be skipped for this Activity.
|
| + assertEquals(0, freMonitor.getHits());
|
| }
|
|
|
| }
|
|
|