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.customtabs; | 5 package org.chromium.chrome.browser.customtabs; |
6 | 6 |
7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; | 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; |
8 | 8 |
9 import android.app.Activity; | 9 import android.app.Activity; |
| 10 import android.app.Application; |
| 11 import android.content.Context; |
10 import android.content.Intent; | 12 import android.content.Intent; |
11 | 13 |
12 import org.chromium.base.ApplicationStatus; | 14 import org.chromium.base.ApplicationStatus; |
| 15 import org.chromium.base.PathUtils; |
| 16 import org.chromium.base.ThreadUtils; |
| 17 import org.chromium.base.library_loader.LibraryLoader; |
| 18 import org.chromium.base.library_loader.LibraryProcessType; |
13 import org.chromium.base.test.util.CallbackHelper; | 19 import org.chromium.base.test.util.CallbackHelper; |
14 import org.chromium.chrome.browser.DeferredStartupHandler; | 20 import org.chromium.chrome.browser.DeferredStartupHandler; |
| 21 import org.chromium.chrome.browser.firstrun.FirstRunStatus; |
15 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 22 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
16 import org.chromium.chrome.browser.tab.Tab; | 23 import org.chromium.chrome.browser.tab.Tab; |
17 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 24 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
| 25 import org.chromium.content.browser.BrowserStartupController; |
| 26 import org.chromium.content.browser.BrowserStartupController.StartupCallback; |
18 import org.chromium.content.browser.test.util.Criteria; | 27 import org.chromium.content.browser.test.util.Criteria; |
19 import org.chromium.content.browser.test.util.CriteriaHelper; | 28 import org.chromium.content.browser.test.util.CriteriaHelper; |
20 | 29 |
21 import java.lang.ref.WeakReference; | 30 import java.lang.ref.WeakReference; |
22 import java.util.List; | 31 import java.util.List; |
23 import java.util.concurrent.TimeUnit; | 32 import java.util.concurrent.TimeUnit; |
24 import java.util.concurrent.TimeoutException; | 33 import java.util.concurrent.TimeoutException; |
25 | 34 |
26 /** | 35 /** |
27 * Base class for all instrumentation tests that require a {@link CustomTabActiv
ity}. | 36 * Base class for all instrumentation tests that require a {@link CustomTabActiv
ity}. |
28 */ | 37 */ |
29 public abstract class CustomTabActivityTestBase extends | 38 public abstract class CustomTabActivityTestBase extends |
30 ChromeActivityTestCaseBase<CustomTabActivity> { | 39 ChromeActivityTestCaseBase<CustomTabActivity> { |
31 | 40 |
32 protected static final long STARTUP_TIMEOUT_MS = scaleTimeout(5) * 1000; | 41 protected static final long STARTUP_TIMEOUT_MS = scaleTimeout(5) * 1000; |
33 protected static final long LONG_TIMEOUT_MS = scaleTimeout(10) * 1000; | 42 protected static final long LONG_TIMEOUT_MS = scaleTimeout(10) * 1000; |
| 43 private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "chrome"; |
34 | 44 |
35 public CustomTabActivityTestBase() { | 45 public CustomTabActivityTestBase() { |
36 super(CustomTabActivity.class); | 46 super(CustomTabActivity.class); |
37 } | 47 } |
38 | 48 |
39 @Override | 49 @Override |
40 public void startMainActivity() throws InterruptedException { | 50 protected void setUp() throws Exception { |
| 51 super.setUp(); |
| 52 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 53 @Override |
| 54 public void run() { |
| 55 FirstRunStatus.setFirstRunFlowComplete(true); |
| 56 } |
| 57 }); |
| 58 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); |
| 59 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized(
); |
41 } | 60 } |
42 | 61 |
43 @Override | 62 @Override |
| 63 protected void tearDown() throws Exception { |
| 64 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 65 @Override |
| 66 public void run() { |
| 67 FirstRunStatus.setFirstRunFlowComplete(false); |
| 68 } |
| 69 }); |
| 70 super.tearDown(); |
| 71 } |
| 72 |
| 73 @Override |
| 74 public void startMainActivity() throws InterruptedException {} |
| 75 |
| 76 @Override |
44 protected void startActivityCompletely(Intent intent) { | 77 protected void startActivityCompletely(Intent intent) { |
45 Activity activity = getInstrumentation().startActivitySync(intent); | 78 Activity activity = getInstrumentation().startActivitySync(intent); |
46 assertNotNull("Main activity did not start", activity); | 79 assertNotNull("Main activity did not start", activity); |
47 CriteriaHelper.pollUiThread(new Criteria() { | 80 CriteriaHelper.pollUiThread(new Criteria() { |
48 @Override | 81 @Override |
49 public boolean isSatisfied() { | 82 public boolean isSatisfied() { |
50 List<WeakReference<Activity>> list = ApplicationStatus.getRunnin
gActivities(); | 83 List<WeakReference<Activity>> list = ApplicationStatus.getRunnin
gActivities(); |
51 for (WeakReference<Activity> ref : list) { | 84 for (WeakReference<Activity> ref : list) { |
52 Activity activity = ref.get(); | 85 Activity activity = ref.get(); |
53 if (activity == null) continue; | 86 if (activity == null) continue; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 CriteriaHelper.pollUiThread(new Criteria("Deferred startup never complet
ed") { | 125 CriteriaHelper.pollUiThread(new Criteria("Deferred startup never complet
ed") { |
93 @Override | 126 @Override |
94 public boolean isSatisfied() { | 127 public boolean isSatisfied() { |
95 return DeferredStartupHandler.getInstance().isDeferredStartupCom
pleteForApp(); | 128 return DeferredStartupHandler.getInstance().isDeferredStartupCom
pleteForApp(); |
96 } | 129 } |
97 }, STARTUP_TIMEOUT_MS, CriteriaHelper.DEFAULT_POLLING_INTERVAL); | 130 }, STARTUP_TIMEOUT_MS, CriteriaHelper.DEFAULT_POLLING_INTERVAL); |
98 assertNotNull(tab); | 131 assertNotNull(tab); |
99 assertNotNull(tab.getView()); | 132 assertNotNull(tab.getView()); |
100 assertTrue(tab.isCurrentlyACustomTab()); | 133 assertTrue(tab.isCurrentlyACustomTab()); |
101 } | 134 } |
| 135 |
| 136 /** |
| 137 * Connects to Custom Tabs, calls warmup() and wait for completion. |
| 138 * |
| 139 * @return the connection. |
| 140 */ |
| 141 protected CustomTabsConnection warmUpAndWait() { |
| 142 final Context context = getInstrumentation().getTargetContext().getAppli
cationContext(); |
| 143 CustomTabsConnection connection = |
| 144 CustomTabsTestUtils.setUpConnection((Application) context); |
| 145 final CallbackHelper startupCallbackHelper = new CallbackHelper(); |
| 146 assertTrue(connection.warmup(0)); |
| 147 ThreadUtils.runOnUiThread(new Runnable() { |
| 148 @Override |
| 149 public void run() { |
| 150 BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER) |
| 151 .addStartupCompletedObserver(new StartupCallback() { |
| 152 @Override |
| 153 public void onSuccess(boolean alreadyStarted) { |
| 154 startupCallbackHelper.notifyCalled(); |
| 155 } |
| 156 |
| 157 @Override |
| 158 public void onFailure() { |
| 159 fail(); |
| 160 } |
| 161 }); |
| 162 } |
| 163 }); |
| 164 |
| 165 try { |
| 166 startupCallbackHelper.waitForCallback(0); |
| 167 } catch (TimeoutException | InterruptedException e) { |
| 168 fail(); |
| 169 } |
| 170 return connection; |
| 171 } |
102 } | 172 } |
OLD | NEW |