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