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 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1359 @SmallTest | 1359 @SmallTest |
1360 @RetryOnFailure | 1360 @RetryOnFailure |
1361 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 1361 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
1362 public void testPostMessageThroughPrerenderWithRequestAfterIntent() | 1362 public void testPostMessageThroughPrerenderWithRequestAfterIntent() |
1363 throws InterruptedException { | 1363 throws InterruptedException { |
1364 sendPostMessageDuringPrerenderTransition(AFTER_INTENT); | 1364 sendPostMessageDuringPrerenderTransition(AFTER_INTENT); |
1365 } | 1365 } |
1366 | 1366 |
1367 private void sendPostMessageDuringPrerenderTransition(int requestTime) | 1367 private void sendPostMessageDuringPrerenderTransition(int requestTime) |
1368 throws InterruptedException { | 1368 throws InterruptedException { |
1369 sendPostMessageDuringSpeculationTransition( | |
1370 requestTime, CustomTabsConnection.SpeculationParams.PRERENDER); | |
1371 } | |
1372 | |
1373 private void sendPostMessageDuringSpeculationTransition(int requestTime, int speculationMode) | |
1374 throws InterruptedException { | |
1369 final CallbackHelper messageChannelHelper = new CallbackHelper(); | 1375 final CallbackHelper messageChannelHelper = new CallbackHelper(); |
1370 final String url = | 1376 final String url = |
1371 mWebServer.setResponse("/test.html", TITLE_FROM_POSTMESSAGE_TO_C HANNEL, null); | 1377 mWebServer.setResponse("/test.html", TITLE_FROM_POSTMESSAGE_TO_C HANNEL, null); |
1372 warmUpAndWait(); | 1378 final CustomTabsConnection connection = warmUpAndWait(); |
1379 | |
1373 final CustomTabsSession session = bindWithCallback(new CustomTabsCallbac k() { | 1380 final CustomTabsSession session = bindWithCallback(new CustomTabsCallbac k() { |
1374 @Override | 1381 @Override |
1375 public void onMessageChannelReady(Bundle extras) { | 1382 public void onMessageChannelReady(Bundle extras) { |
1376 messageChannelHelper.notifyCalled(); | 1383 messageChannelHelper.notifyCalled(); |
1377 } | 1384 } |
1378 }); | 1385 }); |
1386 | |
1387 Intent intent = new CustomTabsIntent.Builder(session).build().intent; | |
1388 intent.setData(Uri.parse(url)); | |
1389 intent.setComponent(new ComponentName( | |
1390 getInstrumentation().getTargetContext(), ChromeLauncherActivity. class)); | |
1391 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
1392 final CustomTabsSessionToken token = | |
Benoit L
2017/03/23 18:28:29
tiny nit: unnecessary final.
ahemery1
2017/03/27 12:27:32
Done.
| |
1393 CustomTabsSessionToken.getSessionTokenFromIntent(intent); | |
1394 | |
1379 boolean channelRequested = false; | 1395 boolean channelRequested = false; |
1380 String titleString = ""; | 1396 String titleString = ""; |
1381 String currentMessage = ""; | 1397 String currentMessage = ""; |
1382 | 1398 |
1383 if (requestTime == BEFORE_MAY_LAUNCH_URL) { | 1399 if (requestTime == BEFORE_MAY_LAUNCH_URL) { |
1384 channelRequested = session.requestPostMessageChannel(null); | 1400 channelRequested = session.requestPostMessageChannel(null); |
1385 assertTrue(channelRequested); | 1401 assertTrue(channelRequested); |
1386 } | 1402 } |
1387 | 1403 |
1404 connection.setSpeculationModeForSession(token, speculationMode); | |
1388 session.mayLaunchUrl(Uri.parse(url), null, null); | 1405 session.mayLaunchUrl(Uri.parse(url), null, null); |
1389 try { | 1406 try { |
1390 ensureCompletedPrerenderForUrl( | 1407 ensureCompletedSpeculationForUrl(connection, url, speculationMode); |
1391 CustomTabsConnection.getInstance((Application) | |
1392 getInstrumentation().getTargetContext().getApplicati onContext()), url); | |
1393 } catch (Exception e) { | 1408 } catch (Exception e) { |
1394 fail(); | 1409 fail(); |
1395 } | 1410 } |
1396 | 1411 |
1397 if (requestTime == BEFORE_INTENT) { | 1412 if (requestTime == BEFORE_INTENT) { |
1398 channelRequested = session.requestPostMessageChannel(null); | 1413 channelRequested = session.requestPostMessageChannel(null); |
1399 assertTrue(channelRequested); | 1414 assertTrue(channelRequested); |
1400 } | 1415 } |
1401 | 1416 |
1402 if (channelRequested) { | 1417 if (channelRequested) { |
1403 try { | 1418 try { |
1404 messageChannelHelper.waitForCallback(0); | 1419 messageChannelHelper.waitForCallback(0); |
1405 } catch (TimeoutException e) { | 1420 } catch (TimeoutException e) { |
1406 fail(); | 1421 fail(); |
1407 } | 1422 } |
1408 currentMessage = "Prerendering "; | 1423 currentMessage = "Prerendering "; |
1409 // Initial title update during prerender. | 1424 // Initial title update during prerender. |
1410 assertTrue(session.postMessage(currentMessage, null) | 1425 assertTrue(session.postMessage(currentMessage, null) |
1411 == CustomTabsService.RESULT_SUCCESS); | 1426 == CustomTabsService.RESULT_SUCCESS); |
1412 titleString = currentMessage; | 1427 titleString = currentMessage; |
1413 } | 1428 } |
1414 | 1429 |
1415 Intent intent = new CustomTabsIntent.Builder(session).build().intent; | |
1416 intent.setData(Uri.parse(url)); | |
1417 intent.setComponent(new ComponentName( | |
1418 getInstrumentation().getTargetContext(), ChromeLauncherActivity. class)); | |
1419 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
1420 try { | 1430 try { |
1421 startCustomTabActivityWithIntent(intent); | 1431 startCustomTabActivityWithIntent(intent); |
1422 } catch (InterruptedException e) { | 1432 } catch (InterruptedException e) { |
1423 fail(); | 1433 fail(); |
1424 } | 1434 } |
1425 | 1435 |
1426 CriteriaHelper.pollInstrumentationThread(new Criteria() { | 1436 CriteriaHelper.pollInstrumentationThread(new Criteria() { |
1427 @Override | 1437 @Override |
1428 public boolean isSatisfied() { | 1438 public boolean isSatisfied() { |
1429 final Tab currentTab = getActivity().getActivityTab(); | 1439 final Tab currentTab = getActivity().getActivityTab(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1477 */ | 1487 */ |
1478 @SmallTest | 1488 @SmallTest |
1479 @RetryOnFailure | 1489 @RetryOnFailure |
1480 public void testPrecreatedRenderer() throws InterruptedException { | 1490 public void testPrecreatedRenderer() throws InterruptedException { |
1481 CustomTabsConnection connection = warmUpAndWait(); | 1491 CustomTabsConnection connection = warmUpAndWait(); |
1482 Context context = getInstrumentation().getTargetContext(); | 1492 Context context = getInstrumentation().getTargetContext(); |
1483 Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(context , mTestPage); | 1493 Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(context , mTestPage); |
1484 CustomTabsSessionToken token = CustomTabsSessionToken.getSessionTokenFro mIntent(intent); | 1494 CustomTabsSessionToken token = CustomTabsSessionToken.getSessionTokenFro mIntent(intent); |
1485 assertTrue(connection.newSession(token)); | 1495 assertTrue(connection.newSession(token)); |
1486 Bundle extras = new Bundle(); | 1496 Bundle extras = new Bundle(); |
1497 // Forcing no prerendering implies falling back to simply creating a spa re WebContent | |
Benoit L
2017/03/23 18:28:29
tiny nit: WebContents.
ahemery1
2017/03/27 12:27:32
Done.
| |
1487 extras.putInt( | 1498 extras.putInt( |
1488 CustomTabsConnection.DEBUG_OVERRIDE_KEY, CustomTabsConnection.NO _PRERENDERING); | 1499 CustomTabsConnection.DEBUG_OVERRIDE_KEY, CustomTabsConnection.NO _PRERENDERING); |
1489 assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), extras, null)); | 1500 assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), extras, null)); |
1490 try { | 1501 try { |
1491 startCustomTabActivityWithIntent(intent); | 1502 startCustomTabActivityWithIntent(intent); |
1492 } catch (InterruptedException e) { | 1503 } catch (InterruptedException e) { |
1493 fail(); | 1504 fail(); |
1494 } | 1505 } |
1495 CriteriaHelper.pollInstrumentationThread(new Criteria() { | 1506 CriteriaHelper.pollInstrumentationThread(new Criteria() { |
1496 @Override | 1507 @Override |
1497 public boolean isSatisfied() { | 1508 public boolean isSatisfied() { |
1498 final Tab currentTab = getActivity().getActivityTab(); | 1509 final Tab currentTab = getActivity().getActivityTab(); |
1499 return mTestPage.equals(currentTab.getUrl()); | 1510 return mTestPage.equals(currentTab.getUrl()); |
1500 } | 1511 } |
1501 }); | 1512 }); |
1502 assertFalse(getActivity().getActivityTab().canGoBack()); | 1513 assertFalse(getActivity().getActivityTab().canGoBack()); |
1503 } | 1514 } |
1504 | 1515 |
1516 /** Tests that calling warmup() is optional without prerendering. */ | |
1517 @SmallTest | |
1518 @RetryOnFailure | |
1519 public void testMayLaunchUrlWithoutWarmupNoSpeculation() { | |
1520 mayLaunchUrlWithoutWarmup(CustomTabsConnection.SpeculationParams.NO_SPEC ULATION); | |
1521 } | |
1522 | |
1505 /** Tests that calling mayLaunchUrl() without warmup() succeeds. */ | 1523 /** Tests that calling mayLaunchUrl() without warmup() succeeds. */ |
1506 @SmallTest | 1524 @SmallTest |
1507 @RetryOnFailure | 1525 @RetryOnFailure |
1508 public void testMayLaunchUrlWithoutWarmup() { | 1526 public void testMayLaunchUrlWithoutWarmupPrerender() { |
1509 mayLaunchUrlWithoutWarmup(false); | 1527 mayLaunchUrlWithoutWarmup(CustomTabsConnection.SpeculationParams.PREREND ER); |
1510 } | |
1511 | |
1512 /** Tests that calling warmup() is optional without prerendering. */ | |
1513 @SmallTest | |
1514 @RetryOnFailure | |
1515 public void testMayLaunchUrlWithoutWarmupNoPrerendering() { | |
1516 mayLaunchUrlWithoutWarmup(true); | |
1517 } | 1528 } |
1518 | 1529 |
1519 /** | 1530 /** |
1520 * Tests that launching a regular Chrome tab after warmup() gives the right layout. | 1531 * Tests that launching a regular Chrome tab after warmup() gives the right layout. |
1521 * | 1532 * |
1522 * About the restrictions and switches: No FRE and no document mode to get a | 1533 * About the restrictions and switches: No FRE and no document mode to get a |
1523 * ChromeTabbedActivity, and no tablets to have the tab switcher button. | 1534 * ChromeTabbedActivity, and no tablets to have the tab switcher button. |
1524 * | 1535 * |
1525 * Non-regression test for crbug.com/547121. | 1536 * Non-regression test for crbug.com/547121. |
1526 * @SmallTest | 1537 * @SmallTest |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1607 * - loadUrl("http://example.com/page.html#other-fragment") | 1618 * - loadUrl("http://example.com/page.html#other-fragment") |
1608 * | 1619 * |
1609 * There are two parameters changing the bahavior: | 1620 * There are two parameters changing the bahavior: |
1610 * @param ignoreFragments Whether the prerender should be kept. | 1621 * @param ignoreFragments Whether the prerender should be kept. |
1611 * @param wait Whether to wait for the prerender to load. | 1622 * @param wait Whether to wait for the prerender to load. |
1612 * | 1623 * |
1613 * The prerender state is assessed through monitoring the properties of the test page. | 1624 * The prerender state is assessed through monitoring the properties of the test page. |
1614 */ | 1625 */ |
1615 private void prerenderAndChangeFragment(boolean ignoreFragments, boolean wai t) | 1626 private void prerenderAndChangeFragment(boolean ignoreFragments, boolean wai t) |
1616 throws Exception { | 1627 throws Exception { |
1628 speculateAndChangeFragment( | |
1629 ignoreFragments, wait, CustomTabsConnection.SpeculationParams.PR ERENDER); | |
1630 } | |
1631 | |
1632 private void speculateAndChangeFragment( | |
1633 boolean ignoreFragments, boolean wait, int speculationMode) throws E xception { | |
1617 String testUrl = mTestServer.getURL(FRAGMENT_TEST_PAGE); | 1634 String testUrl = mTestServer.getURL(FRAGMENT_TEST_PAGE); |
1618 String initialFragment = "#test"; | 1635 String initialFragment = "#test"; |
1619 String initialUrl = testUrl + initialFragment; | 1636 String initialUrl = testUrl + initialFragment; |
1620 String fragment = "#yeah"; | 1637 String fragment = "#yeah"; |
1621 String urlWithFragment = testUrl + fragment; | 1638 String urlWithFragment = testUrl + fragment; |
1622 | 1639 |
1623 Context context = getInstrumentation().getTargetContext().getApplication Context(); | 1640 Context context = getInstrumentation().getTargetContext().getApplication Context(); |
1624 CustomTabsConnection connection = warmUpAndWait(); | 1641 CustomTabsConnection connection = warmUpAndWait(); |
1625 Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(context , urlWithFragment); | 1642 Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(context , urlWithFragment); |
1626 CustomTabsSessionToken token = CustomTabsSessionToken.getSessionTokenFro mIntent(intent); | 1643 CustomTabsSessionToken token = CustomTabsSessionToken.getSessionTokenFro mIntent(intent); |
1627 connection.newSession(token); | 1644 connection.newSession(token); |
1628 connection.setIgnoreUrlFragmentsForSession(token, ignoreFragments); | 1645 connection.setIgnoreUrlFragmentsForSession(token, ignoreFragments); |
1646 connection.setSpeculationModeForSession(token, speculationMode); | |
1629 assertTrue(connection.mayLaunchUrl(token, Uri.parse(initialUrl), null, n ull)); | 1647 assertTrue(connection.mayLaunchUrl(token, Uri.parse(initialUrl), null, n ull)); |
1630 | 1648 |
1631 if (wait) ensureCompletedPrerenderForUrl(connection, initialUrl); | 1649 if (wait) ensureCompletedSpeculationForUrl(connection, initialUrl, specu lationMode); |
1632 | 1650 |
1633 try { | 1651 try { |
1634 startCustomTabActivityWithIntent(intent); | 1652 startCustomTabActivityWithIntent(intent); |
1635 } catch (InterruptedException e) { | 1653 } catch (InterruptedException e) { |
1636 fail(); | 1654 fail(); |
1637 } | 1655 } |
1638 final Tab tab = mActivity.getActivityTab(); | 1656 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 | 1657 |
1646 if (wait) { | 1658 if (wait) { |
1659 ElementContentCriteria initialVisibilityCriteria = new ElementConten tCriteria(tab, | |
1660 "visibility", | |
1661 ignoreFragments ? getExpectedVisibilityForSpeculationMode(sp eculationMode) | |
1662 : "visible"); | |
1663 ElementContentCriteria initialFragmentCriteria = new ElementContentC riteria( | |
1664 tab, "initial-fragment", ignoreFragments ? initialFragment : fragment); | |
1665 ElementContentCriteria fragmentCriteria = | |
1666 new ElementContentCriteria(tab, "fragment", fragment); | |
1647 // The tab hasn't been reloaded. | 1667 // The tab hasn't been reloaded. |
1648 CriteriaHelper.pollInstrumentationThread(initialVisibilityCriteria, 2000, 200); | 1668 CriteriaHelper.pollInstrumentationThread(initialVisibilityCriteria, 2000, 200); |
1649 // No reload (initial fragment is correct). | 1669 // No reload (initial fragment is correct). |
1650 CriteriaHelper.pollInstrumentationThread(initialFragmentCriteria, 20 00, 200); | 1670 CriteriaHelper.pollInstrumentationThread(initialFragmentCriteria, 20 00, 200); |
1651 if (ignoreFragments) { | 1671 if (ignoreFragments) { |
1652 CriteriaHelper.pollInstrumentationThread(fragmentCriteria, 2000, 200); | 1672 CriteriaHelper.pollInstrumentationThread(fragmentCriteria, 2000, 200); |
1653 } | 1673 } |
1654 } else { | 1674 } else { |
1655 CriteriaHelper.pollInstrumentationThread(new ElementContentCriteria( | 1675 CriteriaHelper.pollInstrumentationThread(new ElementContentCriteria( |
1656 tab, "initial-fragment", fragment), 2000, 200); | 1676 tab, "initial-fragment", fragment), 2000, 200); |
1657 } | 1677 } |
1658 assertFalse(tab.canGoForward()); | 1678 assertFalse(tab.canGoForward()); |
1659 assertFalse(tab.canGoBack()); | 1679 assertFalse(tab.canGoBack()); |
1660 } | 1680 } |
1661 | 1681 |
1662 /** | 1682 /** |
1663 * Test whether the url shown on prerender gets updated from about:blank whe n the prerender | 1683 * Test whether the url shown on prerender gets updated from about:blank whe n the prerender |
1664 * completes in the background. | 1684 * completes in the background. |
1665 * Non-regression test for crbug.com/554236. | 1685 * Non-regression test for crbug.com/554236. |
1666 */ | 1686 */ |
1667 @SmallTest | 1687 @SmallTest |
1668 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 1688 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
1669 @RetryOnFailure | 1689 @RetryOnFailure |
1670 public void testPrerenderingCorrectUrl() throws Exception { | 1690 public void testPrerenderingCorrectUrl() throws Exception { |
1691 testSpeculateCorrectUrl(CustomTabsConnection.SpeculationParams.PRERENDER ); | |
1692 } | |
1693 | |
1694 private void testSpeculateCorrectUrl(int speculationMode) throws Exception { | |
1671 Context context = getInstrumentation().getTargetContext().getApplication Context(); | 1695 Context context = getInstrumentation().getTargetContext().getApplication Context(); |
1672 final CustomTabsConnection connection = warmUpAndWait(); | 1696 final CustomTabsConnection connection = warmUpAndWait(); |
1673 CustomTabsSessionToken token = CustomTabsSessionToken.createDummySession TokenForTesting(); | 1697 CustomTabsSessionToken token = CustomTabsSessionToken.createDummySession TokenForTesting(); |
1674 connection.newSession(token); | 1698 connection.newSession(token); |
1699 connection.setSpeculationModeForSession(token, speculationMode); | |
1675 assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), null, nu ll)); | 1700 assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), null, nu ll)); |
1676 ensureCompletedPrerenderForUrl(connection, mTestPage); | 1701 ensureCompletedSpeculationForUrl(connection, mTestPage, speculationMode) ; |
1677 | 1702 |
1678 try { | 1703 try { |
1679 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCu stomTabIntent( | 1704 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCu stomTabIntent( |
1680 context, mTestPage)); | 1705 context, mTestPage)); |
1681 } catch (InterruptedException e) { | 1706 } catch (InterruptedException e) { |
1682 fail(); | 1707 fail(); |
1683 } | 1708 } |
1684 assertEquals(Uri.parse(mTestPage).getHost() + ":" + Uri.parse(mTestPage) .getPort(), | 1709 assertEquals(Uri.parse(mTestPage).getHost() + ":" + Uri.parse(mTestPage) .getPort(), |
1685 ((EditText) mActivity.findViewById(R.id.url_bar)).getText() | 1710 ((EditText) mActivity.findViewById(R.id.url_bar)).getText() |
1686 .toString()); | 1711 .toString()); |
1687 } | 1712 } |
1688 | 1713 |
1689 /** | 1714 /** |
1690 * Test whether invalid urls are avoided for prerendering. | 1715 * Test whether invalid urls are avoided for prerendering. |
1691 */ | 1716 */ |
1692 @SmallTest | 1717 @SmallTest |
1693 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 1718 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
1694 @RetryOnFailure | 1719 @RetryOnFailure |
1695 public void testPrerenderingInvalidUrl() throws Exception { | 1720 public void testPrerenderingInvalidUrl() throws Exception { |
1721 testSpeculateInvalidUrl(CustomTabsConnection.SpeculationParams.PRERENDER ); | |
1722 } | |
1723 | |
1724 private void testSpeculateInvalidUrl(int speculationMode) throws Exception { | |
1696 final CustomTabsConnection connection = warmUpAndWait(); | 1725 final CustomTabsConnection connection = warmUpAndWait(); |
1697 CustomTabsSessionToken token = CustomTabsSessionToken.createDummySession TokenForTesting(); | 1726 CustomTabsSessionToken token = CustomTabsSessionToken.createDummySession TokenForTesting(); |
1698 connection.newSession(token); | 1727 connection.newSession(token); |
1728 connection.setSpeculationModeForSession(token, speculationMode); | |
1699 assertFalse(connection.mayLaunchUrl(token, Uri.parse("chrome://version") , null, null)); | 1729 assertFalse(connection.mayLaunchUrl(token, Uri.parse("chrome://version") , null, null)); |
1700 } | 1730 } |
1701 | 1731 |
1702 /** | 1732 /** |
1703 * Tests that the activity knows there is already a child process when warmu p() has been called. | 1733 * Tests that the activity knows there is already a child process when warmu p() has been called. |
1704 */ | 1734 */ |
1705 @SmallTest | 1735 @SmallTest |
1706 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 1736 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
1707 @RetryOnFailure | 1737 @RetryOnFailure |
1708 public void testAllocateChildConnectionWithWarmup() throws Exception { | 1738 public void testAllocateChildConnectionWithWarmup() throws Exception { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1753 }); | 1783 }); |
1754 } | 1784 } |
1755 | 1785 |
1756 /** | 1786 /** |
1757 * Tests that the activity knows there is already a child process when prere ndering. | 1787 * Tests that the activity knows there is already a child process when prere ndering. |
1758 */ | 1788 */ |
1759 @SmallTest | 1789 @SmallTest |
1760 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 1790 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
1761 @RetryOnFailure | 1791 @RetryOnFailure |
1762 public void testAllocateChildConnectionWithPrerender() throws Exception { | 1792 public void testAllocateChildConnectionWithPrerender() throws Exception { |
1793 testAllocateChildConnectionWithSpeculation( | |
1794 CustomTabsConnection.SpeculationParams.PRERENDER); | |
1795 } | |
1796 | |
1797 private void testAllocateChildConnectionWithSpeculation(int speculationMode) throws Exception { | |
1763 Context context = getInstrumentation().getTargetContext().getApplication Context(); | 1798 Context context = getInstrumentation().getTargetContext().getApplication Context(); |
1764 final CustomTabsConnection connection = warmUpAndWait(); | 1799 final CustomTabsConnection connection = warmUpAndWait(); |
1765 CustomTabsSessionToken token = CustomTabsSessionToken.createDummySession TokenForTesting(); | 1800 CustomTabsSessionToken token = CustomTabsSessionToken.createDummySession TokenForTesting(); |
1766 connection.newSession(token); | 1801 connection.newSession(token); |
1802 connection.setSpeculationModeForSession(token, speculationMode); | |
1767 assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), null, nu ll)); | 1803 assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), null, nu ll)); |
1768 try { | 1804 try { |
1769 startCustomTabActivityWithIntent( | 1805 startCustomTabActivityWithIntent( |
1770 CustomTabsTestUtils.createMinimalCustomTabIntent(context, mT estPage)); | 1806 CustomTabsTestUtils.createMinimalCustomTabIntent(context, mT estPage)); |
1771 } catch (InterruptedException e) { | 1807 } catch (InterruptedException e) { |
1772 fail(); | 1808 fail(); |
1773 } | 1809 } |
1774 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 1810 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
1775 @Override | 1811 @Override |
1776 public void run() { | 1812 public void run() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1810 } | 1846 } |
1811 | 1847 |
1812 /** | 1848 /** |
1813 * Tests that prerendering accepts a referrer, and that this is not lost whe n launching the | 1849 * Tests that prerendering accepts a referrer, and that this is not lost whe n launching the |
1814 * Custom Tab. | 1850 * Custom Tab. |
1815 */ | 1851 */ |
1816 @SmallTest | 1852 @SmallTest |
1817 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 1853 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
1818 @RetryOnFailure | 1854 @RetryOnFailure |
1819 public void testPrerenderingWithReferrer() throws Exception { | 1855 public void testPrerenderingWithReferrer() throws Exception { |
1856 testSpeculatingWithReferrer(CustomTabsConnection.SpeculationParams.PRERE NDER); | |
1857 } | |
1858 | |
1859 private void testSpeculatingWithReferrer(int speculationMode) throws Excepti on { | |
1820 String referrer = "android-app://com.foo.me/"; | 1860 String referrer = "android-app://com.foo.me/"; |
1821 maybePrerenderAndLaunchWithReferrers( | 1861 maybeSpeculateAndLaunchWithReferrers( |
1822 mTestServer.getURL(FRAGMENT_TEST_PAGE), true, referrer, referrer ); | 1862 mTestServer.getURL(FRAGMENT_TEST_PAGE), speculationMode, referre r, referrer); |
1823 | 1863 |
1824 Tab tab = mActivity.getActivityTab(); | 1864 Tab tab = mActivity.getActivityTab(); |
1825 // The tab hasn't been reloaded. | 1865 // The tab hasn't been reloaded. |
1826 CriteriaHelper.pollInstrumentationThread( | 1866 CriteriaHelper.pollInstrumentationThread( |
1827 new ElementContentCriteria(tab, "visibility", "prerender"), 2000 , 200); | 1867 new ElementContentCriteria(tab, "visibility", |
1868 getExpectedVisibilityForSpeculationMode(speculationMode) ), | |
1869 2000, 200); | |
1828 // The Referrer is correctly set. | 1870 // The Referrer is correctly set. |
1829 CriteriaHelper.pollInstrumentationThread( | 1871 CriteriaHelper.pollInstrumentationThread( |
1830 new TabsOpenedFromExternalAppTest.ReferrerCriteria(tab, referrer ), 2000, 200); | 1872 new TabsOpenedFromExternalAppTest.ReferrerCriteria(tab, referrer ), 2000, 200); |
1831 } | 1873 } |
1832 | 1874 |
1833 /** | 1875 /** |
1834 * Tests that prerendering accepts a referrer, and that the prerender is dro pped when the tab | 1876 * Tests that prerendering accepts a referrer, and that the prerender is dro pped when the tab |
1835 * is launched with a mismatched referrer. | 1877 * is launched with a mismatched referrer. |
1836 */ | 1878 */ |
1837 @SmallTest | 1879 @SmallTest |
1838 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 1880 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
1839 @RetryOnFailure | 1881 @RetryOnFailure |
1840 public void testPrerenderingWithMismatchedReferrers() throws Exception { | 1882 public void testPrerenderingWithMismatchedReferrers() throws Exception { |
1883 testSpeculatingWithMismatchedReferrers(CustomTabsConnection.SpeculationP arams.PRERENDER); | |
1884 } | |
1885 | |
1886 private void testSpeculatingWithMismatchedReferrers(int speculationMode) thr ows Exception { | |
1841 String prerenderReferrer = "android-app://com.foo.me/"; | 1887 String prerenderReferrer = "android-app://com.foo.me/"; |
1842 String launchReferrer = "android-app://com.foo.me.i.changed.my.mind/"; | 1888 String launchReferrer = "android-app://com.foo.me.i.changed.my.mind/"; |
1843 maybePrerenderAndLaunchWithReferrers( | 1889 maybeSpeculateAndLaunchWithReferrers(mTestServer.getURL(FRAGMENT_TEST_PA GE), |
1844 mTestServer.getURL(FRAGMENT_TEST_PAGE), true, prerenderReferrer, launchReferrer); | 1890 speculationMode, prerenderReferrer, launchReferrer); |
1845 | 1891 |
1846 Tab tab = mActivity.getActivityTab(); | 1892 Tab tab = mActivity.getActivityTab(); |
1847 // Prerender has been dropped. | 1893 // Prerender has been dropped. |
1848 CriteriaHelper.pollInstrumentationThread( | 1894 CriteriaHelper.pollInstrumentationThread( |
1849 new ElementContentCriteria(tab, "visibility", "visible"), 2000, 200); | 1895 new ElementContentCriteria(tab, "visibility", "visible"), 2000, 200); |
1850 // The Referrer is correctly set. | 1896 // The Referrer is correctly set. |
1851 CriteriaHelper.pollInstrumentationThread( | 1897 CriteriaHelper.pollInstrumentationThread( |
1852 new TabsOpenedFromExternalAppTest.ReferrerCriteria(tab, launchRe ferrer), 2000, 200); | 1898 new TabsOpenedFromExternalAppTest.ReferrerCriteria(tab, launchRe ferrer), 2000, 200); |
1853 } | 1899 } |
1854 | 1900 |
1855 /** Tests that a client can set a referrer, without prerendering. */ | 1901 /** Tests that a client can set a referrer, without speculating. */ |
1856 @SmallTest | 1902 @SmallTest |
1857 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 1903 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
1858 @RetryOnFailure | 1904 @RetryOnFailure |
1859 public void testClientCanSetReferrer() throws Exception { | 1905 public void testClientCanSetReferrer() throws Exception { |
1860 String referrerUrl = "android-app://com.foo.me/"; | 1906 String referrerUrl = "android-app://com.foo.me/"; |
1861 maybePrerenderAndLaunchWithReferrers(mTestPage, false, null, referrerUrl ); | 1907 maybeSpeculateAndLaunchWithReferrers(mTestPage, |
1908 CustomTabsConnection.SpeculationParams.NO_SPECULATION, null, ref errerUrl); | |
1862 | 1909 |
1863 Tab tab = mActivity.getActivityTab(); | 1910 Tab tab = mActivity.getActivityTab(); |
1864 // The Referrer is correctly set. | 1911 // The Referrer is correctly set. |
1865 CriteriaHelper.pollInstrumentationThread( | 1912 CriteriaHelper.pollInstrumentationThread( |
1866 new TabsOpenedFromExternalAppTest.ReferrerCriteria(tab, referrer Url), 2000, 200); | 1913 new TabsOpenedFromExternalAppTest.ReferrerCriteria(tab, referrer Url), 2000, 200); |
1867 } | 1914 } |
1868 | 1915 |
1869 /** | 1916 /** |
1870 * Tests that a Weblite URL from an external app uses the lite_url param whe n Data Reduction | 1917 * Tests that a Weblite URL from an external app uses the lite_url param whe n Data Reduction |
1871 * Proxy previews are being used. | 1918 * Proxy previews are being used. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1954 @RetryOnFailure | 2001 @RetryOnFailure |
1955 public void testLaunchNonWebLiteURL() throws Exception { | 2002 public void testLaunchNonWebLiteURL() throws Exception { |
1956 final String testUrl = mTestPage2 + "/?lite_url=" + mTestPage; | 2003 final String testUrl = mTestPage2 + "/?lite_url=" + mTestPage; |
1957 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCustom TabIntent( | 2004 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCustom TabIntent( |
1958 getInstrumentation().getTargetContext(), testUrl)); | 2005 getInstrumentation().getTargetContext(), testUrl)); |
1959 Tab tab = getActivity().getActivityTab(); | 2006 Tab tab = getActivity().getActivityTab(); |
1960 assertEquals(testUrl, tab.getUrl()); | 2007 assertEquals(testUrl, tab.getUrl()); |
1961 } | 2008 } |
1962 | 2009 |
1963 /** Maybe prerenders a URL with a referrer, then launch it with another one. */ | 2010 /** Maybe prerenders a URL with a referrer, then launch it with another one. */ |
1964 private void maybePrerenderAndLaunchWithReferrers(String url, boolean preren der, | 2011 private void maybeSpeculateAndLaunchWithReferrers(String url, int speculatio nMode, |
1965 String prerenderReferrer, String launchReferrer) throws Exception { | 2012 String speculationReferrer, String launchReferrer) throws Exception { |
1966 Context context = getInstrumentation().getTargetContext().getApplication Context(); | 2013 Context context = getInstrumentation().getTargetContext().getApplication Context(); |
1967 CustomTabsConnection connection = null; | 2014 CustomTabsConnection connection = null; |
1968 CustomTabsSessionToken token = null; | 2015 CustomTabsSessionToken token = null; |
1969 Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(context , url); | 2016 Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(context , url); |
1970 if (prerender) { | 2017 if (speculationMode != CustomTabsConnection.SpeculationParams.NO_SPECULA TION) { |
1971 connection = warmUpAndWait(); | 2018 connection = warmUpAndWait(); |
1972 token = CustomTabsSessionToken.getSessionTokenFromIntent(intent); | 2019 token = CustomTabsSessionToken.getSessionTokenFromIntent(intent); |
1973 connection.newSession(token); | 2020 connection.newSession(token); |
2021 connection.setSpeculationModeForSession(token, speculationMode); | |
1974 Bundle extras = null; | 2022 Bundle extras = null; |
1975 if (prerenderReferrer != null) { | 2023 if (speculationReferrer != null) { |
1976 extras = new Bundle(); | 2024 extras = new Bundle(); |
1977 extras.putParcelable(Intent.EXTRA_REFERRER, Uri.parse(prerenderR eferrer)); | 2025 extras.putParcelable(Intent.EXTRA_REFERRER, Uri.parse(speculatio nReferrer)); |
1978 } | 2026 } |
1979 assertTrue(connection.mayLaunchUrl(token, Uri.parse(url), extras, nu ll)); | 2027 assertTrue(connection.mayLaunchUrl(token, Uri.parse(url), extras, nu ll)); |
1980 ensureCompletedPrerenderForUrl(connection, url); | 2028 ensureCompletedSpeculationForUrl(connection, url, speculationMode); |
1981 } | 2029 } |
1982 | 2030 |
1983 if (launchReferrer != null) { | 2031 if (launchReferrer != null) { |
1984 intent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(launchReferrer)); | 2032 intent.putExtra(Intent.EXTRA_REFERRER, Uri.parse(launchReferrer)); |
1985 } | 2033 } |
1986 try { | 2034 try { |
1987 startCustomTabActivityWithIntent(intent); | 2035 startCustomTabActivityWithIntent(intent); |
1988 } catch (InterruptedException e) { | 2036 } catch (InterruptedException e) { |
1989 fail(); | 2037 fail(); |
1990 } | 2038 } |
1991 } | 2039 } |
1992 | 2040 |
1993 private void mayLaunchUrlWithoutWarmup(boolean noPrerendering) { | 2041 private void mayLaunchUrlWithoutWarmup(int speculationMode) { |
1994 Context context = getInstrumentation().getTargetContext().getApplication Context(); | 2042 Context context = getInstrumentation().getTargetContext().getApplication Context(); |
1995 CustomTabsConnection connection = | 2043 CustomTabsConnection connection = |
1996 CustomTabsTestUtils.setUpConnection((Application) context); | 2044 CustomTabsTestUtils.setUpConnection((Application) context); |
1997 CustomTabsSessionToken token = CustomTabsSessionToken.createDummySession TokenForTesting(); | 2045 CustomTabsSessionToken token = CustomTabsSessionToken.createDummySession TokenForTesting(); |
1998 connection.newSession(token); | 2046 connection.newSession(token); |
1999 Bundle extras = null; | 2047 Bundle extras = null; |
2000 if (noPrerendering) { | 2048 if (speculationMode == CustomTabsConnection.SpeculationParams.NO_SPECULA TION) { |
2001 extras = new Bundle(); | 2049 extras = new Bundle(); |
2002 extras.putInt( | 2050 extras.putInt( |
2003 CustomTabsConnection.DEBUG_OVERRIDE_KEY, CustomTabsConnectio n.NO_PRERENDERING); | 2051 CustomTabsConnection.DEBUG_OVERRIDE_KEY, CustomTabsConnectio n.NO_PRERENDERING); |
2004 } | 2052 } |
2053 connection.setSpeculationModeForSession(token, speculationMode); | |
2005 assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), extras, null)); | 2054 assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), extras, null)); |
2006 try { | 2055 try { |
2007 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCu stomTabIntent( | 2056 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCu stomTabIntent( |
2008 context, mTestPage)); | 2057 context, mTestPage)); |
2009 } catch (InterruptedException e) { | 2058 } catch (InterruptedException e) { |
2010 fail(); | 2059 fail(); |
2011 } | 2060 } |
2012 Tab tab = getActivity().getActivityTab(); | 2061 Tab tab = getActivity().getActivityTab(); |
2013 assertEquals(mTestPage, tab.getUrl()); | 2062 assertEquals(mTestPage, tab.getUrl()); |
2014 } | 2063 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2104 startCustomTabActivityWithIntent(intentWithSession); | 2153 startCustomTabActivityWithIntent(intentWithSession); |
2105 return token; | 2154 return token; |
2106 } | 2155 } |
2107 | 2156 |
2108 private CustomTabsSessionToken warmUpAndLaunchUrlWithSession() throws Interr uptedException { | 2157 private CustomTabsSessionToken warmUpAndLaunchUrlWithSession() throws Interr uptedException { |
2109 return warmUpAndLaunchUrlWithSession( | 2158 return warmUpAndLaunchUrlWithSession( |
2110 CustomTabsTestUtils.createMinimalCustomTabIntent( | 2159 CustomTabsTestUtils.createMinimalCustomTabIntent( |
2111 getInstrumentation().getTargetContext(), mTestPage)); | 2160 getInstrumentation().getTargetContext(), mTestPage)); |
2112 } | 2161 } |
2113 | 2162 |
2114 private static void ensureCompletedPrerenderForUrl( | 2163 private static void ensureCompletedSpeculationForUrl(final CustomTabsConnect ion connection, |
2115 final CustomTabsConnection connection, final String url) throws Exce ption { | 2164 final String url, int speculationMode) throws Exception { |
2116 CriteriaHelper.pollUiThread(new Criteria("No Prerender") { | 2165 if (speculationMode == CustomTabsConnection.SpeculationParams.PRERENDER) { |
2117 @Override | 2166 CriteriaHelper.pollUiThread(new Criteria("No Prerender") { |
2118 public boolean isSatisfied() { | 2167 @Override |
2119 return connection.mSpeculation != null | 2168 public boolean isSatisfied() { |
2120 && connection.mSpeculation.webContents != null | 2169 return connection.mSpeculation != null |
2121 && ExternalPrerenderHandler.hasPrerenderedAndFinishedLoa dingUrl( | 2170 && connection.mSpeculation.webContents != null |
2122 Profile.getLastUsedProfile(), url, | 2171 && ExternalPrerenderHandler.hasPrerenderedAndFinishe dLoadingUrl( |
2123 connection.mSpeculation.webContents); | 2172 Profile.getLastUsedProfile(), url, |
2124 } | 2173 connection.mSpeculation.webContents); |
2125 }, LONG_TIMEOUT_MS, CriteriaHelper.DEFAULT_POLLING_INTERVAL); | 2174 } |
2175 }, LONG_TIMEOUT_MS, CriteriaHelper.DEFAULT_POLLING_INTERVAL); | |
2176 } | |
2126 } | 2177 } |
2127 | 2178 |
2128 private CustomTabsSession bindWithCallback(final CustomTabsCallback callback ) { | 2179 private CustomTabsSession bindWithCallback(final CustomTabsCallback callback ) { |
2129 final AtomicReference<CustomTabsSession> sessionReference = new AtomicRe ference<>(null); | 2180 final AtomicReference<CustomTabsSession> sessionReference = new AtomicRe ference<>(null); |
2130 CustomTabsClient.bindCustomTabsService(getInstrumentation().getContext() , | 2181 CustomTabsClient.bindCustomTabsService(getInstrumentation().getContext() , |
2131 getInstrumentation().getTargetContext().getPackageName(), | 2182 getInstrumentation().getTargetContext().getPackageName(), |
2132 new CustomTabsServiceConnection() { | 2183 new CustomTabsServiceConnection() { |
2133 @Override | 2184 @Override |
2134 public void onServiceDisconnected(ComponentName name) {} | 2185 public void onServiceDisconnected(ComponentName name) {} |
2135 | 2186 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2203 mTab.getWebContents(), mJsFunction); | 2254 mTab.getWebContents(), mJsFunction); |
2204 if (jsonText.equalsIgnoreCase("null")) jsonText = ""; | 2255 if (jsonText.equalsIgnoreCase("null")) jsonText = ""; |
2205 value = jsonText; | 2256 value = jsonText; |
2206 } catch (InterruptedException | TimeoutException e) { | 2257 } catch (InterruptedException | TimeoutException e) { |
2207 e.printStackTrace(); | 2258 e.printStackTrace(); |
2208 return false; | 2259 return false; |
2209 } | 2260 } |
2210 return TextUtils.equals(mExpected, value); | 2261 return TextUtils.equals(mExpected, value); |
2211 } | 2262 } |
2212 } | 2263 } |
2264 | |
2265 private static String getExpectedVisibilityForSpeculationMode(int speculatio nMode) { | |
2266 switch (speculationMode) { | |
2267 case CustomTabsConnection.SpeculationParams.PRERENDER: | |
2268 return "prerender"; | |
2269 default: | |
2270 return "visible"; | |
2271 } | |
2272 } | |
2213 } | 2273 } |
OLD | NEW |