Chromium Code Reviews| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 import org.chromium.content.browser.test.util.Criteria; | 81 import org.chromium.content.browser.test.util.Criteria; |
| 82 import org.chromium.content.browser.test.util.CriteriaHelper; | 82 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 83 import org.chromium.content.browser.test.util.DOMUtils; | 83 import org.chromium.content.browser.test.util.DOMUtils; |
| 84 import org.chromium.content.browser.test.util.JavaScriptUtils; | 84 import org.chromium.content.browser.test.util.JavaScriptUtils; |
| 85 import org.chromium.content_public.browser.LoadUrlParams; | 85 import org.chromium.content_public.browser.LoadUrlParams; |
| 86 import org.chromium.content_public.browser.WebContentsObserver; | 86 import org.chromium.content_public.browser.WebContentsObserver; |
| 87 import org.chromium.net.test.EmbeddedTestServer; | 87 import org.chromium.net.test.EmbeddedTestServer; |
| 88 import org.chromium.net.test.util.TestWebServer; | 88 import org.chromium.net.test.util.TestWebServer; |
| 89 | 89 |
| 90 import java.util.ArrayList; | 90 import java.util.ArrayList; |
| 91 import java.util.List; | |
| 91 import java.util.concurrent.Callable; | 92 import java.util.concurrent.Callable; |
| 92 import java.util.concurrent.TimeoutException; | 93 import java.util.concurrent.TimeoutException; |
| 93 import java.util.concurrent.atomic.AtomicBoolean; | 94 import java.util.concurrent.atomic.AtomicBoolean; |
| 94 import java.util.concurrent.atomic.AtomicReference; | 95 import java.util.concurrent.atomic.AtomicReference; |
| 95 | 96 |
| 96 /** | 97 /** |
| 97 * Instrumentation tests for app menu, context menu, and toolbar of a {@link Cus tomTabActivity}. | 98 * Instrumentation tests for app menu, context menu, and toolbar of a {@link Cus tomTabActivity}. |
| 98 */ | 99 */ |
| 99 public class CustomTabActivityTest extends CustomTabActivityTestBase { | 100 public class CustomTabActivityTest extends CustomTabActivityTestBase { |
| 100 private static final int MAX_MENU_CUSTOM_ITEMS = 5; | 101 private static final int MAX_MENU_CUSTOM_ITEMS = 5; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 + " </script>" | 134 + " </script>" |
| 134 + "</body></html>"; | 135 + "</body></html>"; |
| 135 | 136 |
| 136 private static int sIdToIncrement = 1; | 137 private static int sIdToIncrement = 1; |
| 137 | 138 |
| 138 private CustomTabActivity mActivity; | 139 private CustomTabActivity mActivity; |
| 139 private String mTestPage; | 140 private String mTestPage; |
| 140 private String mTestPage2; | 141 private String mTestPage2; |
| 141 private EmbeddedTestServer mTestServer; | 142 private EmbeddedTestServer mTestServer; |
| 142 private TestWebServer mWebServer; | 143 private TestWebServer mWebServer; |
| 144 private int mDefaultDebugOverrideValue; | |
| 145 private int mLatestDebugOverrideValue; | |
|
ahemery1
2017/03/21 15:15:58
This is some sort of state that we use here only.
| |
| 143 | 146 |
| 144 @Override | 147 @Override |
| 145 protected void setUp() throws Exception { | 148 protected void setUp() throws Exception { |
| 146 super.setUp(); | 149 super.setUp(); |
| 147 | 150 |
| 148 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 151 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 149 @Override | 152 @Override |
| 150 public void run() { | 153 public void run() { |
| 151 FirstRunStatus.setFirstRunFlowComplete(true); | 154 FirstRunStatus.setFirstRunFlowComplete(true); |
| 152 } | 155 } |
| 153 }); | 156 }); |
| 154 | 157 |
| 155 Context appContext = getInstrumentation().getTargetContext().getApplicat ionContext(); | 158 Context appContext = getInstrumentation().getTargetContext().getApplicat ionContext(); |
| 156 mTestServer = EmbeddedTestServer.createAndStartServer(appContext); | 159 mTestServer = EmbeddedTestServer.createAndStartServer(appContext); |
| 157 mTestPage = mTestServer.getURL(TEST_PAGE); | 160 mTestPage = mTestServer.getURL(TEST_PAGE); |
| 158 mTestPage2 = mTestServer.getURL(TEST_PAGE_2); | 161 mTestPage2 = mTestServer.getURL(TEST_PAGE_2); |
| 159 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); | 162 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); |
| 160 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized( ); | 163 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized( ); |
| 161 mWebServer = TestWebServer.start(); | 164 mWebServer = TestWebServer.start(); |
| 162 | 165 |
| 163 CustomTabsConnection connection = | 166 CustomTabsConnection connection = |
| 164 CustomTabsConnection.getInstance((Application) appContext); | 167 CustomTabsConnection.getInstance((Application) appContext); |
| 165 connection.setForcePrerender(true); | 168 connection.setForcePrerender(true); |
| 169 mDefaultDebugOverrideValue = CustomTabsConnection.NO_OVERRIDE; | |
|
ahemery1
2017/03/21 15:15:58
The switch that can be acted upon to modify the en
| |
| 166 } | 170 } |
| 167 | 171 |
| 168 @Override | 172 @Override |
| 169 protected void tearDown() throws Exception { | 173 protected void tearDown() throws Exception { |
| 170 Context appContext = getInstrumentation().getTargetContext().getApplicat ionContext(); | 174 Context appContext = getInstrumentation().getTargetContext().getApplicat ionContext(); |
| 171 CustomTabsConnection connection = | 175 CustomTabsConnection connection = |
| 172 CustomTabsConnection.getInstance((Application) appContext); | 176 CustomTabsConnection.getInstance((Application) appContext); |
| 173 connection.setForcePrerender(false); | 177 connection.setForcePrerender(false); |
| 174 | 178 |
| 175 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 179 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| (...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1378 }); | 1382 }); |
| 1379 boolean channelRequested = false; | 1383 boolean channelRequested = false; |
| 1380 String titleString = ""; | 1384 String titleString = ""; |
| 1381 String currentMessage = ""; | 1385 String currentMessage = ""; |
| 1382 | 1386 |
| 1383 if (requestTime == BEFORE_MAY_LAUNCH_URL) { | 1387 if (requestTime == BEFORE_MAY_LAUNCH_URL) { |
| 1384 channelRequested = session.requestPostMessageChannel(null); | 1388 channelRequested = session.requestPostMessageChannel(null); |
| 1385 assertTrue(channelRequested); | 1389 assertTrue(channelRequested); |
| 1386 } | 1390 } |
| 1387 | 1391 |
| 1388 session.mayLaunchUrl(Uri.parse(url), null, null); | 1392 mayLaunchUrlForTesting(null, session, null, Uri.parse(url), null, null); |
| 1389 try { | 1393 try { |
| 1390 ensureCompletedPrerenderForUrl( | 1394 ensureCompletedPrerenderForUrl( |
| 1391 CustomTabsConnection.getInstance((Application) | 1395 CustomTabsConnection.getInstance((Application) |
| 1392 getInstrumentation().getTargetContext().getApplicati onContext()), url); | 1396 getInstrumentation().getTargetContext().getApplicati onContext()), url); |
| 1393 } catch (Exception e) { | 1397 } catch (Exception e) { |
| 1394 fail(); | 1398 fail(); |
| 1395 } | 1399 } |
| 1396 | 1400 |
| 1397 if (requestTime == BEFORE_INTENT) { | 1401 if (requestTime == BEFORE_INTENT) { |
| 1398 channelRequested = session.requestPostMessageChannel(null); | 1402 channelRequested = session.requestPostMessageChannel(null); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1477 */ | 1481 */ |
| 1478 @SmallTest | 1482 @SmallTest |
| 1479 @RetryOnFailure | 1483 @RetryOnFailure |
| 1480 public void testPrecreatedRenderer() throws InterruptedException { | 1484 public void testPrecreatedRenderer() throws InterruptedException { |
| 1481 CustomTabsConnection connection = warmUpAndWait(); | 1485 CustomTabsConnection connection = warmUpAndWait(); |
| 1482 Context context = getInstrumentation().getTargetContext(); | 1486 Context context = getInstrumentation().getTargetContext(); |
| 1483 Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(context , mTestPage); | 1487 Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(context , mTestPage); |
| 1484 CustomTabsSessionToken token = CustomTabsSessionToken.getSessionTokenFro mIntent(intent); | 1488 CustomTabsSessionToken token = CustomTabsSessionToken.getSessionTokenFro mIntent(intent); |
| 1485 assertTrue(connection.newSession(token)); | 1489 assertTrue(connection.newSession(token)); |
| 1486 Bundle extras = new Bundle(); | 1490 Bundle extras = new Bundle(); |
| 1491 // Forcing no prerendering implies falling back to simply creating a spa re WebContent | |
| 1487 extras.putInt( | 1492 extras.putInt( |
| 1488 CustomTabsConnection.DEBUG_OVERRIDE_KEY, CustomTabsConnection.NO _PRERENDERING); | 1493 CustomTabsConnection.DEBUG_OVERRIDE_KEY, CustomTabsConnection.NO _PRERENDERING); |
| 1489 assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), extras, null)); | 1494 assertTrue(mayLaunchUrlForTesting( |
| 1495 connection, null, token, Uri.parse(mTestPage), extras, null)); | |
| 1490 try { | 1496 try { |
| 1491 startCustomTabActivityWithIntent(intent); | 1497 startCustomTabActivityWithIntent(intent); |
| 1492 } catch (InterruptedException e) { | 1498 } catch (InterruptedException e) { |
| 1493 fail(); | 1499 fail(); |
| 1494 } | 1500 } |
| 1495 CriteriaHelper.pollInstrumentationThread(new Criteria() { | 1501 CriteriaHelper.pollInstrumentationThread(new Criteria() { |
| 1496 @Override | 1502 @Override |
| 1497 public boolean isSatisfied() { | 1503 public boolean isSatisfied() { |
| 1498 final Tab currentTab = getActivity().getActivityTab(); | 1504 final Tab currentTab = getActivity().getActivityTab(); |
| 1499 return mTestPage.equals(currentTab.getUrl()); | 1505 return mTestPage.equals(currentTab.getUrl()); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1619 String initialUrl = testUrl + initialFragment; | 1625 String initialUrl = testUrl + initialFragment; |
| 1620 String fragment = "#yeah"; | 1626 String fragment = "#yeah"; |
| 1621 String urlWithFragment = testUrl + fragment; | 1627 String urlWithFragment = testUrl + fragment; |
| 1622 | 1628 |
| 1623 Context context = getInstrumentation().getTargetContext().getApplication Context(); | 1629 Context context = getInstrumentation().getTargetContext().getApplication Context(); |
| 1624 CustomTabsConnection connection = warmUpAndWait(); | 1630 CustomTabsConnection connection = warmUpAndWait(); |
| 1625 Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(context , urlWithFragment); | 1631 Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(context , urlWithFragment); |
| 1626 CustomTabsSessionToken token = CustomTabsSessionToken.getSessionTokenFro mIntent(intent); | 1632 CustomTabsSessionToken token = CustomTabsSessionToken.getSessionTokenFro mIntent(intent); |
| 1627 connection.newSession(token); | 1633 connection.newSession(token); |
| 1628 connection.setIgnoreUrlFragmentsForSession(token, ignoreFragments); | 1634 connection.setIgnoreUrlFragmentsForSession(token, ignoreFragments); |
| 1629 assertTrue(connection.mayLaunchUrl(token, Uri.parse(initialUrl), null, n ull)); | 1635 assertTrue( |
| 1636 mayLaunchUrlForTesting(connection, null, token, Uri.parse(initia lUrl), null, null)); | |
| 1630 | 1637 |
| 1631 if (wait) ensureCompletedPrerenderForUrl(connection, initialUrl); | 1638 if (wait) ensureCompletedPrerenderForUrl(connection, initialUrl); |
| 1632 | 1639 |
| 1633 try { | 1640 try { |
| 1634 startCustomTabActivityWithIntent(intent); | 1641 startCustomTabActivityWithIntent(intent); |
| 1635 } catch (InterruptedException e) { | 1642 } catch (InterruptedException e) { |
| 1636 fail(); | 1643 fail(); |
| 1637 } | 1644 } |
| 1638 final Tab tab = mActivity.getActivityTab(); | 1645 final Tab tab = mActivity.getActivityTab(); |
| 1639 ElementContentCriteria initialVisibilityCriteria = new ElementContentCri teria( | |
| 1640 tab, "visibility", ignoreFragments ? "prerender" : "visible"); | |
| 1641 ElementContentCriteria initialFragmentCriteria = new ElementContentCrite ria( | |
| 1642 tab, "initial-fragment", ignoreFragments ? initialFragment : fra gment); | |
| 1643 ElementContentCriteria fragmentCriteria = new ElementContentCriteria( | |
| 1644 tab, "fragment", fragment); | |
| 1645 | 1646 |
| 1646 if (wait) { | 1647 if (wait) { |
| 1648 ElementContentCriteria initialVisibilityCriteria = new ElementConten tCriteria(tab, | |
|
ahemery1
2017/03/21 15:15:58
Unrelated change but used only inside the wait sco
| |
| 1649 "visibility", | |
| 1650 ignoreFragments ? getExpectedVisibilityForOverride(mLatestDe bugOverrideValue) | |
| 1651 : "visible"); | |
| 1652 ElementContentCriteria initialFragmentCriteria = new ElementContentC riteria( | |
| 1653 tab, "initial-fragment", ignoreFragments ? initialFragment : fragment); | |
| 1654 ElementContentCriteria fragmentCriteria = | |
| 1655 new ElementContentCriteria(tab, "fragment", fragment); | |
| 1647 // The tab hasn't been reloaded. | 1656 // The tab hasn't been reloaded. |
| 1648 CriteriaHelper.pollInstrumentationThread(initialVisibilityCriteria, 2000, 200); | 1657 CriteriaHelper.pollInstrumentationThread(initialVisibilityCriteria, 2000, 200); |
| 1649 // No reload (initial fragment is correct). | 1658 // No reload (initial fragment is correct). |
| 1650 CriteriaHelper.pollInstrumentationThread(initialFragmentCriteria, 20 00, 200); | 1659 CriteriaHelper.pollInstrumentationThread(initialFragmentCriteria, 20 00, 200); |
| 1651 if (ignoreFragments) { | 1660 if (ignoreFragments) { |
| 1652 CriteriaHelper.pollInstrumentationThread(fragmentCriteria, 2000, 200); | 1661 CriteriaHelper.pollInstrumentationThread(fragmentCriteria, 2000, 200); |
| 1653 } | 1662 } |
| 1654 } else { | 1663 } else { |
| 1655 CriteriaHelper.pollInstrumentationThread(new ElementContentCriteria( | 1664 CriteriaHelper.pollInstrumentationThread(new ElementContentCriteria( |
| 1656 tab, "initial-fragment", fragment), 2000, 200); | 1665 tab, "initial-fragment", fragment), 2000, 200); |
| 1657 } | 1666 } |
| 1658 assertFalse(tab.canGoForward()); | 1667 assertFalse(tab.canGoForward()); |
| 1659 assertFalse(tab.canGoBack()); | 1668 assertFalse(tab.canGoBack()); |
| 1660 } | 1669 } |
| 1661 | 1670 |
| 1662 /** | 1671 /** |
| 1663 * Test whether the url shown on prerender gets updated from about:blank whe n the prerender | 1672 * Test whether the url shown on prerender gets updated from about:blank whe n the prerender |
| 1664 * completes in the background. | 1673 * completes in the background. |
| 1665 * Non-regression test for crbug.com/554236. | 1674 * Non-regression test for crbug.com/554236. |
| 1666 */ | 1675 */ |
| 1667 @SmallTest | 1676 @SmallTest |
| 1668 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 1677 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 1669 @RetryOnFailure | 1678 @RetryOnFailure |
| 1670 public void testPrerenderingCorrectUrl() throws Exception { | 1679 public void testPrerenderingCorrectUrl() throws Exception { |
| 1671 Context context = getInstrumentation().getTargetContext().getApplication Context(); | 1680 Context context = getInstrumentation().getTargetContext().getApplication Context(); |
| 1672 final CustomTabsConnection connection = warmUpAndWait(); | 1681 final CustomTabsConnection connection = warmUpAndWait(); |
| 1673 CustomTabsSessionToken token = CustomTabsSessionToken.createDummySession TokenForTesting(); | 1682 CustomTabsSessionToken token = CustomTabsSessionToken.createDummySession TokenForTesting(); |
| 1674 connection.newSession(token); | 1683 connection.newSession(token); |
| 1675 assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), null, nu ll)); | 1684 assertTrue( |
| 1685 mayLaunchUrlForTesting(connection, null, token, Uri.parse(mTestP age), null, null)); | |
| 1676 ensureCompletedPrerenderForUrl(connection, mTestPage); | 1686 ensureCompletedPrerenderForUrl(connection, mTestPage); |
| 1677 | 1687 |
| 1678 try { | 1688 try { |
| 1679 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCu stomTabIntent( | 1689 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCu stomTabIntent( |
| 1680 context, mTestPage)); | 1690 context, mTestPage)); |
| 1681 } catch (InterruptedException e) { | 1691 } catch (InterruptedException e) { |
| 1682 fail(); | 1692 fail(); |
| 1683 } | 1693 } |
| 1684 assertEquals(Uri.parse(mTestPage).getHost() + ":" + Uri.parse(mTestPage) .getPort(), | 1694 assertEquals(Uri.parse(mTestPage).getHost() + ":" + Uri.parse(mTestPage) .getPort(), |
| 1685 ((EditText) mActivity.findViewById(R.id.url_bar)).getText() | 1695 ((EditText) mActivity.findViewById(R.id.url_bar)).getText() |
| 1686 .toString()); | 1696 .toString()); |
| 1687 } | 1697 } |
| 1688 | 1698 |
| 1689 /** | 1699 /** |
| 1690 * Test whether invalid urls are avoided for prerendering. | 1700 * Test whether invalid urls are avoided for prerendering. |
| 1691 */ | 1701 */ |
| 1692 @SmallTest | 1702 @SmallTest |
| 1693 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 1703 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 1694 @RetryOnFailure | 1704 @RetryOnFailure |
| 1695 public void testPrerenderingInvalidUrl() throws Exception { | 1705 public void testPrerenderingInvalidUrl() throws Exception { |
| 1696 final CustomTabsConnection connection = warmUpAndWait(); | 1706 final CustomTabsConnection connection = warmUpAndWait(); |
| 1697 CustomTabsSessionToken token = CustomTabsSessionToken.createDummySession TokenForTesting(); | 1707 CustomTabsSessionToken token = CustomTabsSessionToken.createDummySession TokenForTesting(); |
| 1698 connection.newSession(token); | 1708 connection.newSession(token); |
| 1699 assertFalse(connection.mayLaunchUrl(token, Uri.parse("chrome://version") , null, null)); | 1709 assertFalse(mayLaunchUrlForTesting( |
| 1710 connection, null, token, Uri.parse("chrome://version"), null, nu ll)); | |
| 1700 } | 1711 } |
| 1701 | 1712 |
| 1702 /** | 1713 /** |
| 1703 * Tests that the activity knows there is already a child process when warmu p() has been called. | 1714 * Tests that the activity knows there is already a child process when warmu p() has been called. |
| 1704 */ | 1715 */ |
| 1705 @SmallTest | 1716 @SmallTest |
| 1706 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 1717 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 1707 @RetryOnFailure | 1718 @RetryOnFailure |
| 1708 public void testAllocateChildConnectionWithWarmup() throws Exception { | 1719 public void testAllocateChildConnectionWithWarmup() throws Exception { |
| 1709 Context context = getInstrumentation().getTargetContext().getApplication Context(); | 1720 Context context = getInstrumentation().getTargetContext().getApplication Context(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1757 * Tests that the activity knows there is already a child process when prere ndering. | 1768 * Tests that the activity knows there is already a child process when prere ndering. |
| 1758 */ | 1769 */ |
| 1759 @SmallTest | 1770 @SmallTest |
| 1760 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 1771 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 1761 @RetryOnFailure | 1772 @RetryOnFailure |
| 1762 public void testAllocateChildConnectionWithPrerender() throws Exception { | 1773 public void testAllocateChildConnectionWithPrerender() throws Exception { |
| 1763 Context context = getInstrumentation().getTargetContext().getApplication Context(); | 1774 Context context = getInstrumentation().getTargetContext().getApplication Context(); |
| 1764 final CustomTabsConnection connection = warmUpAndWait(); | 1775 final CustomTabsConnection connection = warmUpAndWait(); |
| 1765 CustomTabsSessionToken token = CustomTabsSessionToken.createDummySession TokenForTesting(); | 1776 CustomTabsSessionToken token = CustomTabsSessionToken.createDummySession TokenForTesting(); |
| 1766 connection.newSession(token); | 1777 connection.newSession(token); |
| 1767 assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), null, nu ll)); | 1778 assertTrue( |
| 1779 mayLaunchUrlForTesting(connection, null, token, Uri.parse(mTestP age), null, null)); | |
| 1768 try { | 1780 try { |
| 1769 startCustomTabActivityWithIntent( | 1781 startCustomTabActivityWithIntent( |
| 1770 CustomTabsTestUtils.createMinimalCustomTabIntent(context, mT estPage)); | 1782 CustomTabsTestUtils.createMinimalCustomTabIntent(context, mT estPage)); |
| 1771 } catch (InterruptedException e) { | 1783 } catch (InterruptedException e) { |
| 1772 fail(); | 1784 fail(); |
| 1773 } | 1785 } |
| 1774 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 1786 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 1775 @Override | 1787 @Override |
| 1776 public void run() { | 1788 public void run() { |
| 1777 assertFalse("Prerendering should have allocated a child connecti on", | 1789 assertFalse("Prerendering should have allocated a child connecti on", |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1817 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 1829 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 1818 @RetryOnFailure | 1830 @RetryOnFailure |
| 1819 public void testPrerenderingWithReferrer() throws Exception { | 1831 public void testPrerenderingWithReferrer() throws Exception { |
| 1820 String referrer = "android-app://com.foo.me/"; | 1832 String referrer = "android-app://com.foo.me/"; |
| 1821 maybePrerenderAndLaunchWithReferrers( | 1833 maybePrerenderAndLaunchWithReferrers( |
| 1822 mTestServer.getURL(FRAGMENT_TEST_PAGE), true, referrer, referrer ); | 1834 mTestServer.getURL(FRAGMENT_TEST_PAGE), true, referrer, referrer ); |
| 1823 | 1835 |
| 1824 Tab tab = mActivity.getActivityTab(); | 1836 Tab tab = mActivity.getActivityTab(); |
| 1825 // The tab hasn't been reloaded. | 1837 // The tab hasn't been reloaded. |
| 1826 CriteriaHelper.pollInstrumentationThread( | 1838 CriteriaHelper.pollInstrumentationThread( |
| 1827 new ElementContentCriteria(tab, "visibility", "prerender"), 2000 , 200); | 1839 new ElementContentCriteria(tab, "visibility", |
| 1840 getExpectedVisibilityForOverride(mLatestDebugOverrideVal ue)), | |
| 1841 2000, 200); | |
| 1828 // The Referrer is correctly set. | 1842 // The Referrer is correctly set. |
| 1829 CriteriaHelper.pollInstrumentationThread( | 1843 CriteriaHelper.pollInstrumentationThread( |
| 1830 new TabsOpenedFromExternalAppTest.ReferrerCriteria(tab, referrer ), 2000, 200); | 1844 new TabsOpenedFromExternalAppTest.ReferrerCriteria(tab, referrer ), 2000, 200); |
| 1831 } | 1845 } |
| 1832 | 1846 |
| 1833 /** | 1847 /** |
| 1834 * Tests that prerendering accepts a referrer, and that the prerender is dro pped when the tab | 1848 * Tests that prerendering accepts a referrer, and that the prerender is dro pped when the tab |
| 1835 * is launched with a mismatched referrer. | 1849 * is launched with a mismatched referrer. |
| 1836 */ | 1850 */ |
| 1837 @SmallTest | 1851 @SmallTest |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1969 Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(context , url); | 1983 Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(context , url); |
| 1970 if (prerender) { | 1984 if (prerender) { |
| 1971 connection = warmUpAndWait(); | 1985 connection = warmUpAndWait(); |
| 1972 token = CustomTabsSessionToken.getSessionTokenFromIntent(intent); | 1986 token = CustomTabsSessionToken.getSessionTokenFromIntent(intent); |
| 1973 connection.newSession(token); | 1987 connection.newSession(token); |
| 1974 Bundle extras = null; | 1988 Bundle extras = null; |
| 1975 if (prerenderReferrer != null) { | 1989 if (prerenderReferrer != null) { |
| 1976 extras = new Bundle(); | 1990 extras = new Bundle(); |
| 1977 extras.putParcelable(Intent.EXTRA_REFERRER, Uri.parse(prerenderR eferrer)); | 1991 extras.putParcelable(Intent.EXTRA_REFERRER, Uri.parse(prerenderR eferrer)); |
| 1978 } | 1992 } |
| 1979 assertTrue(connection.mayLaunchUrl(token, Uri.parse(url), extras, nu ll)); | 1993 assertTrue( |
| 1994 mayLaunchUrlForTesting(connection, null, token, Uri.parse(ur l), extras, null)); | |
| 1980 ensureCompletedPrerenderForUrl(connection, url); | 1995 ensureCompletedPrerenderForUrl(connection, url); |
| 1981 } | 1996 } |
| 1982 | 1997 |
| 1983 if (launchReferrer != null) { | 1998 if (launchReferrer != null) { |
| 1984 intent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(launchReferrer)); | 1999 intent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(launchReferrer)); |
| 1985 } | 2000 } |
| 1986 try { | 2001 try { |
| 1987 startCustomTabActivityWithIntent(intent); | 2002 startCustomTabActivityWithIntent(intent); |
| 1988 } catch (InterruptedException e) { | 2003 } catch (InterruptedException e) { |
| 1989 fail(); | 2004 fail(); |
| 1990 } | 2005 } |
| 1991 } | 2006 } |
| 1992 | 2007 |
| 1993 private void mayLaunchUrlWithoutWarmup(boolean noPrerendering) { | 2008 private void mayLaunchUrlWithoutWarmup(boolean noPrerendering) { |
| 1994 Context context = getInstrumentation().getTargetContext().getApplication Context(); | 2009 Context context = getInstrumentation().getTargetContext().getApplication Context(); |
| 1995 CustomTabsConnection connection = | 2010 CustomTabsConnection connection = |
| 1996 CustomTabsTestUtils.setUpConnection((Application) context); | 2011 CustomTabsTestUtils.setUpConnection((Application) context); |
| 1997 CustomTabsSessionToken token = CustomTabsSessionToken.createDummySession TokenForTesting(); | 2012 CustomTabsSessionToken token = CustomTabsSessionToken.createDummySession TokenForTesting(); |
| 1998 connection.newSession(token); | 2013 connection.newSession(token); |
| 1999 Bundle extras = null; | 2014 Bundle extras = null; |
| 2000 if (noPrerendering) { | 2015 if (noPrerendering) { |
| 2001 extras = new Bundle(); | 2016 extras = new Bundle(); |
| 2002 extras.putInt( | 2017 extras.putInt( |
| 2003 CustomTabsConnection.DEBUG_OVERRIDE_KEY, CustomTabsConnectio n.NO_PRERENDERING); | 2018 CustomTabsConnection.DEBUG_OVERRIDE_KEY, CustomTabsConnectio n.NO_PRERENDERING); |
| 2004 } | 2019 } |
| 2005 assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), extras, null)); | 2020 assertTrue(mayLaunchUrlForTesting( |
| 2021 connection, null, token, Uri.parse(mTestPage), extras, null)); | |
| 2006 try { | 2022 try { |
| 2007 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCu stomTabIntent( | 2023 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCu stomTabIntent( |
| 2008 context, mTestPage)); | 2024 context, mTestPage)); |
| 2009 } catch (InterruptedException e) { | 2025 } catch (InterruptedException e) { |
| 2010 fail(); | 2026 fail(); |
| 2011 } | 2027 } |
| 2012 Tab tab = getActivity().getActivityTab(); | 2028 Tab tab = getActivity().getActivityTab(); |
| 2013 assertEquals(mTestPage, tab.getUrl()); | 2029 assertEquals(mTestPage, tab.getUrl()); |
| 2014 } | 2030 } |
| 2015 | 2031 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2106 } | 2122 } |
| 2107 | 2123 |
| 2108 private CustomTabsSessionToken warmUpAndLaunchUrlWithSession() throws Interr uptedException { | 2124 private CustomTabsSessionToken warmUpAndLaunchUrlWithSession() throws Interr uptedException { |
| 2109 return warmUpAndLaunchUrlWithSession( | 2125 return warmUpAndLaunchUrlWithSession( |
| 2110 CustomTabsTestUtils.createMinimalCustomTabIntent( | 2126 CustomTabsTestUtils.createMinimalCustomTabIntent( |
| 2111 getInstrumentation().getTargetContext(), mTestPage)); | 2127 getInstrumentation().getTargetContext(), mTestPage)); |
| 2112 } | 2128 } |
| 2113 | 2129 |
| 2114 private static void ensureCompletedPrerenderForUrl( | 2130 private static void ensureCompletedPrerenderForUrl( |
| 2115 final CustomTabsConnection connection, final String url) throws Exce ption { | 2131 final CustomTabsConnection connection, final String url) throws Exce ption { |
| 2116 CriteriaHelper.pollUiThread(new Criteria("No Prerender") { | 2132 // We wait until we have a speculation to pull information from first. |
| 2133 CriteriaHelper.pollInstrumentationThread(new Criteria("No Speculation") { | |
| 2117 @Override | 2134 @Override |
| 2118 public boolean isSatisfied() { | 2135 public boolean isSatisfied() { |
| 2119 return connection.mSpeculation != null | 2136 return connection.mSpeculation != null; |
| 2120 && connection.mSpeculation.webContents != null | |
| 2121 && ExternalPrerenderHandler.hasPrerenderedAndFinishedLoa dingUrl( | |
| 2122 Profile.getLastUsedProfile(), url, | |
| 2123 connection.mSpeculation.webContents); | |
| 2124 } | 2137 } |
| 2125 }, LONG_TIMEOUT_MS, CriteriaHelper.DEFAULT_POLLING_INTERVAL); | 2138 }, LONG_TIMEOUT_MS, CriteriaHelper.DEFAULT_POLLING_INTERVAL); |
| 2139 | |
| 2140 // Then do the specific depending on debug override. | |
| 2141 if (connection.mSpeculation.debugOverrideValue == CustomTabsConnection.N O_OVERRIDE) { | |
|
ahemery1
2017/03/21 15:15:58
We are sure this exist so we can use this value he
| |
| 2142 CriteriaHelper.pollUiThread(new Criteria("No Prerender") { | |
| 2143 @Override | |
| 2144 public boolean isSatisfied() { | |
| 2145 return connection.mSpeculation.webContents != null | |
| 2146 && ExternalPrerenderHandler.hasPrerenderedAndFinishe dLoadingUrl( | |
| 2147 Profile.getLastUsedProfile(), url, | |
| 2148 connection.mSpeculation.webContents); | |
| 2149 } | |
| 2150 }, LONG_TIMEOUT_MS, CriteriaHelper.DEFAULT_POLLING_INTERVAL); | |
| 2151 } | |
| 2126 } | 2152 } |
| 2127 | 2153 |
| 2128 private CustomTabsSession bindWithCallback(final CustomTabsCallback callback ) { | 2154 private CustomTabsSession bindWithCallback(final CustomTabsCallback callback ) { |
| 2129 final AtomicReference<CustomTabsSession> sessionReference = new AtomicRe ference<>(null); | 2155 final AtomicReference<CustomTabsSession> sessionReference = new AtomicRe ference<>(null); |
| 2130 CustomTabsClient.bindCustomTabsService(getInstrumentation().getContext() , | 2156 CustomTabsClient.bindCustomTabsService(getInstrumentation().getContext() , |
| 2131 getInstrumentation().getTargetContext().getPackageName(), | 2157 getInstrumentation().getTargetContext().getPackageName(), |
| 2132 new CustomTabsServiceConnection() { | 2158 new CustomTabsServiceConnection() { |
| 2133 @Override | 2159 @Override |
| 2134 public void onServiceDisconnected(ComponentName name) {} | 2160 public void onServiceDisconnected(ComponentName name) {} |
| 2135 | 2161 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2203 mTab.getWebContents(), mJsFunction); | 2229 mTab.getWebContents(), mJsFunction); |
| 2204 if (jsonText.equalsIgnoreCase("null")) jsonText = ""; | 2230 if (jsonText.equalsIgnoreCase("null")) jsonText = ""; |
| 2205 value = jsonText; | 2231 value = jsonText; |
| 2206 } catch (InterruptedException | TimeoutException e) { | 2232 } catch (InterruptedException | TimeoutException e) { |
| 2207 e.printStackTrace(); | 2233 e.printStackTrace(); |
| 2208 return false; | 2234 return false; |
| 2209 } | 2235 } |
| 2210 return TextUtils.equals(mExpected, value); | 2236 return TextUtils.equals(mExpected, value); |
| 2211 } | 2237 } |
| 2212 } | 2238 } |
| 2239 | |
| 2240 private boolean mayLaunchUrlForTesting(CustomTabsConnection connection, | |
|
ahemery1
2017/03/21 15:15:58
A wrapper that allows us to do some additional ins
| |
| 2241 CustomTabsSession session, CustomTabsSessionToken token, Uri url, Bu ndle extras, | |
| 2242 List<Bundle> otherLikelyBundles) { | |
| 2243 instrumentExtrasForTesting(extras); | |
| 2244 if (connection != null) { | |
| 2245 return connection.mayLaunchUrl(token, url, extras, otherLikelyBundle s); | |
| 2246 } | |
| 2247 if (session != null) { | |
| 2248 return session.mayLaunchUrl(url, extras, otherLikelyBundles); | |
| 2249 } | |
| 2250 return false; | |
| 2251 } | |
| 2252 | |
| 2253 /* | |
| 2254 * Does the following modifications to the extras bundle : | |
| 2255 * - Uses the default debug override if none is specified. | |
| 2256 */ | |
| 2257 private void instrumentExtrasForTesting(Bundle extras) { | |
| 2258 if (extras == null) extras = new Bundle(); | |
| 2259 int debugOverrideValue = | |
| 2260 extras.getInt(CustomTabsConnection.DEBUG_OVERRIDE_KEY, mDefaultD ebugOverrideValue); | |
| 2261 extras.putInt(CustomTabsConnection.DEBUG_OVERRIDE_KEY, debugOverrideValu e); | |
| 2262 mLatestDebugOverrideValue = debugOverrideValue; | |
| 2263 } | |
| 2264 | |
| 2265 private static String getExpectedVisibilityForOverride(int mode) { | |
| 2266 switch (mode) { | |
| 2267 case CustomTabsConnection.NO_OVERRIDE: | |
| 2268 return "prerender"; | |
| 2269 default: | |
| 2270 return "visible"; | |
| 2271 } | |
| 2272 } | |
| 2213 } | 2273 } |
| OLD | NEW |