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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 mTestServer = EmbeddedTestServer.createAndStartServer(appContext); | 156 mTestServer = EmbeddedTestServer.createAndStartServer(appContext); |
157 mTestPage = mTestServer.getURL(TEST_PAGE); | 157 mTestPage = mTestServer.getURL(TEST_PAGE); |
158 mTestPage2 = mTestServer.getURL(TEST_PAGE_2); | 158 mTestPage2 = mTestServer.getURL(TEST_PAGE_2); |
159 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); | 159 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); |
160 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized( ); | 160 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized( ); |
161 mWebServer = TestWebServer.start(); | 161 mWebServer = TestWebServer.start(); |
162 | 162 |
163 CustomTabsConnection connection = | 163 CustomTabsConnection connection = |
164 CustomTabsConnection.getInstance((Application) appContext); | 164 CustomTabsConnection.getInstance((Application) appContext); |
165 connection.setForcePrerender(true); | 165 connection.setForcePrerender(true); |
166 connection.setPrerenderMode(CustomTabsConnection.DEFAULT_PRERENDER); | |
166 } | 167 } |
167 | 168 |
168 @Override | 169 @Override |
169 protected void tearDown() throws Exception { | 170 protected void tearDown() throws Exception { |
170 Context appContext = getInstrumentation().getTargetContext().getApplicat ionContext(); | 171 Context appContext = getInstrumentation().getTargetContext().getApplicat ionContext(); |
171 CustomTabsConnection connection = | 172 CustomTabsConnection connection = |
172 CustomTabsConnection.getInstance((Application) appContext); | 173 CustomTabsConnection.getInstance((Application) appContext); |
173 connection.setForcePrerender(false); | 174 connection.setForcePrerender(false); |
174 | 175 |
175 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 176 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
(...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1477 */ | 1478 */ |
1478 @SmallTest | 1479 @SmallTest |
1479 @RetryOnFailure | 1480 @RetryOnFailure |
1480 public void testPrecreatedRenderer() throws InterruptedException { | 1481 public void testPrecreatedRenderer() throws InterruptedException { |
1481 CustomTabsConnection connection = warmUpAndWait(); | 1482 CustomTabsConnection connection = warmUpAndWait(); |
1482 Context context = getInstrumentation().getTargetContext(); | 1483 Context context = getInstrumentation().getTargetContext(); |
1483 Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(context , mTestPage); | 1484 Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(context , mTestPage); |
1484 CustomTabsSessionToken token = CustomTabsSessionToken.getSessionTokenFro mIntent(intent); | 1485 CustomTabsSessionToken token = CustomTabsSessionToken.getSessionTokenFro mIntent(intent); |
1485 assertTrue(connection.newSession(token)); | 1486 assertTrue(connection.newSession(token)); |
1486 Bundle extras = new Bundle(); | 1487 Bundle extras = new Bundle(); |
1488 // Forcing no prerendering implies falling back to simply creating a spa re WebContent | |
ahemery
2017/03/16 17:28:35
Unrelated comment to help readability
| |
1487 extras.putInt( | 1489 extras.putInt( |
1488 CustomTabsConnection.DEBUG_OVERRIDE_KEY, CustomTabsConnection.NO _PRERENDERING); | 1490 CustomTabsConnection.DEBUG_OVERRIDE_KEY, CustomTabsConnection.NO _PRERENDERING); |
1489 assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), extras, null)); | 1491 assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), extras, null)); |
1490 try { | 1492 try { |
1491 startCustomTabActivityWithIntent(intent); | 1493 startCustomTabActivityWithIntent(intent); |
1492 } catch (InterruptedException e) { | 1494 } catch (InterruptedException e) { |
1493 fail(); | 1495 fail(); |
1494 } | 1496 } |
1495 CriteriaHelper.pollInstrumentationThread(new Criteria() { | 1497 CriteriaHelper.pollInstrumentationThread(new Criteria() { |
1496 @Override | 1498 @Override |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1630 | 1632 |
1631 if (wait) ensureCompletedPrerenderForUrl(connection, initialUrl); | 1633 if (wait) ensureCompletedPrerenderForUrl(connection, initialUrl); |
1632 | 1634 |
1633 try { | 1635 try { |
1634 startCustomTabActivityWithIntent(intent); | 1636 startCustomTabActivityWithIntent(intent); |
1635 } catch (InterruptedException e) { | 1637 } catch (InterruptedException e) { |
1636 fail(); | 1638 fail(); |
1637 } | 1639 } |
1638 final Tab tab = mActivity.getActivityTab(); | 1640 final Tab tab = mActivity.getActivityTab(); |
1639 ElementContentCriteria initialVisibilityCriteria = new ElementContentCri teria( | 1641 ElementContentCriteria initialVisibilityCriteria = new ElementContentCri teria( |
1640 tab, "visibility", ignoreFragments ? "prerender" : "visible"); | 1642 tab, "visibility", ignoreFragments ? getBaseExpectedVisibility() : "visible"); |
ahemery
2017/03/16 17:28:35
Since prerender visibility is prerender and hidden
| |
1641 ElementContentCriteria initialFragmentCriteria = new ElementContentCrite ria( | 1643 ElementContentCriteria initialFragmentCriteria = new ElementContentCrite ria( |
1642 tab, "initial-fragment", ignoreFragments ? initialFragment : fra gment); | 1644 tab, "initial-fragment", ignoreFragments ? initialFragment : fra gment); |
1643 ElementContentCriteria fragmentCriteria = new ElementContentCriteria( | 1645 ElementContentCriteria fragmentCriteria = new ElementContentCriteria( |
1644 tab, "fragment", fragment); | 1646 tab, "fragment", fragment); |
1645 | 1647 |
1646 if (wait) { | 1648 if (wait) { |
1647 // The tab hasn't been reloaded. | 1649 // The tab hasn't been reloaded. |
1648 CriteriaHelper.pollInstrumentationThread(initialVisibilityCriteria, 2000, 200); | 1650 CriteriaHelper.pollInstrumentationThread(initialVisibilityCriteria, 2000, 200); |
1649 // No reload (initial fragment is correct). | 1651 // No reload (initial fragment is correct). |
1650 CriteriaHelper.pollInstrumentationThread(initialFragmentCriteria, 20 00, 200); | 1652 CriteriaHelper.pollInstrumentationThread(initialFragmentCriteria, 20 00, 200); |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2106 } | 2108 } |
2107 | 2109 |
2108 private CustomTabsSessionToken warmUpAndLaunchUrlWithSession() throws Interr uptedException { | 2110 private CustomTabsSessionToken warmUpAndLaunchUrlWithSession() throws Interr uptedException { |
2109 return warmUpAndLaunchUrlWithSession( | 2111 return warmUpAndLaunchUrlWithSession( |
2110 CustomTabsTestUtils.createMinimalCustomTabIntent( | 2112 CustomTabsTestUtils.createMinimalCustomTabIntent( |
2111 getInstrumentation().getTargetContext(), mTestPage)); | 2113 getInstrumentation().getTargetContext(), mTestPage)); |
2112 } | 2114 } |
2113 | 2115 |
2114 private static void ensureCompletedPrerenderForUrl( | 2116 private static void ensureCompletedPrerenderForUrl( |
2115 final CustomTabsConnection connection, final String url) throws Exce ption { | 2117 final CustomTabsConnection connection, final String url) throws Exce ption { |
2116 CriteriaHelper.pollUiThread(new Criteria("No Prerender") { | 2118 if (connection.mPrerenderMode == CustomTabsConnection.DEFAULT_PRERENDER) { |
2117 @Override | 2119 CriteriaHelper.pollUiThread(new Criteria("No Prerender") { |
2118 public boolean isSatisfied() { | 2120 @Override |
2119 return connection.mSpeculation != null | 2121 public boolean isSatisfied() { |
2120 && connection.mSpeculation.webContents != null | 2122 return connection.mSpeculation != null |
2121 && ExternalPrerenderHandler.hasPrerenderedAndFinishedLoa dingUrl( | 2123 && connection.mSpeculation.webContents != null |
2122 Profile.getLastUsedProfile(), url, | 2124 && ExternalPrerenderHandler.hasPrerenderedAndFinishe dLoadingUrl( |
2123 connection.mSpeculation.webContents); | 2125 Profile.getLastUsedProfile(), url, |
2124 } | 2126 connection.mSpeculation.webContents); |
2125 }, LONG_TIMEOUT_MS, CriteriaHelper.DEFAULT_POLLING_INTERVAL); | 2127 } |
2128 }, LONG_TIMEOUT_MS, CriteriaHelper.DEFAULT_POLLING_INTERVAL); | |
2129 } | |
2126 } | 2130 } |
2127 | 2131 |
2128 private CustomTabsSession bindWithCallback(final CustomTabsCallback callback ) { | 2132 private CustomTabsSession bindWithCallback(final CustomTabsCallback callback ) { |
2129 final AtomicReference<CustomTabsSession> sessionReference = new AtomicRe ference<>(null); | 2133 final AtomicReference<CustomTabsSession> sessionReference = new AtomicRe ference<>(null); |
2130 CustomTabsClient.bindCustomTabsService(getInstrumentation().getContext() , | 2134 CustomTabsClient.bindCustomTabsService(getInstrumentation().getContext() , |
2131 getInstrumentation().getTargetContext().getPackageName(), | 2135 getInstrumentation().getTargetContext().getPackageName(), |
2132 new CustomTabsServiceConnection() { | 2136 new CustomTabsServiceConnection() { |
2133 @Override | 2137 @Override |
2134 public void onServiceDisconnected(ComponentName name) {} | 2138 public void onServiceDisconnected(ComponentName name) {} |
2135 | 2139 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2203 mTab.getWebContents(), mJsFunction); | 2207 mTab.getWebContents(), mJsFunction); |
2204 if (jsonText.equalsIgnoreCase("null")) jsonText = ""; | 2208 if (jsonText.equalsIgnoreCase("null")) jsonText = ""; |
2205 value = jsonText; | 2209 value = jsonText; |
2206 } catch (InterruptedException | TimeoutException e) { | 2210 } catch (InterruptedException | TimeoutException e) { |
2207 e.printStackTrace(); | 2211 e.printStackTrace(); |
2208 return false; | 2212 return false; |
2209 } | 2213 } |
2210 return TextUtils.equals(mExpected, value); | 2214 return TextUtils.equals(mExpected, value); |
2211 } | 2215 } |
2212 } | 2216 } |
2217 | |
2218 private String getBaseExpectedVisibility() { | |
2219 final Context context = getInstrumentation().getTargetContext().getAppli cationContext(); | |
2220 CustomTabsConnection connection = CustomTabsConnection.getInstance((Appl ication) context); | |
2221 return getExpectedVisibilityForMode(connection.mPrerenderMode); | |
2222 } | |
2223 | |
2224 private static String getExpectedVisibilityForMode(int mode) { | |
2225 switch (mode) { | |
2226 case CustomTabsConnection.DEFAULT_PRERENDER: | |
2227 return "prerender"; | |
2228 default: | |
2229 return "visible"; | |
2230 } | |
2231 } | |
2213 } | 2232 } |
OLD | NEW |