| 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; | |
| 50 import org.chromium.base.ThreadUtils; | 49 import org.chromium.base.ThreadUtils; |
| 51 import org.chromium.base.library_loader.LibraryLoader; | |
| 52 import org.chromium.base.library_loader.LibraryProcessType; | |
| 53 import org.chromium.base.test.util.CallbackHelper; | 50 import org.chromium.base.test.util.CallbackHelper; |
| 54 import org.chromium.base.test.util.CommandLineFlags; | 51 import org.chromium.base.test.util.CommandLineFlags; |
| 55 import org.chromium.base.test.util.DisabledTest; | 52 import org.chromium.base.test.util.DisabledTest; |
| 56 import org.chromium.base.test.util.Restriction; | 53 import org.chromium.base.test.util.Restriction; |
| 57 import org.chromium.base.test.util.RetryOnFailure; | 54 import org.chromium.base.test.util.RetryOnFailure; |
| 58 import org.chromium.chrome.R; | 55 import org.chromium.chrome.R; |
| 59 import org.chromium.chrome.browser.ChromeActivity; | 56 import org.chromium.chrome.browser.ChromeActivity; |
| 60 import org.chromium.chrome.browser.ChromeSwitches; | 57 import org.chromium.chrome.browser.ChromeSwitches; |
| 61 import org.chromium.chrome.browser.ChromeTabbedActivity; | 58 import org.chromium.chrome.browser.ChromeTabbedActivity; |
| 62 import org.chromium.chrome.browser.IntentHandler; | 59 import org.chromium.chrome.browser.IntentHandler; |
| 63 import org.chromium.chrome.browser.TabsOpenedFromExternalAppTest; | 60 import org.chromium.chrome.browser.TabsOpenedFromExternalAppTest; |
| 64 import org.chromium.chrome.browser.WarmupManager; | 61 import org.chromium.chrome.browser.WarmupManager; |
| 65 import org.chromium.chrome.browser.appmenu.AppMenuHandler; | 62 import org.chromium.chrome.browser.appmenu.AppMenuHandler; |
| 66 import org.chromium.chrome.browser.document.ChromeLauncherActivity; | 63 import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
| 67 import org.chromium.chrome.browser.firstrun.FirstRunStatus; | |
| 68 import org.chromium.chrome.browser.metrics.PageLoadMetrics; | 64 import org.chromium.chrome.browser.metrics.PageLoadMetrics; |
| 69 import org.chromium.chrome.browser.prerender.ExternalPrerenderHandler; | 65 import org.chromium.chrome.browser.prerender.ExternalPrerenderHandler; |
| 70 import org.chromium.chrome.browser.profiles.Profile; | 66 import org.chromium.chrome.browser.profiles.Profile; |
| 71 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 67 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
| 72 import org.chromium.chrome.browser.tab.Tab; | 68 import org.chromium.chrome.browser.tab.Tab; |
| 73 import org.chromium.chrome.browser.tab.TabObserver; | 69 import org.chromium.chrome.browser.tab.TabObserver; |
| 74 import org.chromium.chrome.browser.tab.TabTestUtils; | 70 import org.chromium.chrome.browser.tab.TabTestUtils; |
| 75 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; | 71 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; |
| 76 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 72 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
| 77 import org.chromium.chrome.browser.tabmodel.TabModelSelector; | 73 import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| 78 import org.chromium.chrome.browser.toolbar.CustomTabToolbar; | 74 import org.chromium.chrome.browser.toolbar.CustomTabToolbar; |
| 79 import org.chromium.chrome.browser.util.ColorUtils; | 75 import org.chromium.chrome.browser.util.ColorUtils; |
| 80 import org.chromium.chrome.test.util.ChromeRestriction; | 76 import org.chromium.chrome.test.util.ChromeRestriction; |
| 81 import org.chromium.chrome.test.util.browser.LocationSettingsTestUtil; | 77 import org.chromium.chrome.test.util.browser.LocationSettingsTestUtil; |
| 82 import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils; | 78 import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils; |
| 83 import org.chromium.content.browser.BrowserStartupController; | |
| 84 import org.chromium.content.browser.BrowserStartupController.StartupCallback; | |
| 85 import org.chromium.content.browser.test.util.Criteria; | 79 import org.chromium.content.browser.test.util.Criteria; |
| 86 import org.chromium.content.browser.test.util.CriteriaHelper; | 80 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 87 import org.chromium.content.browser.test.util.DOMUtils; | 81 import org.chromium.content.browser.test.util.DOMUtils; |
| 88 import org.chromium.content.browser.test.util.JavaScriptUtils; | 82 import org.chromium.content.browser.test.util.JavaScriptUtils; |
| 89 import org.chromium.content_public.browser.LoadUrlParams; | 83 import org.chromium.content_public.browser.LoadUrlParams; |
| 90 import org.chromium.content_public.browser.WebContentsObserver; | 84 import org.chromium.content_public.browser.WebContentsObserver; |
| 91 import org.chromium.net.test.EmbeddedTestServer; | 85 import org.chromium.net.test.EmbeddedTestServer; |
| 92 import org.chromium.net.test.util.TestWebServer; | 86 import org.chromium.net.test.util.TestWebServer; |
| 93 import org.chromium.ui.mojom.WindowOpenDisposition; | 87 import org.chromium.ui.mojom.WindowOpenDisposition; |
| 94 | 88 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 private CustomTabActivity mActivity; | 137 private CustomTabActivity mActivity; |
| 144 private String mTestPage; | 138 private String mTestPage; |
| 145 private String mTestPage2; | 139 private String mTestPage2; |
| 146 private EmbeddedTestServer mTestServer; | 140 private EmbeddedTestServer mTestServer; |
| 147 private TestWebServer mWebServer; | 141 private TestWebServer mWebServer; |
| 148 | 142 |
| 149 @Override | 143 @Override |
| 150 protected void setUp() throws Exception { | 144 protected void setUp() throws Exception { |
| 151 super.setUp(); | 145 super.setUp(); |
| 152 | 146 |
| 153 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
| 154 @Override | |
| 155 public void run() { | |
| 156 FirstRunStatus.setFirstRunFlowComplete(true); | |
| 157 } | |
| 158 }); | |
| 159 | |
| 160 Context appContext = getInstrumentation().getTargetContext().getApplicat
ionContext(); | 147 Context appContext = getInstrumentation().getTargetContext().getApplicat
ionContext(); |
| 161 mTestServer = EmbeddedTestServer.createAndStartServer(appContext); | 148 mTestServer = EmbeddedTestServer.createAndStartServer(appContext); |
| 162 mTestPage = mTestServer.getURL(TEST_PAGE); | 149 mTestPage = mTestServer.getURL(TEST_PAGE); |
| 163 mTestPage2 = mTestServer.getURL(TEST_PAGE_2); | 150 mTestPage2 = mTestServer.getURL(TEST_PAGE_2); |
| 164 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); | |
| 165 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized(
); | |
| 166 mWebServer = TestWebServer.start(); | 151 mWebServer = TestWebServer.start(); |
| 167 | 152 |
| 168 CustomTabsConnection connection = | 153 CustomTabsConnection connection = |
| 169 CustomTabsConnection.getInstance((Application) appContext); | 154 CustomTabsConnection.getInstance((Application) appContext); |
| 170 connection.setForcePrerender(true); | 155 connection.setForcePrerender(true); |
| 171 } | 156 } |
| 172 | 157 |
| 173 @Override | 158 @Override |
| 174 protected void tearDown() throws Exception { | 159 protected void tearDown() throws Exception { |
| 175 Context appContext = getInstrumentation().getTargetContext().getApplicat
ionContext(); | 160 Context appContext = getInstrumentation().getTargetContext().getApplicat
ionContext(); |
| 176 CustomTabsConnection connection = | 161 CustomTabsConnection connection = |
| 177 CustomTabsConnection.getInstance((Application) appContext); | 162 CustomTabsConnection.getInstance((Application) appContext); |
| 178 connection.setForcePrerender(false); | 163 connection.setForcePrerender(false); |
| 179 | 164 |
| 180 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
| 181 @Override | |
| 182 public void run() { | |
| 183 FirstRunStatus.setFirstRunFlowComplete(false); | |
| 184 } | |
| 185 }); | |
| 186 | |
| 187 mTestServer.stopAndDestroyServer(); | 165 mTestServer.stopAndDestroyServer(); |
| 188 | 166 |
| 189 // finish() is called on a non-UI thread by the testing harness. Must hi
de the menu | 167 // finish() is called on a non-UI thread by the testing harness. Must hi
de the menu |
| 190 // first, otherwise the UI is manipulated on a non-UI thread. | 168 // first, otherwise the UI is manipulated on a non-UI thread. |
| 191 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 169 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 192 @Override | 170 @Override |
| 193 public void run() { | 171 public void run() { |
| 194 if (mActivity == null) return; | 172 if (mActivity == null) return; |
| 195 AppMenuHandler handler = mActivity.getAppMenuHandler(); | 173 AppMenuHandler handler = mActivity.getAppMenuHandler(); |
| 196 if (handler != null) handler.hideAppMenu(); | 174 if (handler != null) handler.hideAppMenu(); |
| (...skipping 1931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2128 try { | 2106 try { |
| 2129 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCu
stomTabIntent( | 2107 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCu
stomTabIntent( |
| 2130 context, mTestPage)); | 2108 context, mTestPage)); |
| 2131 } catch (InterruptedException e) { | 2109 } catch (InterruptedException e) { |
| 2132 fail(); | 2110 fail(); |
| 2133 } | 2111 } |
| 2134 Tab tab = getActivity().getActivityTab(); | 2112 Tab tab = getActivity().getActivityTab(); |
| 2135 assertEquals(mTestPage, tab.getUrl()); | 2113 assertEquals(mTestPage, tab.getUrl()); |
| 2136 } | 2114 } |
| 2137 | 2115 |
| 2138 private CustomTabsConnection warmUpAndWait() { | |
| 2139 final Context context = getInstrumentation().getTargetContext().getAppli
cationContext(); | |
| 2140 CustomTabsConnection connection = | |
| 2141 CustomTabsTestUtils.setUpConnection((Application) context); | |
| 2142 final CallbackHelper startupCallbackHelper = new CallbackHelper(); | |
| 2143 assertTrue(connection.warmup(0)); | |
| 2144 ThreadUtils.runOnUiThread(new Runnable() { | |
| 2145 @Override | |
| 2146 public void run() { | |
| 2147 BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER) | |
| 2148 .addStartupCompletedObserver(new StartupCallback() { | |
| 2149 @Override | |
| 2150 public void onSuccess(boolean alreadyStarted) { | |
| 2151 startupCallbackHelper.notifyCalled(); | |
| 2152 } | |
| 2153 | |
| 2154 @Override | |
| 2155 public void onFailure() { | |
| 2156 fail(); | |
| 2157 } | |
| 2158 }); | |
| 2159 } | |
| 2160 }); | |
| 2161 | |
| 2162 try { | |
| 2163 startupCallbackHelper.waitForCallback(0); | |
| 2164 } catch (TimeoutException | InterruptedException e) { | |
| 2165 fail(); | |
| 2166 } | |
| 2167 return connection; | |
| 2168 } | |
| 2169 | |
| 2170 private ChromeActivity reparentAndVerifyTab() throws InterruptedException { | 2116 private ChromeActivity reparentAndVerifyTab() throws InterruptedException { |
| 2171 ActivityResult result = null; | 2117 ActivityResult result = null; |
| 2172 final ActivityMonitor monitor = getInstrumentation().addMonitor( | 2118 final ActivityMonitor monitor = getInstrumentation().addMonitor( |
| 2173 ChromeTabbedActivity.class.getName(), result, false); | 2119 ChromeTabbedActivity.class.getName(), result, false); |
| 2174 final Tab tabToBeReparented = mActivity.getActivityTab(); | 2120 final Tab tabToBeReparented = mActivity.getActivityTab(); |
| 2175 final CallbackHelper tabHiddenHelper = new CallbackHelper(); | 2121 final CallbackHelper tabHiddenHelper = new CallbackHelper(); |
| 2176 TabObserver observer = new EmptyTabObserver() { | 2122 TabObserver observer = new EmptyTabObserver() { |
| 2177 @Override | 2123 @Override |
| 2178 public void onHidden(Tab tab) { | 2124 public void onHidden(Tab tab) { |
| 2179 tabHiddenHelper.notifyCalled(); | 2125 tabHiddenHelper.notifyCalled(); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2338 | 2284 |
| 2339 private static String getExpectedVisibilityForSpeculationMode(int speculatio
nMode) { | 2285 private static String getExpectedVisibilityForSpeculationMode(int speculatio
nMode) { |
| 2340 switch (speculationMode) { | 2286 switch (speculationMode) { |
| 2341 case CustomTabsConnection.SpeculationParams.PRERENDER: | 2287 case CustomTabsConnection.SpeculationParams.PRERENDER: |
| 2342 return "prerender"; | 2288 return "prerender"; |
| 2343 default: | 2289 default: |
| 2344 return "visible"; | 2290 return "visible"; |
| 2345 } | 2291 } |
| 2346 } | 2292 } |
| 2347 } | 2293 } |
| OLD | NEW |