Chromium Code Reviews| 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.test.InstrumentationTestCase; | 16 import android.test.InstrumentationTestCase; |
| 17 import android.test.mock.MockContext; | 17 import android.test.mock.MockContext; |
| 18 import android.test.mock.MockPackageManager; | 18 import android.test.mock.MockPackageManager; |
| 19 import android.test.suitebuilder.annotation.SmallTest; | 19 import android.test.suitebuilder.annotation.SmallTest; |
| 20 | 20 |
| 21 import org.chromium.base.CommandLine; | 21 import org.chromium.base.CommandLine; |
| 22 import org.chromium.base.metrics.RecordHistogram; | 22 import org.chromium.base.metrics.RecordHistogram; |
| 23 import org.chromium.chrome.browser.IntentHandler; | 23 import org.chromium.chrome.browser.IntentHandler; |
| 24 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid eUrlLoadingResult; | 24 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid eUrlLoadingResult; |
| 25 import org.chromium.chrome.browser.tab.Tab; | 25 import org.chromium.chrome.browser.tab.Tab; |
| 26 import org.chromium.chrome.browser.tab.TabRedirectHandler; | 26 import org.chromium.chrome.browser.tab.TabRedirectHandler; |
| 27 import org.chromium.chrome.browser.util.FeatureUtilities; | 27 import org.chromium.chrome.browser.util.FeatureUtilities; |
| 28 import org.chromium.ui.base.PageTransition; | 28 import org.chromium.ui.base.PageTransition; |
| 29 import org.chromium.webapk.lib.common.WebApkConstants; | |
| 29 | 30 |
| 30 import java.net.URISyntaxException; | 31 import java.net.URISyntaxException; |
| 31 import java.util.ArrayList; | 32 import java.util.ArrayList; |
| 32 import java.util.List; | 33 import java.util.List; |
| 33 | 34 |
| 34 /** | 35 /** |
| 35 * Instrumentation tests for {@link ExternalNavigationHandler}. | 36 * Instrumentation tests for {@link ExternalNavigationHandler}. |
| 36 */ | 37 */ |
| 37 public class ExternalNavigationHandlerTest extends InstrumentationTestCase { | 38 public class ExternalNavigationHandlerTest extends InstrumentationTestCase { |
| 38 | 39 |
| 39 // Expectations | 40 // Expectations |
| 40 private static final int IGNORE = 0x0; | 41 private static final int IGNORE = 0x0; |
| 41 private static final int START_INCOGNITO = 0x1; | 42 private static final int START_INCOGNITO = 0x1; |
| 42 private static final int START_CHROME = 0x2; | 43 private static final int START_CHROME = 0x2; |
| 43 private static final int START_FILE = 0x4; | 44 private static final int START_WEBAPK = 0x4; |
| 44 private static final int START_OTHER_ACTIVITY = 0x8; | 45 private static final int START_FILE = 0x8; |
| 45 private static final int INTENT_SANITIZATION_EXCEPTION = 0x10; | 46 private static final int START_OTHER_ACTIVITY = 0x10; |
| 47 private static final int INTENT_SANITIZATION_EXCEPTION = 0x20; | |
| 46 | 48 |
| 47 private static final String SEARCH_RESULT_URL_FOR_TOM_HANKS = | 49 private static final String SEARCH_RESULT_URL_FOR_TOM_HANKS = |
| 48 "https://www.google.com/search?q=tom+hanks"; | 50 "https://www.google.com/search?q=tom+hanks"; |
| 49 private static final String IMDB_WEBPAGE_FOR_TOM_HANKS = "http://m.imdb.com/ name/nm0000158"; | 51 private static final String IMDB_WEBPAGE_FOR_TOM_HANKS = "http://m.imdb.com/ name/nm0000158"; |
| 50 private static final String INTENT_URL_WITH_FALLBACK_URL = | 52 private static final String INTENT_URL_WITH_FALLBACK_URL = |
| 51 "intent:///name/nm0000158#Intent;scheme=imdb;package=com.imdb.mobile ;" | 53 "intent:///name/nm0000158#Intent;scheme=imdb;package=com.imdb.mobile ;" |
| 52 + "S." + ExternalNavigationHandler.EXTRA_BROWSER_FALLBACK_URL + "=" | 54 + "S." + ExternalNavigationHandler.EXTRA_BROWSER_FALLBACK_URL + "=" |
| 53 + Uri.encode(IMDB_WEBPAGE_FOR_TOM_HANKS) + ";end"; | 55 + Uri.encode(IMDB_WEBPAGE_FOR_TOM_HANKS) + ";end"; |
| 54 private static final String INTENT_URL_WITH_FALLBACK_URL_WITHOUT_PACKAGE_NAM E = | 56 private static final String INTENT_URL_WITH_FALLBACK_URL_WITHOUT_PACKAGE_NAM E = |
| 55 "intent:///name/nm0000158#Intent;scheme=imdb;" | 57 "intent:///name/nm0000158#Intent;scheme=imdb;" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 66 + "S." + ExternalNavigationHandler.EXTRA_BROWSER_FALLBACK_URL + "=" | 68 + "S." + ExternalNavigationHandler.EXTRA_BROWSER_FALLBACK_URL + "=" |
| 67 + Uri.encode("http://url.myredirector.com/aaa") + ";end"; | 69 + Uri.encode("http://url.myredirector.com/aaa") + ";end"; |
| 68 | 70 |
| 69 private static final String PLUS_STREAM_URL = "https://plus.google.com/strea m"; | 71 private static final String PLUS_STREAM_URL = "https://plus.google.com/strea m"; |
| 70 private static final String CALENDAR_URL = "http://www.google.com/calendar"; | 72 private static final String CALENDAR_URL = "http://www.google.com/calendar"; |
| 71 private static final String KEEP_URL = "http://www.google.com/keep"; | 73 private static final String KEEP_URL = "http://www.google.com/keep"; |
| 72 | 74 |
| 73 private static final String TEXT_APP_1_PACKAGE_NAME = "text_app_1"; | 75 private static final String TEXT_APP_1_PACKAGE_NAME = "text_app_1"; |
| 74 private static final String TEXT_APP_2_PACKAGE_NAME = "text_app_2"; | 76 private static final String TEXT_APP_2_PACKAGE_NAME = "text_app_2"; |
| 75 | 77 |
| 78 private static final String WEBAPK_SCOPE = "https://www.template.com"; | |
| 79 private static final String WEBAPK_PACKAGE_NAME = "org.chromium.webapk.templ ate"; | |
| 80 | |
| 81 private static final String WEBAPK_WITH_NATIVE_APP_SCOPE = | |
| 82 "https://www.webapk.with.native.com"; | |
| 83 private static final String WEBAPK_WITH_NATIVE_APP_PACKAGE_NAME = | |
| 84 "org.chromium.webapk.with.native"; | |
| 85 private static final String NATIVE_APP_PACKAGE_NAME = "com.webapk.with.nativ e.android"; | |
| 86 | |
| 87 private static final String COUNTERFEIT_WEBAPK_SCOPE = "http://www.counterfe ight.webapk.com"; | |
| 88 private static final String COUNTERFEIT_WEBAPK_PACKAGE_NAME = | |
| 89 "org.chromium.webapk.counterfeight"; | |
| 90 | |
| 76 private final TestExternalNavigationDelegate mDelegate; | 91 private final TestExternalNavigationDelegate mDelegate; |
| 77 private ExternalNavigationHandler mUrlHandler; | 92 private ExternalNavigationHandler mUrlHandler; |
| 78 | 93 |
| 79 public ExternalNavigationHandlerTest() { | 94 public ExternalNavigationHandlerTest() { |
| 80 mDelegate = new TestExternalNavigationDelegate(); | 95 mDelegate = new TestExternalNavigationDelegate(); |
| 81 mUrlHandler = new ExternalNavigationHandler(mDelegate); | 96 mUrlHandler = new ExternalNavigationHandler(mDelegate); |
| 82 } | 97 } |
| 83 | 98 |
| 84 @Override | 99 @Override |
| 85 protected void setUp() throws Exception { | 100 protected void setUp() throws Exception { |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 743 checkUrl("intent://012345678?body=hello%20there/#Intent;scheme=sms;end") | 758 checkUrl("intent://012345678?body=hello%20there/#Intent;scheme=sms;end") |
| 744 .withReferrer(referer) | 759 .withReferrer(referer) |
| 745 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN T, | 760 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN T, |
| 746 START_OTHER_ACTIVITY); | 761 START_OTHER_ACTIVITY); |
| 747 | 762 |
| 748 assertNotNull(mDelegate.startActivityIntent); | 763 assertNotNull(mDelegate.startActivityIntent); |
| 749 assertEquals(TEXT_APP_2_PACKAGE_NAME, mDelegate.startActivityIntent.getP ackage()); | 764 assertEquals(TEXT_APP_2_PACKAGE_NAME, mDelegate.startActivityIntent.getP ackage()); |
| 750 } | 765 } |
| 751 | 766 |
| 752 /** | 767 /** |
| 753 * Test that tapping on a link which is outside of the referrer Web APK's sc ope brings the | 768 * Test that tapping on a link which is outside of the referrer WebAPK's sco pe brings the |
| 754 * user back to Chrome. | 769 * user back to Chrome. |
| 755 */ | 770 */ |
| 756 @SmallTest | 771 @SmallTest |
| 757 public void testLeaveWebApk_LinkOutOfScope() { | 772 public void testLeaveWebApk_LinkOutOfScope() { |
| 758 checkUrl(SEARCH_RESULT_URL_FOR_TOM_HANKS) | 773 checkUrl(SEARCH_RESULT_URL_FOR_TOM_HANKS) |
| 759 .withIsWebApk(true) | 774 .withWebApkPackageName(WEBAPK_PACKAGE_NAME) |
| 760 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN T, START_CHROME); | 775 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN T, START_CHROME); |
| 761 } | 776 } |
| 762 | 777 |
| 778 /** | |
| 779 * Test that tapping a link which falls solely in the scope of a WebAPK laun ches a WebAPK | |
| 780 * without showing the intent picker. | |
| 781 */ | |
| 782 @SmallTest | |
| 783 public void testLaunchWebApk_BypassIntentPicker() { | |
| 784 checkUrl(WEBAPK_SCOPE) | |
| 785 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN T, START_WEBAPK); | |
| 786 } | |
| 787 | |
| 788 /** | |
| 789 * Test that tapping a link which falls in the scope of multiple intent hand lers, one of which | |
| 790 * is a WebAPK, shows the intent picker. | |
| 791 */ | |
| 792 @SmallTest | |
| 793 public void testLaunchWebApk_ShowIntentPickerMultipleIntentHandlers() { | |
| 794 checkUrl(WEBAPK_WITH_NATIVE_APP_SCOPE) | |
| 795 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN T, | |
| 796 START_OTHER_ACTIVITY); | |
| 797 } | |
| 798 | |
| 799 /** | |
| 800 * Test that tapping a link which falls into the scope of a different WebAPK launches a WebAPK | |
| 801 * without showing the intent picker. | |
|
Xi Han
2016/06/07 19:16:47
This is because the other WebAPK is the only handl
pkotwicz
2016/06/07 22:07:07
I changed the comment to say "solely falls into th
Xi Han
2016/06/08 14:00:11
Thanks for updating the comment!
| |
| 802 */ | |
| 803 @SmallTest | |
| 804 public void testLaunchWebApk_BypassIntentPickerFromAnotherWebApk() { | |
| 805 checkUrl(WEBAPK_SCOPE) | |
| 806 .withReferrer(WEBAPK_WITH_NATIVE_APP_SCOPE) | |
| 807 .withWebApkPackageName(WEBAPK_WITH_NATIVE_APP_PACKAGE_NAME) | |
| 808 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN T, START_WEBAPK); | |
| 809 } | |
| 810 | |
| 811 /** | |
| 812 * Test that a link which falls into the scope of an invalid WebAPK (e.g. it was incorrectly | |
| 813 * signed) does not get any special WebAPK handling. The first time that the user taps on the | |
| 814 * link, the intent picker should be shown. | |
| 815 */ | |
| 816 @SmallTest | |
| 817 public void testLaunchWebApk_ShowIntentPickerInvalidWebApk() { | |
| 818 checkUrl(COUNTERFEIT_WEBAPK_SCOPE) | |
| 819 .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN T, | |
| 820 START_OTHER_ACTIVITY); | |
| 821 } | |
| 822 | |
| 823 /** | |
| 824 * Test that tapping a link which falls into the scope of the current WebAPK stays within the | |
| 825 * WebAPK. | |
| 826 */ | |
| 827 @SmallTest | |
| 828 public void testLaunchWebApk_StayInSameWebApk() { | |
| 829 checkUrl(WEBAPK_SCOPE + "/new.html") | |
| 830 .withReferrer(WEBAPK_SCOPE) | |
| 831 .withWebApkPackageName(WEBAPK_PACKAGE_NAME) | |
| 832 .expecting(OverrideUrlLoadingResult.NO_OVERRIDE, IGNORE); | |
| 833 } | |
| 834 | |
| 763 private static ResolveInfo newResolveInfo(String packageName, String name) { | 835 private static ResolveInfo newResolveInfo(String packageName, String name) { |
| 764 ActivityInfo ai = new ActivityInfo(); | 836 ActivityInfo ai = new ActivityInfo(); |
| 765 ai.packageName = packageName; | 837 ai.packageName = packageName; |
| 766 ai.name = name; | 838 ai.name = name; |
| 767 ResolveInfo ri = new ResolveInfo(); | 839 ResolveInfo ri = new ResolveInfo(); |
| 768 ri.activityInfo = ai; | 840 ri.activityInfo = ai; |
| 769 return ri; | 841 return ri; |
| 770 } | 842 } |
| 771 | 843 |
| 772 private static class TestExternalNavigationDelegate implements ExternalNavig ationDelegate { | 844 private static class TestExternalNavigationDelegate implements ExternalNavig ationDelegate { |
| 773 private Context mContext; | 845 private Context mContext; |
| 774 | 846 |
| 775 public void setContext(Context context) { | 847 public void setContext(Context context) { |
| 776 mContext = context; | 848 mContext = context; |
| 777 } | 849 } |
| 778 | 850 |
| 779 @Override | 851 @Override |
| 780 public List<ResolveInfo> queryIntentActivities(Intent intent) { | 852 public List<ResolveInfo> queryIntentActivities(Intent intent) { |
| 781 List<ResolveInfo> list = new ArrayList<ResolveInfo>(); | 853 List<ResolveInfo> list = new ArrayList<ResolveInfo>(); |
| 782 // TODO(yfriedman): We shouldn't have a separate global override jus t for tests - we | 854 // TODO(yfriedman): We shouldn't have a separate global override jus t for tests - we |
| 783 // should mimic the appropriate intent resolution intead. | 855 // should mimic the appropriate intent resolution intead. |
| 784 if (mQueryIntentOverride != null) { | 856 if (mQueryIntentOverride != null) { |
| 785 if (mQueryIntentOverride.booleanValue()) { | 857 if (mQueryIntentOverride.booleanValue()) { |
| 786 list.add(newResolveInfo("foo", "foo")); | 858 list.add(newResolveInfo("foo", "foo")); |
| 787 } else { | 859 } else { |
| 788 return list; | 860 return list; |
| 789 } | 861 } |
| 790 } | 862 } |
| 791 if (intent.getDataString().startsWith("http://") | 863 String dataString = intent.getDataString(); |
| 864 if (dataString.startsWith("http://") | |
| 792 || intent.getDataString().startsWith("https://")) { | 865 || intent.getDataString().startsWith("https://")) { |
| 793 list.add(newResolveInfo("chrome", "chrome")); | 866 list.add(newResolveInfo("chrome", "chrome")); |
| 794 } | 867 } |
| 795 if (intent.getDataString().startsWith("http://m.youtube.com") | 868 if (dataString.startsWith("http://m.youtube.com") |
| 796 || intent.getDataString().startsWith("http://youtube.com")) { | 869 || intent.getDataString().startsWith("http://youtube.com")) { |
| 797 list.add(newResolveInfo("youtube", "youtube")); | 870 list.add(newResolveInfo("youtube", "youtube")); |
| 798 } else if (intent.getDataString().startsWith(PLUS_STREAM_URL)) { | 871 } else if (dataString.startsWith(PLUS_STREAM_URL)) { |
| 799 list.add(newResolveInfo("plus", "plus")); | 872 list.add(newResolveInfo("plus", "plus")); |
| 800 } else if (intent.getDataString().startsWith(CALENDAR_URL)) { | 873 } else if (intent.getDataString().startsWith(CALENDAR_URL)) { |
| 801 list.add(newResolveInfo("calendar", "calendar")); | 874 list.add(newResolveInfo("calendar", "calendar")); |
| 802 } else if (intent.getDataString().startsWith("sms")) { | 875 } else if (dataString.startsWith("sms")) { |
| 803 list.add(newResolveInfo( | 876 list.add(newResolveInfo( |
| 804 TEXT_APP_1_PACKAGE_NAME, TEXT_APP_1_PACKAGE_NAME + ".cls ")); | 877 TEXT_APP_1_PACKAGE_NAME, TEXT_APP_1_PACKAGE_NAME + ".cls ")); |
| 805 list.add(newResolveInfo( | 878 list.add(newResolveInfo( |
| 806 TEXT_APP_2_PACKAGE_NAME, TEXT_APP_2_PACKAGE_NAME + ".cls ")); | 879 TEXT_APP_2_PACKAGE_NAME, TEXT_APP_2_PACKAGE_NAME + ".cls ")); |
| 880 } else if (dataString.startsWith(WEBAPK_SCOPE)) { | |
| 881 list.add(newResolveInfo(WEBAPK_PACKAGE_NAME, WEBAPK_PACKAGE_NAME )); | |
| 882 } else if (dataString.startsWith(WEBAPK_WITH_NATIVE_APP_SCOPE)) { | |
| 883 list.add(newResolveInfo(WEBAPK_WITH_NATIVE_APP_PACKAGE_NAME, | |
| 884 WEBAPK_WITH_NATIVE_APP_PACKAGE_NAME)); | |
| 885 list.add(newResolveInfo(NATIVE_APP_PACKAGE_NAME, NATIVE_APP_PACK AGE_NAME)); | |
| 886 } else if (dataString.startsWith(COUNTERFEIT_WEBAPK_SCOPE)) { | |
| 887 list.add(newResolveInfo(COUNTERFEIT_WEBAPK_PACKAGE_NAME, COUNTER FEIT_WEBAPK_SCOPE)); | |
| 807 } else { | 888 } else { |
| 808 list.add(newResolveInfo("foo", "foo")); | 889 list.add(newResolveInfo("foo", "foo")); |
| 809 } | 890 } |
| 810 return list; | 891 return list; |
| 811 } | 892 } |
| 812 | 893 |
| 813 @Override | 894 @Override |
| 814 public boolean willChromeHandleIntent(Intent intent) { | 895 public boolean willChromeHandleIntent(Intent intent) { |
| 815 return !isSpecializedHandlerAvailable(queryIntentActivities(intent)) ; | 896 return !isSpecializedHandlerAvailable(queryIntentActivities(intent)) ; |
| 816 } | 897 } |
| 817 | 898 |
| 818 @Override | 899 @Override |
| 819 public boolean isSpecializedHandlerAvailable(List<ResolveInfo> resolveIn fos) { | 900 public boolean isSpecializedHandlerAvailable(List<ResolveInfo> resolveIn fos) { |
| 820 for (ResolveInfo resolveInfo : resolveInfos) { | 901 return countSpecializedHandlers(resolveInfos) > 0; |
| 821 String packageName = resolveInfo.activityInfo.packageName; | |
| 822 if (packageName.equals("youtube") || packageName.equals("calenda r")) { | |
| 823 return true; | |
| 824 } | |
| 825 } | |
| 826 return false; | |
| 827 } | 902 } |
| 828 | 903 |
| 829 @Override | 904 @Override |
| 905 public int countSpecializedHandlers(List<ResolveInfo> infos) { | |
| 906 if (infos == null) { | |
| 907 return 0; | |
| 908 } | |
| 909 int count = 0; | |
| 910 for (ResolveInfo info : infos) { | |
| 911 String packageName = info.activityInfo.packageName; | |
| 912 if (packageName.equals("youtube") || packageName.equals("calenda r") | |
| 913 || packageName.equals(WEBAPK_WITH_NATIVE_APP_PACKAGE_NAM E) | |
| 914 || packageName.equals(WEBAPK_PACKAGE_NAME) | |
| 915 || packageName.equals(COUNTERFEIT_WEBAPK_PACKAGE_NAME) | |
| 916 || packageName.equals(NATIVE_APP_PACKAGE_NAME)) { | |
| 917 ++count; | |
| 918 } | |
| 919 } | |
| 920 return count; | |
| 921 } | |
| 922 | |
| 923 @Override | |
| 924 public String findValidWebApkPackageName(List<ResolveInfo> infos) { | |
| 925 if (infos == null) { | |
| 926 return null; | |
| 927 } | |
| 928 for (ResolveInfo info : infos) { | |
| 929 String packageName = info.activityInfo.packageName; | |
| 930 if (packageName.equals(WEBAPK_PACKAGE_NAME) | |
| 931 || packageName.equals(WEBAPK_WITH_NATIVE_APP_PACKAGE_NAM E)) { | |
| 932 return packageName; | |
| 933 } | |
| 934 } | |
| 935 return null; | |
| 936 } | |
| 937 | |
| 938 @Override | |
| 830 public String getPackageName() { | 939 public String getPackageName() { |
| 831 return "test"; | 940 return "test"; |
| 832 } | 941 } |
| 833 | 942 |
| 834 @Override | 943 @Override |
| 835 public void startActivity(Intent intent) { | 944 public void startActivity(Intent intent) { |
| 836 startActivityIntent = intent; | 945 startActivityIntent = intent; |
| 837 } | 946 } |
| 838 | 947 |
| 839 @Override | 948 @Override |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 943 | 1052 |
| 944 private class ExternalNavigationTestParams { | 1053 private class ExternalNavigationTestParams { |
| 945 private final String mUrl; | 1054 private final String mUrl; |
| 946 | 1055 |
| 947 private String mReferrerUrl; | 1056 private String mReferrerUrl; |
| 948 private boolean mIsIncognito; | 1057 private boolean mIsIncognito; |
| 949 private int mPageTransition = PageTransition.LINK; | 1058 private int mPageTransition = PageTransition.LINK; |
| 950 private boolean mIsRedirect; | 1059 private boolean mIsRedirect; |
| 951 private boolean mChromeAppInForegroundRequired = true; | 1060 private boolean mChromeAppInForegroundRequired = true; |
| 952 private boolean mIsBackgroundTabNavigation; | 1061 private boolean mIsBackgroundTabNavigation; |
| 953 private boolean mIsWebApk; | 1062 private String mWebApkPackageName; |
| 954 private boolean mHasUserGesture; | 1063 private boolean mHasUserGesture; |
| 955 private TabRedirectHandler mRedirectHandler; | 1064 private TabRedirectHandler mRedirectHandler; |
| 956 | 1065 |
| 957 private ExternalNavigationTestParams(String url) { | 1066 private ExternalNavigationTestParams(String url) { |
| 958 mUrl = url; | 1067 mUrl = url; |
| 959 } | 1068 } |
| 960 | 1069 |
| 961 public ExternalNavigationTestParams withIsWebApk(boolean isWebApk) { | 1070 public ExternalNavigationTestParams withWebApkPackageName(String webApkP ackageName) { |
| 962 mIsWebApk = isWebApk; | 1071 mWebApkPackageName = webApkPackageName; |
| 963 return this; | 1072 return this; |
| 964 } | 1073 } |
| 965 | 1074 |
| 966 public ExternalNavigationTestParams withReferrer(String referrerUrl) { | 1075 public ExternalNavigationTestParams withReferrer(String referrerUrl) { |
| 967 mReferrerUrl = referrerUrl; | 1076 mReferrerUrl = referrerUrl; |
| 968 return this; | 1077 return this; |
| 969 } | 1078 } |
| 970 | 1079 |
| 971 public ExternalNavigationTestParams withIsIncognito(boolean isIncognito) { | 1080 public ExternalNavigationTestParams withIsIncognito(boolean isIncognito) { |
| 972 mIsIncognito = isIncognito; | 1081 mIsIncognito = isIncognito; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1002 | 1111 |
| 1003 public ExternalNavigationTestParams withRedirectHandler(TabRedirectHandl er handler) { | 1112 public ExternalNavigationTestParams withRedirectHandler(TabRedirectHandl er handler) { |
| 1004 mRedirectHandler = handler; | 1113 mRedirectHandler = handler; |
| 1005 return this; | 1114 return this; |
| 1006 } | 1115 } |
| 1007 | 1116 |
| 1008 public void expecting(OverrideUrlLoadingResult expectedOverrideResult, | 1117 public void expecting(OverrideUrlLoadingResult expectedOverrideResult, |
| 1009 int otherExpectation) { | 1118 int otherExpectation) { |
| 1010 boolean expectStartIncognito = (otherExpectation & START_INCOGNITO) != 0; | 1119 boolean expectStartIncognito = (otherExpectation & START_INCOGNITO) != 0; |
| 1011 boolean expectStartActivity = | 1120 boolean expectStartActivity = |
| 1012 (otherExpectation & (START_CHROME | START_OTHER_ACTIVITY)) ! = 0; | 1121 (otherExpectation & (START_CHROME | START_WEBAPK | START_OTH ER_ACTIVITY)) != 0; |
| 1013 boolean expectStartChrome = (otherExpectation & START_CHROME) != 0; | 1122 boolean expectStartChrome = (otherExpectation & START_CHROME) != 0; |
| 1123 boolean expectStartWebApk = (otherExpectation & START_WEBAPK) != 0; | |
| 1014 boolean expectStartOtherActivity = (otherExpectation & START_OTHER_A CTIVITY) != 0; | 1124 boolean expectStartOtherActivity = (otherExpectation & START_OTHER_A CTIVITY) != 0; |
| 1015 boolean expectStartFile = (otherExpectation & START_FILE) != 0; | 1125 boolean expectStartFile = (otherExpectation & START_FILE) != 0; |
| 1016 boolean expectSaneIntent = expectStartOtherActivity | 1126 boolean expectSaneIntent = expectStartOtherActivity |
| 1017 && (otherExpectation & INTENT_SANITIZATION_EXCEPTION) == 0; | 1127 && (otherExpectation & INTENT_SANITIZATION_EXCEPTION) == 0; |
| 1018 | 1128 |
| 1019 mDelegate.reset(); | 1129 mDelegate.reset(); |
| 1020 | 1130 |
| 1021 ExternalNavigationParams params = new ExternalNavigationParams.Build er( | 1131 ExternalNavigationParams params = new ExternalNavigationParams.Build er( |
| 1022 mUrl, mIsIncognito, mReferrerUrl, | 1132 mUrl, mIsIncognito, mReferrerUrl, |
| 1023 mPageTransition, mIsRedirect) | 1133 mPageTransition, mIsRedirect) |
| 1024 .setApplicationMustBeInForeground(mChromeAppInForegroundRequ ired) | 1134 .setApplicationMustBeInForeground(mChromeAppInForegroundRequ ired) |
| 1025 .setRedirectHandler(mRedirectHandler) | 1135 .setRedirectHandler(mRedirectHandler) |
| 1026 .setIsBackgroundTabNavigation(mIsBackgroundTabNavigation) | 1136 .setIsBackgroundTabNavigation(mIsBackgroundTabNavigation) |
| 1027 .setIsMainFrame(true) | 1137 .setIsMainFrame(true) |
| 1028 .setIsWebApk(mIsWebApk) | 1138 .setWebApkPackageName(mWebApkPackageName) |
| 1029 .setHasUserGesture(mHasUserGesture) | 1139 .setHasUserGesture(mHasUserGesture) |
| 1030 .build(); | 1140 .build(); |
| 1031 OverrideUrlLoadingResult result = mUrlHandler.shouldOverrideUrlLoadi ng(params); | 1141 OverrideUrlLoadingResult result = mUrlHandler.shouldOverrideUrlLoadi ng(params); |
| 1032 boolean startActivityCalled = false; | 1142 boolean startActivityCalled = false; |
| 1033 boolean startChromeCalled = false; | 1143 boolean startChromeCalled = false; |
| 1144 boolean startWebApkCalled = false; | |
| 1034 if (mDelegate.startActivityIntent != null) { | 1145 if (mDelegate.startActivityIntent != null) { |
| 1035 startActivityCalled = true; | 1146 startActivityCalled = true; |
| 1036 String packageName = mDelegate.startActivityIntent.getPackage(); | 1147 String packageName = mDelegate.startActivityIntent.getPackage(); |
| 1037 startChromeCalled = | 1148 if (packageName != null) { |
| 1038 packageName != null && packageName.equals(mDelegate.getP ackageName()); | 1149 startChromeCalled = packageName.equals(mDelegate.getPackageN ame()); |
| 1150 startWebApkCalled = | |
| 1151 packageName.startsWith(WebApkConstants.WEBAPK_PACKAG E_PREFIX); | |
| 1152 } | |
| 1039 } | 1153 } |
| 1040 | 1154 |
| 1041 assertEquals(expectedOverrideResult, result); | 1155 assertEquals(expectedOverrideResult, result); |
| 1042 assertEquals(expectStartIncognito, mDelegate.startIncognitoIntentCal led); | 1156 assertEquals(expectStartIncognito, mDelegate.startIncognitoIntentCal led); |
| 1043 assertEquals(expectStartActivity, startActivityCalled); | 1157 assertEquals(expectStartActivity, startActivityCalled); |
| 1044 assertEquals(expectStartChrome, startChromeCalled); | 1158 assertEquals(expectStartChrome, startChromeCalled); |
| 1159 assertEquals(expectStartWebApk, startWebApkCalled); | |
| 1045 assertEquals(expectStartFile, mDelegate.startFileIntentCalled); | 1160 assertEquals(expectStartFile, mDelegate.startFileIntentCalled); |
| 1046 | 1161 |
| 1047 if (startActivityCalled && expectSaneIntent) { | 1162 if (startActivityCalled && expectSaneIntent) { |
| 1048 checkIntentSanity(mDelegate.startActivityIntent, "Intent"); | 1163 checkIntentSanity(mDelegate.startActivityIntent, "Intent"); |
| 1049 if (mDelegate.startActivityIntent.getSelector() != null) { | 1164 if (mDelegate.startActivityIntent.getSelector() != null) { |
| 1050 checkIntentSanity(mDelegate.startActivityIntent.getSelector( ), | 1165 checkIntentSanity(mDelegate.startActivityIntent.getSelector( ), |
| 1051 "Intent's selector"); | 1166 "Intent's selector"); |
| 1052 } | 1167 } |
| 1053 } | 1168 } |
| 1054 } | 1169 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1076 return new TestPackageManager(); | 1191 return new TestPackageManager(); |
| 1077 } | 1192 } |
| 1078 | 1193 |
| 1079 @Override | 1194 @Override |
| 1080 public String getPackageName() { | 1195 public String getPackageName() { |
| 1081 return "test.app.name"; | 1196 return "test.app.name"; |
| 1082 } | 1197 } |
| 1083 | 1198 |
| 1084 } | 1199 } |
| 1085 } | 1200 } |
| OLD | NEW |