| 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.sync; | 5 package org.chromium.chrome.browser.sync; |
| 6 | 6 |
| 7 import android.accounts.Account; | 7 import android.accounts.Account; |
| 8 import android.app.Activity; | 8 import android.app.Activity; |
| 9 import android.app.Instrumentation; | 9 import android.app.Instrumentation; |
| 10 import android.app.Instrumentation.ActivityMonitor; | 10 import android.app.Instrumentation.ActivityMonitor; |
| 11 import android.content.Context; | 11 import android.content.Context; |
| 12 import android.content.Intent; | 12 import android.content.Intent; |
| 13 import android.os.Bundle; | 13 import android.os.Bundle; |
| 14 import android.support.test.filters.SmallTest; | 14 import android.support.test.filters.SmallTest; |
| 15 | 15 |
| 16 import org.chromium.base.ThreadUtils; | 16 import org.chromium.base.ThreadUtils; |
| 17 import org.chromium.base.test.util.CallbackHelper; |
| 17 import org.chromium.base.test.util.CommandLineFlags; | 18 import org.chromium.base.test.util.CommandLineFlags; |
| 18 import org.chromium.base.test.util.Feature; | 19 import org.chromium.base.test.util.Feature; |
| 19 import org.chromium.base.test.util.FlakyTest; | 20 import org.chromium.base.test.util.FlakyTest; |
| 20 import org.chromium.base.test.util.RetryOnFailure; | 21 import org.chromium.base.test.util.RetryOnFailure; |
| 21 import org.chromium.chrome.browser.ChromeSwitches; | 22 import org.chromium.chrome.browser.ChromeSwitches; |
| 22 import org.chromium.chrome.browser.firstrun.FirstRunActivity; | 23 import org.chromium.chrome.browser.firstrun.FirstRunActivity; |
| 24 import org.chromium.chrome.browser.firstrun.FirstRunActivity.FirstRunActivityObs
erver; |
| 23 import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer; | 25 import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer; |
| 24 import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor; | 26 import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor; |
| 25 import org.chromium.chrome.browser.preferences.Preferences; | 27 import org.chromium.chrome.browser.preferences.Preferences; |
| 26 import org.chromium.chrome.browser.signin.AccountManagementFragment; | 28 import org.chromium.chrome.browser.signin.AccountManagementFragment; |
| 27 import org.chromium.chrome.test.util.ActivityUtils; | 29 import org.chromium.chrome.test.util.ActivityUtils; |
| 28 import org.chromium.chrome.test.util.browser.signin.SigninTestUtil; | 30 import org.chromium.chrome.test.util.browser.signin.SigninTestUtil; |
| 29 import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; | 31 import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; |
| 30 import org.chromium.content.browser.test.util.Criteria; | 32 import org.chromium.content.browser.test.util.Criteria; |
| 31 import org.chromium.content.browser.test.util.CriteriaHelper; | 33 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 32 | 34 |
| 35 import java.util.concurrent.TimeoutException; |
| 36 |
| 33 /** | 37 /** |
| 34 * Tests for the first run experience. | 38 * Tests for the first run experience. |
| 35 */ | 39 */ |
| 36 @CommandLineFlags.Remove(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE) | 40 @CommandLineFlags.Remove(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE) |
| 37 @RetryOnFailure // crbug.com/637448 | 41 @RetryOnFailure // crbug.com/637448 |
| 38 public class FirstRunTest extends SyncTestBase { | 42 public class FirstRunTest extends SyncTestBase { |
| 39 private static final String TEST_ACTION = "com.artificial.package.TEST_ACTIO
N"; | 43 private static final String TEST_ACTION = "com.artificial.package.TEST_ACTIO
N"; |
| 40 | 44 |
| 41 private static enum ShowSettings { | 45 private static enum ShowSettings { |
| 42 YES, | 46 YES, |
| 43 NO; | 47 NO; |
| 44 } | 48 } |
| 45 | 49 |
| 50 private static final class TestObserver implements FirstRunActivityObserver
{ |
| 51 public final CallbackHelper flowIsKnownCallback = new CallbackHelper(); |
| 52 |
| 53 @Override |
| 54 public void onFlowIsKnown() { |
| 55 flowIsKnownCallback.notifyCalled(); |
| 56 } |
| 57 |
| 58 @Override |
| 59 public void onAcceptTermsOfService() {} |
| 60 |
| 61 @Override |
| 62 public void onJumpToPage(int position) {} |
| 63 |
| 64 @Override |
| 65 public void onUpdateCachedEngineName() {} |
| 66 |
| 67 @Override |
| 68 public void onAbortFirstRunExperience() {} |
| 69 } |
| 70 |
| 71 private final TestObserver mTestObserver = new TestObserver(); |
| 46 private FirstRunActivity mActivity; | 72 private FirstRunActivity mActivity; |
| 47 | 73 |
| 48 @Override | 74 @Override |
| 49 public void startMainActivity() throws InterruptedException { | 75 public void startMainActivity() throws InterruptedException { |
| 76 FirstRunActivity.setObserverForTest(mTestObserver); |
| 77 |
| 50 // Starts up and waits for the FirstRunActivity to be ready. | 78 // Starts up and waits for the FirstRunActivity to be ready. |
| 51 // This isn't exactly what startMainActivity is supposed to be doing, bu
t short of a | 79 // This isn't exactly what startMainActivity is supposed to be doing, bu
t short of a |
| 52 // refactoring of SyncTestBase to use something other than ChromeTabbedA
ctivity, it's the | 80 // refactoring of SyncTestBase to use something other than ChromeTabbedA
ctivity, it's the |
| 53 // only way to reuse the rest of the setup and initialization code insid
e of it. | 81 // only way to reuse the rest of the setup and initialization code insid
e of it. |
| 54 final Instrumentation instrumentation = getInstrumentation(); | 82 final Instrumentation instrumentation = getInstrumentation(); |
| 55 final Context context = instrumentation.getTargetContext(); | 83 final Context context = instrumentation.getTargetContext(); |
| 56 | 84 |
| 57 // Create an Intent that causes Chrome to run. | 85 // Create an Intent that causes Chrome to run. |
| 58 final Intent intent = new Intent(TEST_ACTION); | 86 final Intent intent = new Intent(TEST_ACTION); |
| 59 intent.setPackage(context.getPackageName()); | 87 intent.setPackage(context.getPackageName()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 71 }); | 99 }); |
| 72 | 100 |
| 73 // Wait for the FRE to be ready to use. | 101 // Wait for the FRE to be ready to use. |
| 74 Activity activity = | 102 Activity activity = |
| 75 freMonitor.waitForActivityWithTimeout(CriteriaHelper.DEFAULT_MAX
_TIME_TO_POLL); | 103 freMonitor.waitForActivityWithTimeout(CriteriaHelper.DEFAULT_MAX
_TIME_TO_POLL); |
| 76 instrumentation.removeMonitor(freMonitor); | 104 instrumentation.removeMonitor(freMonitor); |
| 77 | 105 |
| 78 assertTrue(activity instanceof FirstRunActivity); | 106 assertTrue(activity instanceof FirstRunActivity); |
| 79 mActivity = (FirstRunActivity) activity; | 107 mActivity = (FirstRunActivity) activity; |
| 80 | 108 |
| 81 CriteriaHelper.pollUiThread(new Criteria() { | 109 try { |
| 82 @Override | 110 mTestObserver.flowIsKnownCallback.waitForCallback(0); |
| 83 public boolean isSatisfied() { | 111 } catch (TimeoutException e) { |
| 84 return mActivity.isPostNativePageSequenceCreated(); | 112 fail(); |
| 85 } | 113 } |
| 86 }); | |
| 87 | 114 |
| 88 getInstrumentation().waitForIdleSync(); | 115 getInstrumentation().waitForIdleSync(); |
| 89 } | 116 } |
| 90 | 117 |
| 91 @Override | 118 @Override |
| 119 public void setUp() throws Exception { |
| 120 super.setUp(); |
| 121 } |
| 122 |
| 123 @Override |
| 92 public void tearDown() throws Exception { | 124 public void tearDown() throws Exception { |
| 93 if (mActivity != null) mActivity.finish(); | 125 if (mActivity != null) mActivity.finish(); |
| 94 super.tearDown(); | 126 super.tearDown(); |
| 95 } | 127 } |
| 96 | 128 |
| 97 // Test that signing in through FirstRun signs in and starts sync. | 129 // Test that signing in through FirstRun signs in and starts sync. |
| 98 /* | 130 /* |
| 99 * @SmallTest | 131 * @SmallTest |
| 100 * @Feature({"Sync"}) | 132 * @Feature({"Sync"}) |
| 101 */ | 133 */ |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 220 |
| 189 private void processFirstRunOnUiThread() { | 221 private void processFirstRunOnUiThread() { |
| 190 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 222 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 191 @Override | 223 @Override |
| 192 public void run() { | 224 public void run() { |
| 193 FirstRunSignInProcessor.start(mActivity); | 225 FirstRunSignInProcessor.start(mActivity); |
| 194 } | 226 } |
| 195 }); | 227 }); |
| 196 } | 228 } |
| 197 } | 229 } |
| OLD | NEW |