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 android.app.Activity; | 7 import android.app.Activity; |
8 import android.os.Bundle; | 8 import android.os.Bundle; |
9 import android.support.test.filters.SmallTest; | 9 import android.support.test.filters.SmallTest; |
10 | 10 |
11 import org.chromium.base.test.util.RetryOnFailure; | 11 import org.chromium.base.test.util.RetryOnFailure; |
12 import org.chromium.chrome.browser.customtabs.CustomTabDelegateFactory.CustomTab
NavigationDelegate; | 12 import org.chromium.chrome.browser.customtabs.CustomTabDelegateFactory.CustomTab
NavigationDelegate; |
13 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler; | 13 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler; |
14 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid
eUrlLoadingResult; | 14 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid
eUrlLoadingResult; |
15 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams; | 15 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams; |
16 import org.chromium.chrome.browser.tab.Tab; | 16 import org.chromium.chrome.browser.tab.Tab; |
17 import org.chromium.chrome.browser.tab.TabDelegateFactory; | 17 import org.chromium.chrome.browser.tab.TabDelegateFactory; |
| 18 import org.chromium.content.browser.test.util.Criteria; |
| 19 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 20 import org.chromium.content.browser.test.util.DOMUtils; |
18 import org.chromium.net.test.EmbeddedTestServer; | 21 import org.chromium.net.test.EmbeddedTestServer; |
19 | 22 |
20 /** | 23 /** |
21 * Instrumentation test for external navigation handling of a Custom Tab. | 24 * Instrumentation tests for external navigation handling of a Custom Tab. |
22 */ | 25 */ |
23 @RetryOnFailure | 26 @RetryOnFailure |
24 public class CustomTabExternalNavigationTest extends CustomTabActivityTestBase { | 27 public class CustomTabExternalNavigationTest extends CustomTabActivityTestBase { |
25 | |
26 /** | 28 /** |
27 * A dummy activity that claims to handle "customtab://customtabtest". | 29 * A dummy activity that claims to handle "customtab://customtabtest". |
28 */ | 30 */ |
29 public static class DummyActivityForSpecialScheme extends Activity { | 31 public static class DummyActivityForSpecialScheme extends Activity { |
30 @Override | 32 @Override |
31 protected void onCreate(Bundle savedInstanceState) { | 33 protected void onCreate(Bundle savedInstanceState) { |
32 super.onCreate(savedInstanceState); | 34 super.onCreate(savedInstanceState); |
33 finish(); | 35 finish(); |
34 } | 36 } |
35 } | 37 } |
(...skipping 19 matching lines...) Expand all Loading... |
55 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation
().getContext()); | 57 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation
().getContext()); |
56 super.setUp(); | 58 super.setUp(); |
57 } | 59 } |
58 | 60 |
59 @Override | 61 @Override |
60 public void tearDown() throws Exception { | 62 public void tearDown() throws Exception { |
61 mTestServer.stopAndDestroyServer(); | 63 mTestServer.stopAndDestroyServer(); |
62 super.tearDown(); | 64 super.tearDown(); |
63 } | 65 } |
64 | 66 |
65 @Override | |
66 public void startMainActivity() throws InterruptedException { | |
67 super.startMainActivity(); | |
68 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCustom
TabIntent( | |
69 getInstrumentation().getTargetContext(), mTestServer.getURL(TEST
_PATH))); | |
70 Tab tab = getActivity().getActivityTab(); | |
71 TabDelegateFactory delegateFactory = tab.getDelegateFactory(); | |
72 assertTrue(delegateFactory instanceof CustomTabDelegateFactory); | |
73 CustomTabDelegateFactory customTabDelegateFactory = | |
74 ((CustomTabDelegateFactory) delegateFactory); | |
75 mUrlHandler = customTabDelegateFactory.getExternalNavigationHandler(); | |
76 assertTrue(customTabDelegateFactory.getExternalNavigationDelegate() | |
77 instanceof CustomTabNavigationDelegate); | |
78 mNavigationDelegate = (CustomTabNavigationDelegate) customTabDelegateFac
tory | |
79 .getExternalNavigationDelegate(); | |
80 } | |
81 | |
82 /** | 67 /** |
83 * For urls with special schemes and hosts, and there is exactly one activit
y having a matching | 68 * For urls with special schemes and hosts, and there is exactly one activit
y having a matching |
84 * intent filter, the framework will make that activity the default handler
of the special url. | 69 * intent filter, the framework will make that activity the default handler
of the special url. |
85 * This test tests whether chrome is able to start the default external hand
ler. | 70 * This test tests whether chrome is able to start the default external hand
ler. |
86 */ | 71 */ |
87 @SmallTest | 72 @SmallTest |
88 public void testExternalActivityStartedForDefaultUrl() { | 73 public void testExternalActivityStartedForDefaultUrl() throws Exception { |
| 74 startCustomTabActivity(mTestServer.getURL(TEST_PATH)); |
89 final String testUrl = "customtab://customtabtest/intent"; | 75 final String testUrl = "customtab://customtabtest/intent"; |
90 ExternalNavigationParams params = new ExternalNavigationParams.Builder(t
estUrl, false) | 76 ExternalNavigationParams params = new ExternalNavigationParams.Builder(t
estUrl, false) |
91 .build(); | 77 .build(); |
92 OverrideUrlLoadingResult result = mUrlHandler.shouldOverrideUrlLoading(p
arams); | 78 OverrideUrlLoadingResult result = mUrlHandler.shouldOverrideUrlLoading(p
arams); |
93 assertEquals(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT, res
ult); | 79 assertEquals(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT, res
ult); |
94 assertTrue("A dummy activity should have been started to handle the spec
ial url.", | 80 assertTrue("A dummy activity should have been started to handle the spec
ial url.", |
95 mNavigationDelegate.hasExternalActivityStarted()); | 81 mNavigationDelegate.hasExternalActivityStarted()); |
96 } | 82 } |
97 | 83 |
98 /** | 84 /** |
99 * When loading a normal http url that chrome is able to handle, an intent p
icker should never | 85 * When loading a normal http url that chrome is able to handle, an intent p
icker should never |
100 * be shown, even if other activities such as {@link DummyActivityForHttp} c
laim to handle it. | 86 * be shown, even if other activities such as {@link DummyActivityForHttp} c
laim to handle it. |
101 */ | 87 */ |
102 @SmallTest | 88 @SmallTest |
103 public void testIntentPickerNotShownForNormalUrl() { | 89 public void testIntentPickerNotShownForNormalUrl() throws Exception { |
| 90 startCustomTabActivity(mTestServer.getURL(TEST_PATH)); |
104 final String testUrl = "http://customtabtest.com"; | 91 final String testUrl = "http://customtabtest.com"; |
105 ExternalNavigationParams params = new ExternalNavigationParams.Builder(t
estUrl, false) | 92 ExternalNavigationParams params = new ExternalNavigationParams.Builder(t
estUrl, false) |
106 .build(); | 93 .build(); |
107 OverrideUrlLoadingResult result = mUrlHandler.shouldOverrideUrlLoading(p
arams); | 94 OverrideUrlLoadingResult result = mUrlHandler.shouldOverrideUrlLoading(p
arams); |
108 assertEquals(OverrideUrlLoadingResult.NO_OVERRIDE, result); | 95 assertEquals(OverrideUrlLoadingResult.NO_OVERRIDE, result); |
109 assertFalse("External activities should not be started to handle the url
", | 96 assertFalse("External activities should not be started to handle the url
", |
110 mNavigationDelegate.hasExternalActivityStarted()); | 97 mNavigationDelegate.hasExternalActivityStarted()); |
111 } | 98 } |
| 99 |
| 100 /** |
| 101 * Launches a Custom Tab, clicks on an external app scheme link, and check t
hat an external |
| 102 * activity has been launched. |
| 103 */ |
| 104 @SmallTest |
| 105 public void testExternalApplicationLink() throws Exception { |
| 106 warmUpAndWait(); |
| 107 startCustomTabActivity(mTestServer.getURL(TEST_PATH)); |
| 108 |
| 109 Tab tab = getActivity().getActivityTab(); |
| 110 assertTrue(DOMUtils.clickNode(tab.getContentViewCore(), "customtab-exter
nal-link")); |
| 111 |
| 112 CriteriaHelper.pollUiThread(new Criteria("External Activity not launched
.") { |
| 113 @Override |
| 114 public boolean isSatisfied() { |
| 115 return mNavigationDelegate.hasExternalActivityStarted(); |
| 116 } |
| 117 }); |
| 118 } |
| 119 |
| 120 private void startCustomTabActivity(String url) throws InterruptedException
{ |
| 121 super.startMainActivity(); |
| 122 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCustom
TabIntent( |
| 123 getInstrumentation().getTargetContext(), url)); |
| 124 Tab tab = getActivity().getActivityTab(); |
| 125 TabDelegateFactory delegateFactory = tab.getDelegateFactory(); |
| 126 assertTrue(delegateFactory instanceof CustomTabDelegateFactory); |
| 127 CustomTabDelegateFactory customTabDelegateFactory = |
| 128 ((CustomTabDelegateFactory) delegateFactory); |
| 129 mUrlHandler = customTabDelegateFactory.getExternalNavigationHandler(); |
| 130 assertTrue(customTabDelegateFactory.getExternalNavigationDelegate() |
| 131 instanceof CustomTabNavigationDelegate); |
| 132 mNavigationDelegate = (CustomTabNavigationDelegate) |
| 133 customTabDelegateFactory.getExternalNaviga
tionDelegate(); |
| 134 } |
112 } | 135 } |
OLD | NEW |