Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/externalnav/ExternalNavigationHandlerTest.java

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

Powered by Google App Engine
This is Rietveld 408576698