| 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.test.FlakyTest; | 9 import android.test.FlakyTest; |
| 10 import android.test.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
| 11 | 11 |
| 12 import org.chromium.base.ApplicationStatus; | 12 import org.chromium.base.ApplicationStatus; |
| 13 import org.chromium.base.ThreadUtils; | 13 import org.chromium.base.ThreadUtils; |
| 14 import org.chromium.chrome.browser.customtabs.CustomTab.CustomTabNavigationDeleg
ate; | 14 import org.chromium.chrome.browser.customtabs.CustomTabDelegateFactory.CustomTab
NavigationDelegate; |
| 15 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler; | 15 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler; |
| 16 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid
eUrlLoadingResult; | 16 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid
eUrlLoadingResult; |
| 17 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams; | 17 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams; |
| 18 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 18 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
| 19 import org.chromium.chrome.browser.tab.Tab; | 19 import org.chromium.chrome.browser.tab.Tab; |
| 20 import org.chromium.chrome.browser.tab.TabDelegateFactory; |
| 20 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 21 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
| 21 import org.chromium.chrome.browser.tabmodel.TabModelSelector; | 22 import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| 22 import org.chromium.chrome.test.util.TestHttpServerClient; | 23 import org.chromium.chrome.test.util.TestHttpServerClient; |
| 23 import org.chromium.content.browser.test.util.CallbackHelper; | 24 import org.chromium.content.browser.test.util.CallbackHelper; |
| 24 import org.chromium.content_public.browser.LoadUrlParams; | 25 import org.chromium.content_public.browser.LoadUrlParams; |
| 25 | 26 |
| 26 import java.util.concurrent.TimeoutException; | 27 import java.util.concurrent.TimeoutException; |
| 27 | 28 |
| 28 /** | 29 /** |
| 29 * Instrumentation test for external navigation handling in a {@link CustomTab}. | 30 * Instrumentation test for external navigation handling in a {@link CustomTab}. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 56 "chrome/test/data/android/google.html"); | 57 "chrome/test/data/android/google.html"); |
| 57 private ExternalNavigationHandler mUrlHandler; | 58 private ExternalNavigationHandler mUrlHandler; |
| 58 private CustomTabNavigationDelegate mNavigationDelegate; | 59 private CustomTabNavigationDelegate mNavigationDelegate; |
| 59 | 60 |
| 60 @Override | 61 @Override |
| 61 public void startMainActivity() throws InterruptedException { | 62 public void startMainActivity() throws InterruptedException { |
| 62 super.startMainActivity(); | 63 super.startMainActivity(); |
| 63 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCustom
TabIntent( | 64 startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCustom
TabIntent( |
| 64 getInstrumentation().getTargetContext(), TEST_URL, null)); | 65 getInstrumentation().getTargetContext(), TEST_URL, null)); |
| 65 Tab tab = getActivity().getActivityTab(); | 66 Tab tab = getActivity().getActivityTab(); |
| 66 assertTrue("A custom tab is not present in the activity.", tab instanceo
f CustomTab); | 67 TabDelegateFactory delegateFactory = tab.getDelegateFactoryForTest(); |
| 67 CustomTab customTab = (CustomTab) tab; | 68 assert delegateFactory instanceof CustomTabDelegateFactory; |
| 68 mUrlHandler = customTab.getExternalNavigationHandler(); | 69 mUrlHandler = ((CustomTabDelegateFactory) delegateFactory).getExternalNa
vigationHandler(); |
| 69 mNavigationDelegate = customTab.getExternalNavigationDelegate(); | 70 mNavigationDelegate = ((CustomTabDelegateFactory) delegateFactory) |
| 71 .getExternalNavigationDelegate(); |
| 70 } | 72 } |
| 71 | 73 |
| 72 /** | 74 /** |
| 73 * For urls with special schemes and hosts, and there is exactly one activit
y having a matching | 75 * For urls with special schemes and hosts, and there is exactly one activit
y having a matching |
| 74 * intent filter, the framework will make that activity the default handler
of the special url. | 76 * intent filter, the framework will make that activity the default handler
of the special url. |
| 75 * This test tests whether chrome is able to start the default external hand
ler. | 77 * This test tests whether chrome is able to start the default external hand
ler. |
| 76 */ | 78 */ |
| 77 @SmallTest | 79 @SmallTest |
| 78 public void testExternalActivityStartedForDefaultUrl() { | 80 public void testExternalActivityStartedForDefaultUrl() { |
| 79 final String testUrl = "customtab://customtabtest/intent"; | 81 final String testUrl = "customtab://customtabtest/intent"; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 false); | 130 false); |
| 129 } | 131 } |
| 130 }); | 132 }); |
| 131 | 133 |
| 132 loadUrlHelper.waitForCallback(0, 1); | 134 loadUrlHelper.waitForCallback(0, 1); |
| 133 assertTrue("A new tab should not have been created.", | 135 assertTrue("A new tab should not have been created.", |
| 134 ApplicationStatus.getLastTrackedFocusedActivity() == getActivity
()); | 136 ApplicationStatus.getLastTrackedFocusedActivity() == getActivity
()); |
| 135 assertEquals(testUrl, getActivity().getActivityTab().getUrl()); | 137 assertEquals(testUrl, getActivity().getActivityTab().getUrl()); |
| 136 } | 138 } |
| 137 } | 139 } |
| OLD | NEW |