| 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; | |
| 12 import android.content.Intent; | 10 import android.content.Intent; |
| 13 | 11 |
| 14 import org.chromium.base.ApplicationStatus; | 12 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; | |
| 19 import org.chromium.base.test.util.CallbackHelper; | 13 import org.chromium.base.test.util.CallbackHelper; |
| 20 import org.chromium.chrome.browser.DeferredStartupHandler; | 14 import org.chromium.chrome.browser.DeferredStartupHandler; |
| 21 import org.chromium.chrome.browser.firstrun.FirstRunStatus; | |
| 22 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 15 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
| 23 import org.chromium.chrome.browser.tab.Tab; | 16 import org.chromium.chrome.browser.tab.Tab; |
| 24 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 17 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
| 25 import org.chromium.content.browser.BrowserStartupController; | |
| 26 import org.chromium.content.browser.BrowserStartupController.StartupCallback; | |
| 27 import org.chromium.content.browser.test.util.Criteria; | 18 import org.chromium.content.browser.test.util.Criteria; |
| 28 import org.chromium.content.browser.test.util.CriteriaHelper; | 19 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 29 | 20 |
| 30 import java.lang.ref.WeakReference; | 21 import java.lang.ref.WeakReference; |
| 31 import java.util.List; | 22 import java.util.List; |
| 32 import java.util.concurrent.TimeUnit; | 23 import java.util.concurrent.TimeUnit; |
| 33 import java.util.concurrent.TimeoutException; | 24 import java.util.concurrent.TimeoutException; |
| 34 | 25 |
| 35 /** | 26 /** |
| 36 * Base class for all instrumentation tests that require a {@link CustomTabActiv
ity}. | 27 * Base class for all instrumentation tests that require a {@link CustomTabActiv
ity}. |
| 37 */ | 28 */ |
| 38 public abstract class CustomTabActivityTestBase extends | 29 public abstract class CustomTabActivityTestBase extends |
| 39 ChromeActivityTestCaseBase<CustomTabActivity> { | 30 ChromeActivityTestCaseBase<CustomTabActivity> { |
| 40 | 31 |
| 41 protected static final long STARTUP_TIMEOUT_MS = scaleTimeout(5) * 1000; | 32 protected static final long STARTUP_TIMEOUT_MS = scaleTimeout(5) * 1000; |
| 42 protected static final long LONG_TIMEOUT_MS = scaleTimeout(10) * 1000; | 33 protected static final long LONG_TIMEOUT_MS = scaleTimeout(10) * 1000; |
| 43 private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "chrome"; | |
| 44 | 34 |
| 45 public CustomTabActivityTestBase() { | 35 public CustomTabActivityTestBase() { |
| 46 super(CustomTabActivity.class); | 36 super(CustomTabActivity.class); |
| 47 } | 37 } |
| 48 | 38 |
| 49 @Override | 39 @Override |
| 50 protected void setUp() throws Exception { | 40 public void startMainActivity() throws InterruptedException { |
| 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(
); | |
| 60 } | 41 } |
| 61 | 42 |
| 62 @Override | 43 @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 | |
| 77 protected void startActivityCompletely(Intent intent) { | 44 protected void startActivityCompletely(Intent intent) { |
| 78 Activity activity = getInstrumentation().startActivitySync(intent); | 45 Activity activity = getInstrumentation().startActivitySync(intent); |
| 79 assertNotNull("Main activity did not start", activity); | 46 assertNotNull("Main activity did not start", activity); |
| 80 CriteriaHelper.pollUiThread(new Criteria() { | 47 CriteriaHelper.pollUiThread(new Criteria() { |
| 81 @Override | 48 @Override |
| 82 public boolean isSatisfied() { | 49 public boolean isSatisfied() { |
| 83 List<WeakReference<Activity>> list = ApplicationStatus.getRunnin
gActivities(); | 50 List<WeakReference<Activity>> list = ApplicationStatus.getRunnin
gActivities(); |
| 84 for (WeakReference<Activity> ref : list) { | 51 for (WeakReference<Activity> ref : list) { |
| 85 Activity activity = ref.get(); | 52 Activity activity = ref.get(); |
| 86 if (activity == null) continue; | 53 if (activity == null) continue; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 CriteriaHelper.pollUiThread(new Criteria("Deferred startup never complet
ed") { | 92 CriteriaHelper.pollUiThread(new Criteria("Deferred startup never complet
ed") { |
| 126 @Override | 93 @Override |
| 127 public boolean isSatisfied() { | 94 public boolean isSatisfied() { |
| 128 return DeferredStartupHandler.getInstance().isDeferredStartupCom
pleteForApp(); | 95 return DeferredStartupHandler.getInstance().isDeferredStartupCom
pleteForApp(); |
| 129 } | 96 } |
| 130 }, STARTUP_TIMEOUT_MS, CriteriaHelper.DEFAULT_POLLING_INTERVAL); | 97 }, STARTUP_TIMEOUT_MS, CriteriaHelper.DEFAULT_POLLING_INTERVAL); |
| 131 assertNotNull(tab); | 98 assertNotNull(tab); |
| 132 assertNotNull(tab.getView()); | 99 assertNotNull(tab.getView()); |
| 133 assertTrue(tab.isCurrentlyACustomTab()); | 100 assertTrue(tab.isCurrentlyACustomTab()); |
| 134 } | 101 } |
| 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 } | |
| 172 } | 102 } |
| OLD | NEW |