Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1224)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/firstrun/FirstRunIntegrationTest.java

Issue 2834253002: 🔍 Don't display the search engine until First Run completes (Closed)
Patch Set: Cmments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..0e4a031c307e883dbe9e6062859a210d496d1fa1 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
@@ -11,16 +11,19 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.customtabs.CustomTabsIntent;
+import android.support.test.filters.MediumTest;
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 +31,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 +170,105 @@ 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(
+ "FirstRunActivity didn't abort", 0);
+
+ mActivity = instrumentation.waitForMonitorWithTimeout(
+ activityMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL);
+ CriteriaHelper.pollInstrumentationThread(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return mActivity.isFinishing();
+ }
+ });
+ }
+
+ @MediumTest
+ 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("Failed to finalize the flow", 0);
+ clickButton(mActivity, R.id.terms_accept);
+ mTestObserver.acceptTermsOfServiceCallback.waitForCallback("Failed to accept the ToS", 0);
+ mTestObserver.jumpToPageCallback.waitForCallback(
+ "Failed to try moving to the next screen", 0);
+
+ // Acknowledge that Data Saver will be enabled.
+ int jumpCallCount = mTestObserver.jumpToPageCallback.getCallCount();
+ clickButton(mActivity, R.id.next_button);
+ mTestObserver.jumpToPageCallback.waitForCallback(
+ "Failed to try moving to next screen", 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(
+ "Failed to try moving to next screen", jumpCallCount);
+ mTestObserver.updateCachedEngineCallback.waitForCallback(
+ "Failed to alert search widgets that an update is necessary", 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();
+ }
+ });
+ }
}

Powered by Google App Engine
This is Rietveld 408576698