| 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.externalnav; | 5 package org.chromium.chrome.browser.externalnav; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.content.pm.ActivityInfo; | 10 import android.content.pm.ActivityInfo; |
| 11 import android.content.pm.PackageManager; | 11 import android.content.pm.PackageManager; |
| 12 import android.content.pm.ResolveInfo; | 12 import android.content.pm.ResolveInfo; |
| 13 import android.net.Uri; | 13 import android.net.Uri; |
| 14 import android.os.SystemClock; | 14 import android.os.SystemClock; |
| 15 import android.provider.Browser; | 15 import android.provider.Browser; |
| 16 import android.support.customtabs.CustomTabsIntent; | 16 import android.support.customtabs.CustomTabsIntent; |
| 17 import android.test.InstrumentationTestCase; | 17 import android.test.InstrumentationTestCase; |
| 18 import android.test.mock.MockContext; | 18 import android.test.mock.MockContext; |
| 19 import android.test.mock.MockPackageManager; | 19 import android.test.mock.MockPackageManager; |
| 20 import android.test.suitebuilder.annotation.SmallTest; | 20 import android.test.suitebuilder.annotation.SmallTest; |
| 21 | 21 |
| 22 import org.chromium.base.CommandLine; | |
| 23 import org.chromium.base.metrics.RecordHistogram; | 22 import org.chromium.base.metrics.RecordHistogram; |
| 24 import org.chromium.chrome.browser.ChromeSwitches; | |
| 25 import org.chromium.chrome.browser.IntentHandler; | 23 import org.chromium.chrome.browser.IntentHandler; |
| 26 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid
eUrlLoadingResult; | 24 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid
eUrlLoadingResult; |
| 27 import org.chromium.chrome.browser.tab.Tab; | 25 import org.chromium.chrome.browser.tab.Tab; |
| 28 import org.chromium.chrome.browser.tab.TabRedirectHandler; | 26 import org.chromium.chrome.browser.tab.TabRedirectHandler; |
| 29 import org.chromium.chrome.browser.util.FeatureUtilities; | 27 import org.chromium.chrome.browser.util.FeatureUtilities; |
| 28 import org.chromium.chrome.browser.webapps.ChromeWebApkHost; |
| 30 import org.chromium.ui.base.PageTransition; | 29 import org.chromium.ui.base.PageTransition; |
| 31 import org.chromium.webapk.lib.common.WebApkConstants; | 30 import org.chromium.webapk.lib.common.WebApkConstants; |
| 32 | 31 |
| 33 import java.net.URISyntaxException; | 32 import java.net.URISyntaxException; |
| 34 import java.util.ArrayList; | 33 import java.util.ArrayList; |
| 35 import java.util.List; | 34 import java.util.List; |
| 36 | 35 |
| 37 /** | 36 /** |
| 38 * Instrumentation tests for {@link ExternalNavigationHandler}. | 37 * Instrumentation tests for {@link ExternalNavigationHandler}. |
| 39 */ | 38 */ |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 102 |
| 104 public ExternalNavigationHandlerTest() { | 103 public ExternalNavigationHandlerTest() { |
| 105 mDelegate = new TestExternalNavigationDelegate(); | 104 mDelegate = new TestExternalNavigationDelegate(); |
| 106 mUrlHandler = new ExternalNavigationHandler(mDelegate); | 105 mUrlHandler = new ExternalNavigationHandler(mDelegate); |
| 107 } | 106 } |
| 108 | 107 |
| 109 @Override | 108 @Override |
| 110 protected void setUp() throws Exception { | 109 protected void setUp() throws Exception { |
| 111 super.setUp(); | 110 super.setUp(); |
| 112 mDelegate.setContext(getInstrumentation().getTargetContext()); | 111 mDelegate.setContext(getInstrumentation().getTargetContext()); |
| 113 CommandLine.init(new String[0]); | |
| 114 RecordHistogram.disableForTests(); | 112 RecordHistogram.disableForTests(); |
| 115 mDelegate.mQueryIntentOverride = null; | 113 mDelegate.mQueryIntentOverride = null; |
| 114 ChromeWebApkHost.initForTesting(false); // disabled by default |
| 116 } | 115 } |
| 117 | 116 |
| 118 @SmallTest | 117 @SmallTest |
| 119 public void testOrdinaryIncognitoUri() { | 118 public void testOrdinaryIncognitoUri() { |
| 120 checkUrl("http://youtube.com/") | 119 checkUrl("http://youtube.com/") |
| 121 .withIsIncognito(true) | 120 .withIsIncognito(true) |
| 122 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_ASYNC_ACTION,
START_INCOGNITO); | 121 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_ASYNC_ACTION,
START_INCOGNITO); |
| 123 } | 122 } |
| 124 | 123 |
| 125 @SmallTest | 124 @SmallTest |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 */ | 856 */ |
| 858 @SmallTest | 857 @SmallTest |
| 859 public void testLeaveWebApk_LinkOutOfScope() { | 858 public void testLeaveWebApk_LinkOutOfScope() { |
| 860 checkUrl(SEARCH_RESULT_URL_FOR_TOM_HANKS) | 859 checkUrl(SEARCH_RESULT_URL_FOR_TOM_HANKS) |
| 861 .withWebApkPackageName(WEBAPK_PACKAGE_NAME) | 860 .withWebApkPackageName(WEBAPK_PACKAGE_NAME) |
| 862 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN
T, START_CHROME); | 861 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN
T, START_CHROME); |
| 863 } | 862 } |
| 864 | 863 |
| 865 /** | 864 /** |
| 866 * Test that tapping a link which falls solely into the scope of a WebAPK do
es not bypass the | 865 * Test that tapping a link which falls solely into the scope of a WebAPK do
es not bypass the |
| 867 * intent picker if WebAPKs are disabled in the command line. | 866 * intent picker if WebAPKs are not enabled. |
| 868 */ | 867 */ |
| 869 @SmallTest | 868 @SmallTest |
| 870 public void testLaunchWebApk_WebApkDisabledCommandLine() { | 869 public void testLaunchWebApk_WebApkNotEnabled() { |
| 871 checkUrl(WEBAPK_SCOPE) | 870 checkUrl(WEBAPK_SCOPE) |
| 872 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN
T, | 871 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN
T, |
| 873 START_OTHER_ACTIVITY); | 872 START_OTHER_ACTIVITY); |
| 874 } | 873 } |
| 875 | 874 |
| 876 /** | 875 /** |
| 877 * Test that tapping a link which falls solely in the scope of a WebAPK laun
ches a WebAPK | 876 * Test that tapping a link which falls solely in the scope of a WebAPK laun
ches a WebAPK |
| 878 * without showing the intent picker if WebAPKs are enabled in the command l
ine. | 877 * without showing the intent picker if WebAPKs are enabled. |
| 879 */ | 878 */ |
| 880 @SmallTest | 879 @SmallTest |
| 881 public void testLaunchWebApk_BypassIntentPicker() { | 880 public void testLaunchWebApk_BypassIntentPicker() { |
| 882 CommandLine.getInstance().appendSwitch(ChromeSwitches.ENABLE_WEBAPK); | 881 ChromeWebApkHost.initForTesting(true); |
| 883 checkUrl(WEBAPK_SCOPE) | 882 checkUrl(WEBAPK_SCOPE) |
| 884 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN
T, START_WEBAPK); | 883 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN
T, START_WEBAPK); |
| 885 } | 884 } |
| 886 | 885 |
| 887 /** | 886 /** |
| 888 * Test that tapping a link which falls in the scope of multiple intent hand
lers, one of which | 887 * Test that tapping a link which falls in the scope of multiple intent hand
lers, one of which |
| 889 * is a WebAPK, shows the intent picker. | 888 * is a WebAPK, shows the intent picker. |
| 890 */ | 889 */ |
| 891 @SmallTest | 890 @SmallTest |
| 892 public void testLaunchWebApk_ShowIntentPickerMultipleIntentHandlers() { | 891 public void testLaunchWebApk_ShowIntentPickerMultipleIntentHandlers() { |
| 893 CommandLine.getInstance().appendSwitch(ChromeSwitches.ENABLE_WEBAPK); | 892 ChromeWebApkHost.initForTesting(true); |
| 894 checkUrl(WEBAPK_WITH_NATIVE_APP_SCOPE) | 893 checkUrl(WEBAPK_WITH_NATIVE_APP_SCOPE) |
| 895 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN
T, | 894 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN
T, |
| 896 START_OTHER_ACTIVITY); | 895 START_OTHER_ACTIVITY); |
| 897 } | 896 } |
| 898 | 897 |
| 899 /** | 898 /** |
| 900 * Test that tapping a link which falls solely into the scope of a different
WebAPK launches a | 899 * Test that tapping a link which falls solely into the scope of a different
WebAPK launches a |
| 901 * WebAPK without showing the intent picker. | 900 * WebAPK without showing the intent picker. |
| 902 */ | 901 */ |
| 903 @SmallTest | 902 @SmallTest |
| 904 public void testLaunchWebApk_BypassIntentPickerFromAnotherWebApk() { | 903 public void testLaunchWebApk_BypassIntentPickerFromAnotherWebApk() { |
| 905 CommandLine.getInstance().appendSwitch(ChromeSwitches.ENABLE_WEBAPK); | 904 ChromeWebApkHost.initForTesting(true); |
| 906 checkUrl(WEBAPK_SCOPE) | 905 checkUrl(WEBAPK_SCOPE) |
| 907 .withReferrer(WEBAPK_WITH_NATIVE_APP_SCOPE) | 906 .withReferrer(WEBAPK_WITH_NATIVE_APP_SCOPE) |
| 908 .withWebApkPackageName(WEBAPK_WITH_NATIVE_APP_PACKAGE_NAME) | 907 .withWebApkPackageName(WEBAPK_WITH_NATIVE_APP_PACKAGE_NAME) |
| 909 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN
T, START_WEBAPK); | 908 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN
T, START_WEBAPK); |
| 910 } | 909 } |
| 911 | 910 |
| 912 /** | 911 /** |
| 913 * Test that a link which falls into the scope of an invalid WebAPK (e.g. it
was incorrectly | 912 * Test that a link which falls into the scope of an invalid WebAPK (e.g. it
was incorrectly |
| 914 * signed) does not get any special WebAPK handling. The first time that the
user taps on the | 913 * signed) does not get any special WebAPK handling. The first time that the
user taps on the |
| 915 * link, the intent picker should be shown. | 914 * link, the intent picker should be shown. |
| 916 */ | 915 */ |
| 917 @SmallTest | 916 @SmallTest |
| 918 public void testLaunchWebApk_ShowIntentPickerInvalidWebApk() { | 917 public void testLaunchWebApk_ShowIntentPickerInvalidWebApk() { |
| 919 CommandLine.getInstance().appendSwitch(ChromeSwitches.ENABLE_WEBAPK); | 918 ChromeWebApkHost.initForTesting(true); |
| 920 checkUrl(COUNTERFEIT_WEBAPK_SCOPE) | 919 checkUrl(COUNTERFEIT_WEBAPK_SCOPE) |
| 921 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN
T, | 920 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN
T, |
| 922 START_OTHER_ACTIVITY); | 921 START_OTHER_ACTIVITY); |
| 923 } | 922 } |
| 924 | 923 |
| 925 /** | 924 /** |
| 926 * Test that tapping a link which falls into the scope of the current WebAPK
stays within the | 925 * Test that tapping a link which falls into the scope of the current WebAPK
stays within the |
| 927 * WebAPK. | 926 * WebAPK. |
| 928 */ | 927 */ |
| 929 @SmallTest | 928 @SmallTest |
| 930 public void testLaunchWebApk_StayInSameWebApk() { | 929 public void testLaunchWebApk_StayInSameWebApk() { |
| 931 CommandLine.getInstance().appendSwitch(ChromeSwitches.ENABLE_WEBAPK); | 930 ChromeWebApkHost.initForTesting(true); |
| 932 checkUrl(WEBAPK_SCOPE + "/new.html") | 931 checkUrl(WEBAPK_SCOPE + "/new.html") |
| 933 .withWebApkPackageName(WEBAPK_PACKAGE_NAME) | 932 .withWebApkPackageName(WEBAPK_PACKAGE_NAME) |
| 934 .expecting(OverrideUrlLoadingResult.NO_OVERRIDE, IGNORE); | 933 .expecting(OverrideUrlLoadingResult.NO_OVERRIDE, IGNORE); |
| 935 } | 934 } |
| 936 | 935 |
| 937 private static ResolveInfo newResolveInfo(String packageName, String name) { | 936 private static ResolveInfo newResolveInfo(String packageName, String name) { |
| 938 ActivityInfo ai = new ActivityInfo(); | 937 ActivityInfo ai = new ActivityInfo(); |
| 939 ai.packageName = packageName; | 938 ai.packageName = packageName; |
| 940 ai.name = name; | 939 ai.name = name; |
| 941 ResolveInfo ri = new ResolveInfo(); | 940 ResolveInfo ri = new ResolveInfo(); |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 return new TestPackageManager(); | 1301 return new TestPackageManager(); |
| 1303 } | 1302 } |
| 1304 | 1303 |
| 1305 @Override | 1304 @Override |
| 1306 public String getPackageName() { | 1305 public String getPackageName() { |
| 1307 return "test.app.name"; | 1306 return "test.app.name"; |
| 1308 } | 1307 } |
| 1309 | 1308 |
| 1310 } | 1309 } |
| 1311 } | 1310 } |
| OLD | NEW |