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