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; | |
21 import org.chromium.net.test.EmbeddedTestServer; | 18 import org.chromium.net.test.EmbeddedTestServer; |
22 | 19 |
23 /** | 20 /** |
24 * Instrumentation tests for external navigation handling of a Custom Tab. | 21 * Instrumentation test for external navigation handling of a Custom Tab. |
25 */ | 22 */ |
26 @RetryOnFailure | 23 @RetryOnFailure |
27 public class CustomTabExternalNavigationTest extends CustomTabActivityTestBase { | 24 public class CustomTabExternalNavigationTest extends CustomTabActivityTestBase { |
| 25 |
28 /** | 26 /** |
29 * A dummy activity that claims to handle "customtab://customtabtest". | 27 * A dummy activity that claims to handle "customtab://customtabtest". |
30 */ | 28 */ |
31 public static class DummyActivityForSpecialScheme extends Activity { | 29 public static class DummyActivityForSpecialScheme extends Activity { |
32 @Override | 30 @Override |
33 protected void onCreate(Bundle savedInstanceState) { | 31 protected void onCreate(Bundle savedInstanceState) { |
34 super.onCreate(savedInstanceState); | 32 super.onCreate(savedInstanceState); |
35 finish(); | 33 finish(); |
36 } | 34 } |
37 } | 35 } |
(...skipping 19 matching lines...) Expand all Loading... |
57 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation
().getContext()); | 55 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation
().getContext()); |
58 super.setUp(); | 56 super.setUp(); |
59 } | 57 } |
60 | 58 |
61 @Override | 59 @Override |
62 public void tearDown() throws Exception { | 60 public void tearDown() throws Exception { |
63 mTestServer.stopAndDestroyServer(); | 61 mTestServer.stopAndDestroyServer(); |
64 super.tearDown(); | 62 super.tearDown(); |
65 } | 63 } |
66 | 64 |
| 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 |
67 /** | 82 /** |
68 * For urls with special schemes and hosts, and there is exactly one activit
y having a matching | 83 * For urls with special schemes and hosts, and there is exactly one activit
y having a matching |
69 * intent filter, the framework will make that activity the default handler
of the special url. | 84 * intent filter, the framework will make that activity the default handler
of the special url. |
70 * This test tests whether chrome is able to start the default external hand
ler. | 85 * This test tests whether chrome is able to start the default external hand
ler. |
71 */ | 86 */ |
72 @SmallTest | 87 @SmallTest |
73 public void testExternalActivityStartedForDefaultUrl() throws Exception { | 88 public void testExternalActivityStartedForDefaultUrl() { |
74 startCustomTabActivity(mTestServer.getURL(TEST_PATH)); | |
75 final String testUrl = "customtab://customtabtest/intent"; | 89 final String testUrl = "customtab://customtabtest/intent"; |
76 ExternalNavigationParams params = new ExternalNavigationParams.Builder(t
estUrl, false) | 90 ExternalNavigationParams params = new ExternalNavigationParams.Builder(t
estUrl, false) |
77 .build(); | 91 .build(); |
78 OverrideUrlLoadingResult result = mUrlHandler.shouldOverrideUrlLoading(p
arams); | 92 OverrideUrlLoadingResult result = mUrlHandler.shouldOverrideUrlLoading(p
arams); |
79 assertEquals(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT, res
ult); | 93 assertEquals(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT, res
ult); |
80 assertTrue("A dummy activity should have been started to handle the spec
ial url.", | 94 assertTrue("A dummy activity should have been started to handle the spec
ial url.", |
81 mNavigationDelegate.hasExternalActivityStarted()); | 95 mNavigationDelegate.hasExternalActivityStarted()); |
82 } | 96 } |
83 | 97 |
84 /** | 98 /** |
85 * When loading a normal http url that chrome is able to handle, an intent p
icker should never | 99 * When loading a normal http url that chrome is able to handle, an intent p
icker should never |
86 * be shown, even if other activities such as {@link DummyActivityForHttp} c
laim to handle it. | 100 * be shown, even if other activities such as {@link DummyActivityForHttp} c
laim to handle it. |
87 */ | 101 */ |
88 @SmallTest | 102 @SmallTest |
89 public void testIntentPickerNotShownForNormalUrl() throws Exception { | 103 public void testIntentPickerNotShownForNormalUrl() { |
90 startCustomTabActivity(mTestServer.getURL(TEST_PATH)); | |
91 final String testUrl = "http://customtabtest.com"; | 104 final String testUrl = "http://customtabtest.com"; |
92 ExternalNavigationParams params = new ExternalNavigationParams.Builder(t
estUrl, false) | 105 ExternalNavigationParams params = new ExternalNavigationParams.Builder(t
estUrl, false) |
93 .build(); | 106 .build(); |
94 OverrideUrlLoadingResult result = mUrlHandler.shouldOverrideUrlLoading(p
arams); | 107 OverrideUrlLoadingResult result = mUrlHandler.shouldOverrideUrlLoading(p
arams); |
95 assertEquals(OverrideUrlLoadingResult.NO_OVERRIDE, result); | 108 assertEquals(OverrideUrlLoadingResult.NO_OVERRIDE, result); |
96 assertFalse("External activities should not be started to handle the url
", | 109 assertFalse("External activities should not be started to handle the url
", |
97 mNavigationDelegate.hasExternalActivityStarted()); | 110 mNavigationDelegate.hasExternalActivityStarted()); |
98 } | 111 } |
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 } | |
135 } | 112 } |
OLD | NEW |