| 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.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; | 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; |
| 8 | 8 |
| 9 import android.app.Activity; | 9 import android.app.Activity; |
| 10 import android.app.Application; | 10 import android.app.Application; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 import android.view.MenuItem; | 39 import android.view.MenuItem; |
| 40 import android.view.View; | 40 import android.view.View; |
| 41 import android.view.ViewGroup; | 41 import android.view.ViewGroup; |
| 42 import android.widget.EditText; | 42 import android.widget.EditText; |
| 43 import android.widget.ImageButton; | 43 import android.widget.ImageButton; |
| 44 | 44 |
| 45 import org.chromium.base.ActivityState; | 45 import org.chromium.base.ActivityState; |
| 46 import org.chromium.base.ApplicationStatus; | 46 import org.chromium.base.ApplicationStatus; |
| 47 import org.chromium.base.ApplicationStatus.ActivityStateListener; | 47 import org.chromium.base.ApplicationStatus.ActivityStateListener; |
| 48 import org.chromium.base.ObserverList.RewindableIterator; | 48 import org.chromium.base.ObserverList.RewindableIterator; |
| 49 import org.chromium.base.PathUtils; |
| 49 import org.chromium.base.ThreadUtils; | 50 import org.chromium.base.ThreadUtils; |
| 51 import org.chromium.base.library_loader.LibraryLoader; |
| 52 import org.chromium.base.library_loader.LibraryProcessType; |
| 50 import org.chromium.base.test.util.CallbackHelper; | 53 import org.chromium.base.test.util.CallbackHelper; |
| 51 import org.chromium.base.test.util.CommandLineFlags; | 54 import org.chromium.base.test.util.CommandLineFlags; |
| 52 import org.chromium.base.test.util.DisabledTest; | 55 import org.chromium.base.test.util.DisabledTest; |
| 53 import org.chromium.base.test.util.Restriction; | 56 import org.chromium.base.test.util.Restriction; |
| 54 import org.chromium.base.test.util.RetryOnFailure; | 57 import org.chromium.base.test.util.RetryOnFailure; |
| 55 import org.chromium.chrome.R; | 58 import org.chromium.chrome.R; |
| 56 import org.chromium.chrome.browser.ChromeActivity; | 59 import org.chromium.chrome.browser.ChromeActivity; |
| 57 import org.chromium.chrome.browser.ChromeSwitches; | 60 import org.chromium.chrome.browser.ChromeSwitches; |
| 58 import org.chromium.chrome.browser.ChromeTabbedActivity; | 61 import org.chromium.chrome.browser.ChromeTabbedActivity; |
| 59 import org.chromium.chrome.browser.IntentHandler; | 62 import org.chromium.chrome.browser.IntentHandler; |
| 60 import org.chromium.chrome.browser.TabsOpenedFromExternalAppTest; | 63 import org.chromium.chrome.browser.TabsOpenedFromExternalAppTest; |
| 61 import org.chromium.chrome.browser.WarmupManager; | 64 import org.chromium.chrome.browser.WarmupManager; |
| 62 import org.chromium.chrome.browser.appmenu.AppMenuHandler; | 65 import org.chromium.chrome.browser.appmenu.AppMenuHandler; |
| 63 import org.chromium.chrome.browser.document.ChromeLauncherActivity; | 66 import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
| 67 import org.chromium.chrome.browser.firstrun.FirstRunStatus; |
| 64 import org.chromium.chrome.browser.metrics.PageLoadMetrics; | 68 import org.chromium.chrome.browser.metrics.PageLoadMetrics; |
| 65 import org.chromium.chrome.browser.prerender.ExternalPrerenderHandler; | 69 import org.chromium.chrome.browser.prerender.ExternalPrerenderHandler; |
| 66 import org.chromium.chrome.browser.profiles.Profile; | 70 import org.chromium.chrome.browser.profiles.Profile; |
| 67 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 71 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
| 68 import org.chromium.chrome.browser.tab.Tab; | 72 import org.chromium.chrome.browser.tab.Tab; |
| 69 import org.chromium.chrome.browser.tab.TabObserver; | 73 import org.chromium.chrome.browser.tab.TabObserver; |
| 70 import org.chromium.chrome.browser.tab.TabTestUtils; | 74 import org.chromium.chrome.browser.tab.TabTestUtils; |
| 71 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; | 75 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; |
| 72 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 76 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
| 73 import org.chromium.chrome.browser.tabmodel.TabModelSelector; | 77 import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| 74 import org.chromium.chrome.browser.toolbar.CustomTabToolbar; | 78 import org.chromium.chrome.browser.toolbar.CustomTabToolbar; |
| 75 import org.chromium.chrome.browser.util.ColorUtils; | 79 import org.chromium.chrome.browser.util.ColorUtils; |
| 76 import org.chromium.chrome.test.util.ChromeRestriction; | 80 import org.chromium.chrome.test.util.ChromeRestriction; |
| 77 import org.chromium.chrome.test.util.browser.LocationSettingsTestUtil; | 81 import org.chromium.chrome.test.util.browser.LocationSettingsTestUtil; |
| 78 import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils; | 82 import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils; |
| 83 import org.chromium.content.browser.BrowserStartupController; |
| 84 import org.chromium.content.browser.BrowserStartupController.StartupCallback; |
| 79 import org.chromium.content.browser.test.util.Criteria; | 85 import org.chromium.content.browser.test.util.Criteria; |
| 80 import org.chromium.content.browser.test.util.CriteriaHelper; | 86 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 81 import org.chromium.content.browser.test.util.DOMUtils; | 87 import org.chromium.content.browser.test.util.DOMUtils; |
| 82 import org.chromium.content.browser.test.util.JavaScriptUtils; | 88 import org.chromium.content.browser.test.util.JavaScriptUtils; |
| 83 import org.chromium.content_public.browser.LoadUrlParams; | 89 import org.chromium.content_public.browser.LoadUrlParams; |
| 84 import org.chromium.content_public.browser.WebContentsObserver; | 90 import org.chromium.content_public.browser.WebContentsObserver; |
| 85 import org.chromium.net.test.EmbeddedTestServer; | 91 import org.chromium.net.test.EmbeddedTestServer; |
| 86 import org.chromium.net.test.util.TestWebServer; | 92 import org.chromium.net.test.util.TestWebServer; |
| 87 import org.chromium.ui.mojom.WindowOpenDisposition; | 93 import org.chromium.ui.mojom.WindowOpenDisposition; |
| 88 | 94 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 private CustomTabActivity mActivity; | 143 private CustomTabActivity mActivity; |
| 138 private String mTestPage; | 144 private String mTestPage; |
| 139 private String mTestPage2; | 145 private String mTestPage2; |
| 140 private EmbeddedTestServer mTestServer; | 146 private EmbeddedTestServer mTestServer; |
| 141 private TestWebServer mWebServer; | 147 private TestWebServer mWebServer; |
| 142 | 148 |
| 143 @Override | 149 @Override |
| 144 protected void setUp() throws Exception { | 150 protected void setUp() throws Exception { |
| 145 super.setUp(); | 151 super.setUp(); |
| 146 | 152 |
| 153 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 154 @Override |
| 155 public void run() { |
| 156 FirstRunStatus.setFirstRunFlowComplete(true); |
| 157 } |
| 158 }); |
| 159 |
| 147 Context appContext = getInstrumentation().getTargetContext().getApplicat
ionContext(); | 160 Context appContext = getInstrumentation().getTargetContext().getApplicat
ionContext(); |
| 148 mTestServer = EmbeddedTestServer.createAndStartServer(appContext); | 161 mTestServer = EmbeddedTestServer.createAndStartServer(appContext); |
| 149 mTestPage = mTestServer.getURL(TEST_PAGE); | 162 mTestPage = mTestServer.getURL(TEST_PAGE); |
| 150 mTestPage2 = mTestServer.getURL(TEST_PAGE_2); | 163 mTestPage2 = mTestServer.getURL(TEST_PAGE_2); |
| 164 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); |
| 165 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized(
); |
| 151 mWebServer = TestWebServer.start(); | 166 mWebServer = TestWebServer.start(); |
| 152 | 167 |
| 153 CustomTabsConnection connection = | 168 CustomTabsConnection connection = |
| 154 CustomTabsConnection.getInstance((Application) appContext); | 169 CustomTabsConnection.getInstance((Application) appContext); |
| 155 connection.setForcePrerender(true); | 170 connection.setForcePrerender(true); |
| 156 } | 171 } |
| 157 | 172 |
| 158 @Override | 173 @Override |
| 159 protected void tearDown() throws Exception { | 174 protected void tearDown() throws Exception { |
| 160 Context appContext = getInstrumentation().getTargetContext().getApplicat
ionContext(); | 175 Context appContext = getInstrumentation().getTargetContext().getApplicat
ionContext(); |
| 161 CustomTabsConnection connection = | 176 CustomTabsConnection connection = |
| 162 CustomTabsConnection.getInstance((Application) appContext); | 177 CustomTabsConnection.getInstance((Application) appContext); |
| 163 connection.setForcePrerender(false); | 178 connection.setForcePrerender(false); |
| 164 | 179 |
| 180 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 181 @Override |
| 182 public void run() { |
| 183 FirstRunStatus.setFirstRunFlowComplete(false); |
| 184 } |
| 185 }); |
| 186 |
| 165 mTestServer.stopAndDestroyServer(); | 187 mTestServer.stopAndDestroyServer(); |
| 166 | 188 |
| 167 // finish() is called on a non-UI thread by the testing harness. Must hi
de the menu | 189 // finish() is called on a non-UI thread by the testing harness. Must hi
de the menu |
| 168 // first, otherwise the UI is manipulated on a non-UI thread. | 190 // first, otherwise the UI is manipulated on a non-UI thread. |
| 169 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 191 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 170 @Override | 192 @Override |
| 171 public void run() { | 193 public void run() { |
| 172 if (mActivity == null) return; | 194 if (mActivity == null) return; |
| 173 AppMenuHandler handler = mActivity.getAppMenuHandler(); | 195 AppMenuHandler handler = mActivity.getAppMenuHandler(); |
| 174 if (handler != null) handler.hideAppMenu(); | 196 if (handler != null) handler.hideAppMenu(); |
| (...skipping 2077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2252 try { | 2274 try { |
| 2253 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCu
stomTabIntent( | 2275 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCu
stomTabIntent( |
| 2254 context, mTestPage)); | 2276 context, mTestPage)); |
| 2255 } catch (InterruptedException e) { | 2277 } catch (InterruptedException e) { |
| 2256 fail(); | 2278 fail(); |
| 2257 } | 2279 } |
| 2258 Tab tab = getActivity().getActivityTab(); | 2280 Tab tab = getActivity().getActivityTab(); |
| 2259 assertEquals(mTestPage, tab.getUrl()); | 2281 assertEquals(mTestPage, tab.getUrl()); |
| 2260 } | 2282 } |
| 2261 | 2283 |
| 2284 private CustomTabsConnection warmUpAndWait() { |
| 2285 final Context context = getInstrumentation().getTargetContext().getAppli
cationContext(); |
| 2286 CustomTabsConnection connection = |
| 2287 CustomTabsTestUtils.setUpConnection((Application) context); |
| 2288 final CallbackHelper startupCallbackHelper = new CallbackHelper(); |
| 2289 assertTrue(connection.warmup(0)); |
| 2290 ThreadUtils.runOnUiThread(new Runnable() { |
| 2291 @Override |
| 2292 public void run() { |
| 2293 BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER) |
| 2294 .addStartupCompletedObserver(new StartupCallback() { |
| 2295 @Override |
| 2296 public void onSuccess(boolean alreadyStarted) { |
| 2297 startupCallbackHelper.notifyCalled(); |
| 2298 } |
| 2299 |
| 2300 @Override |
| 2301 public void onFailure() { |
| 2302 fail(); |
| 2303 } |
| 2304 }); |
| 2305 } |
| 2306 }); |
| 2307 |
| 2308 try { |
| 2309 startupCallbackHelper.waitForCallback(0); |
| 2310 } catch (TimeoutException | InterruptedException e) { |
| 2311 fail(); |
| 2312 } |
| 2313 return connection; |
| 2314 } |
| 2315 |
| 2262 private ChromeActivity reparentAndVerifyTab() throws InterruptedException { | 2316 private ChromeActivity reparentAndVerifyTab() throws InterruptedException { |
| 2263 ActivityResult result = null; | 2317 ActivityResult result = null; |
| 2264 final ActivityMonitor monitor = getInstrumentation().addMonitor( | 2318 final ActivityMonitor monitor = getInstrumentation().addMonitor( |
| 2265 ChromeTabbedActivity.class.getName(), result, false); | 2319 ChromeTabbedActivity.class.getName(), result, false); |
| 2266 final Tab tabToBeReparented = mActivity.getActivityTab(); | 2320 final Tab tabToBeReparented = mActivity.getActivityTab(); |
| 2267 final CallbackHelper tabHiddenHelper = new CallbackHelper(); | 2321 final CallbackHelper tabHiddenHelper = new CallbackHelper(); |
| 2268 TabObserver observer = new EmptyTabObserver() { | 2322 TabObserver observer = new EmptyTabObserver() { |
| 2269 @Override | 2323 @Override |
| 2270 public void onHidden(Tab tab) { | 2324 public void onHidden(Tab tab) { |
| 2271 tabHiddenHelper.notifyCalled(); | 2325 tabHiddenHelper.notifyCalled(); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2442 switch (speculationMode) { | 2496 switch (speculationMode) { |
| 2443 case CustomTabsConnection.SpeculationParams.PRERENDER: | 2497 case CustomTabsConnection.SpeculationParams.PRERENDER: |
| 2444 return "prerender"; | 2498 return "prerender"; |
| 2445 case CustomTabsConnection.SpeculationParams.HIDDEN_TAB: | 2499 case CustomTabsConnection.SpeculationParams.HIDDEN_TAB: |
| 2446 return "hidden"; | 2500 return "hidden"; |
| 2447 default: | 2501 default: |
| 2448 return "visible"; | 2502 return "visible"; |
| 2449 } | 2503 } |
| 2450 } | 2504 } |
| 2451 } | 2505 } |
| OLD | NEW |