Index: chrome/android/javatests/src/org/chromium/chrome/browser/externalnav/ExternalNavigationHandlerTest.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/externalnav/ExternalNavigationHandlerTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/externalnav/ExternalNavigationHandlerTest.java |
index 87a615876182c2405fe386bd134046e63f16d0ab..3be19b5c70278b22ab0a33d52070596c111c2f8b 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/externalnav/ExternalNavigationHandlerTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/externalnav/ExternalNavigationHandlerTest.java |
@@ -26,6 +26,7 @@ import org.chromium.chrome.browser.tab.Tab; |
import org.chromium.chrome.browser.tab.TabRedirectHandler; |
import org.chromium.chrome.browser.util.FeatureUtilities; |
import org.chromium.ui.base.PageTransition; |
+import org.chromium.webapk.lib.common.WebApkConstants; |
import java.net.URISyntaxException; |
import java.util.ArrayList; |
@@ -40,9 +41,10 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase { |
private static final int IGNORE = 0x0; |
private static final int START_INCOGNITO = 0x1; |
private static final int START_CHROME = 0x2; |
- private static final int START_FILE = 0x4; |
- private static final int START_OTHER_ACTIVITY = 0x8; |
- private static final int INTENT_SANITIZATION_EXCEPTION = 0x10; |
+ private static final int START_WEBAPK = 0x4; |
+ private static final int START_FILE = 0x8; |
+ private static final int START_OTHER_ACTIVITY = 0x10; |
+ private static final int INTENT_SANITIZATION_EXCEPTION = 0x20; |
private static final String SEARCH_RESULT_URL_FOR_TOM_HANKS = |
"https://www.google.com/search?q=tom+hanks"; |
@@ -73,6 +75,19 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase { |
private static final String TEXT_APP_1_PACKAGE_NAME = "text_app_1"; |
private static final String TEXT_APP_2_PACKAGE_NAME = "text_app_2"; |
+ private static final String WEBAPK_SCOPE = "https://www.template.com"; |
+ private static final String WEBAPK_PACKAGE_NAME = "org.chromium.webapk.template"; |
+ |
+ private static final String WEBAPK_WITH_NATIVE_APP_SCOPE = |
+ "https://www.webapk.with.native.com"; |
+ private static final String WEBAPK_WITH_NATIVE_APP_PACKAGE_NAME = |
+ "org.chromium.webapk.with.native"; |
+ private static final String NATIVE_APP_PACKAGE_NAME = "com.webapk.with.native.android"; |
+ |
+ private static final String COUNTERFEIT_WEBAPK_SCOPE = "http://www.counterfeight.webapk.com"; |
+ private static final String COUNTERFEIT_WEBAPK_PACKAGE_NAME = |
+ "org.chromium.webapk.counterfeight"; |
+ |
private final TestExternalNavigationDelegate mDelegate; |
private ExternalNavigationHandler mUrlHandler; |
@@ -750,16 +765,73 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase { |
} |
/** |
- * Test that tapping on a link which is outside of the referrer Web APK's scope brings the |
+ * Test that tapping on a link which is outside of the referrer WebAPK's scope brings the |
* user back to Chrome. |
*/ |
@SmallTest |
public void testLeaveWebApk_LinkOutOfScope() { |
checkUrl(SEARCH_RESULT_URL_FOR_TOM_HANKS) |
- .withIsWebApk(true) |
+ .withWebApkPackageName(WEBAPK_PACKAGE_NAME) |
.expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT, START_CHROME); |
} |
+ /** |
+ * Test that tapping a link which falls solely in the scope of a WebAPK launches a WebAPK |
+ * without showing the intent picker. |
+ */ |
+ @SmallTest |
+ public void testLaunchWebApk_BypassIntentPicker() { |
+ checkUrl(WEBAPK_SCOPE) |
+ .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT, START_WEBAPK); |
+ } |
+ |
+ /** |
+ * Test that tapping a link which falls in the scope of multiple intent handlers, one of which |
+ * is a WebAPK, shows the intent picker. |
+ */ |
+ @SmallTest |
+ public void testLaunchWebApk_ShowIntentPickerMultipleIntentHandlers() { |
+ checkUrl(WEBAPK_WITH_NATIVE_APP_SCOPE) |
+ .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT, |
+ START_OTHER_ACTIVITY); |
+ } |
+ |
+ /** |
+ * Test that tapping a link which falls into the scope of a different WebAPK launches a WebAPK |
+ * 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!
|
+ */ |
+ @SmallTest |
+ public void testLaunchWebApk_BypassIntentPickerFromAnotherWebApk() { |
+ checkUrl(WEBAPK_SCOPE) |
+ .withReferrer(WEBAPK_WITH_NATIVE_APP_SCOPE) |
+ .withWebApkPackageName(WEBAPK_WITH_NATIVE_APP_PACKAGE_NAME) |
+ .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT, START_WEBAPK); |
+ } |
+ |
+ /** |
+ * Test that a link which falls into the scope of an invalid WebAPK (e.g. it was incorrectly |
+ * signed) does not get any special WebAPK handling. The first time that the user taps on the |
+ * link, the intent picker should be shown. |
+ */ |
+ @SmallTest |
+ public void testLaunchWebApk_ShowIntentPickerInvalidWebApk() { |
+ checkUrl(COUNTERFEIT_WEBAPK_SCOPE) |
+ .expecting(OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT, |
+ START_OTHER_ACTIVITY); |
+ } |
+ |
+ /** |
+ * Test that tapping a link which falls into the scope of the current WebAPK stays within the |
+ * WebAPK. |
+ */ |
+ @SmallTest |
+ public void testLaunchWebApk_StayInSameWebApk() { |
+ checkUrl(WEBAPK_SCOPE + "/new.html") |
+ .withReferrer(WEBAPK_SCOPE) |
+ .withWebApkPackageName(WEBAPK_PACKAGE_NAME) |
+ .expecting(OverrideUrlLoadingResult.NO_OVERRIDE, IGNORE); |
+ } |
+ |
private static ResolveInfo newResolveInfo(String packageName, String name) { |
ActivityInfo ai = new ActivityInfo(); |
ai.packageName = packageName; |
@@ -788,22 +860,31 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase { |
return list; |
} |
} |
- if (intent.getDataString().startsWith("http://") |
+ String dataString = intent.getDataString(); |
+ if (dataString.startsWith("http://") |
|| intent.getDataString().startsWith("https://")) { |
list.add(newResolveInfo("chrome", "chrome")); |
} |
- if (intent.getDataString().startsWith("http://m.youtube.com") |
+ if (dataString.startsWith("http://m.youtube.com") |
|| intent.getDataString().startsWith("http://youtube.com")) { |
list.add(newResolveInfo("youtube", "youtube")); |
- } else if (intent.getDataString().startsWith(PLUS_STREAM_URL)) { |
+ } else if (dataString.startsWith(PLUS_STREAM_URL)) { |
list.add(newResolveInfo("plus", "plus")); |
} else if (intent.getDataString().startsWith(CALENDAR_URL)) { |
list.add(newResolveInfo("calendar", "calendar")); |
- } else if (intent.getDataString().startsWith("sms")) { |
+ } else if (dataString.startsWith("sms")) { |
list.add(newResolveInfo( |
TEXT_APP_1_PACKAGE_NAME, TEXT_APP_1_PACKAGE_NAME + ".cls")); |
list.add(newResolveInfo( |
TEXT_APP_2_PACKAGE_NAME, TEXT_APP_2_PACKAGE_NAME + ".cls")); |
+ } else if (dataString.startsWith(WEBAPK_SCOPE)) { |
+ list.add(newResolveInfo(WEBAPK_PACKAGE_NAME, WEBAPK_PACKAGE_NAME)); |
+ } else if (dataString.startsWith(WEBAPK_WITH_NATIVE_APP_SCOPE)) { |
+ list.add(newResolveInfo(WEBAPK_WITH_NATIVE_APP_PACKAGE_NAME, |
+ WEBAPK_WITH_NATIVE_APP_PACKAGE_NAME)); |
+ list.add(newResolveInfo(NATIVE_APP_PACKAGE_NAME, NATIVE_APP_PACKAGE_NAME)); |
+ } else if (dataString.startsWith(COUNTERFEIT_WEBAPK_SCOPE)) { |
+ list.add(newResolveInfo(COUNTERFEIT_WEBAPK_PACKAGE_NAME, COUNTERFEIT_WEBAPK_SCOPE)); |
} else { |
list.add(newResolveInfo("foo", "foo")); |
} |
@@ -817,13 +898,41 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase { |
@Override |
public boolean isSpecializedHandlerAvailable(List<ResolveInfo> resolveInfos) { |
- for (ResolveInfo resolveInfo : resolveInfos) { |
- String packageName = resolveInfo.activityInfo.packageName; |
- if (packageName.equals("youtube") || packageName.equals("calendar")) { |
- return true; |
+ return countSpecializedHandlers(resolveInfos) > 0; |
+ } |
+ |
+ @Override |
+ public int countSpecializedHandlers(List<ResolveInfo> infos) { |
+ if (infos == null) { |
+ return 0; |
+ } |
+ int count = 0; |
+ for (ResolveInfo info : infos) { |
+ String packageName = info.activityInfo.packageName; |
+ if (packageName.equals("youtube") || packageName.equals("calendar") |
+ || packageName.equals(WEBAPK_WITH_NATIVE_APP_PACKAGE_NAME) |
+ || packageName.equals(WEBAPK_PACKAGE_NAME) |
+ || packageName.equals(COUNTERFEIT_WEBAPK_PACKAGE_NAME) |
+ || packageName.equals(NATIVE_APP_PACKAGE_NAME)) { |
+ ++count; |
} |
} |
- return false; |
+ return count; |
+ } |
+ |
+ @Override |
+ public String findValidWebApkPackageName(List<ResolveInfo> infos) { |
+ if (infos == null) { |
+ return null; |
+ } |
+ for (ResolveInfo info : infos) { |
+ String packageName = info.activityInfo.packageName; |
+ if (packageName.equals(WEBAPK_PACKAGE_NAME) |
+ || packageName.equals(WEBAPK_WITH_NATIVE_APP_PACKAGE_NAME)) { |
+ return packageName; |
+ } |
+ } |
+ return null; |
} |
@Override |
@@ -950,7 +1059,7 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase { |
private boolean mIsRedirect; |
private boolean mChromeAppInForegroundRequired = true; |
private boolean mIsBackgroundTabNavigation; |
- private boolean mIsWebApk; |
+ private String mWebApkPackageName; |
private boolean mHasUserGesture; |
private TabRedirectHandler mRedirectHandler; |
@@ -958,8 +1067,8 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase { |
mUrl = url; |
} |
- public ExternalNavigationTestParams withIsWebApk(boolean isWebApk) { |
- mIsWebApk = isWebApk; |
+ public ExternalNavigationTestParams withWebApkPackageName(String webApkPackageName) { |
+ mWebApkPackageName = webApkPackageName; |
return this; |
} |
@@ -1009,8 +1118,9 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase { |
int otherExpectation) { |
boolean expectStartIncognito = (otherExpectation & START_INCOGNITO) != 0; |
boolean expectStartActivity = |
- (otherExpectation & (START_CHROME | START_OTHER_ACTIVITY)) != 0; |
+ (otherExpectation & (START_CHROME | START_WEBAPK | START_OTHER_ACTIVITY)) != 0; |
boolean expectStartChrome = (otherExpectation & START_CHROME) != 0; |
+ boolean expectStartWebApk = (otherExpectation & START_WEBAPK) != 0; |
boolean expectStartOtherActivity = (otherExpectation & START_OTHER_ACTIVITY) != 0; |
boolean expectStartFile = (otherExpectation & START_FILE) != 0; |
boolean expectSaneIntent = expectStartOtherActivity |
@@ -1025,23 +1135,28 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase { |
.setRedirectHandler(mRedirectHandler) |
.setIsBackgroundTabNavigation(mIsBackgroundTabNavigation) |
.setIsMainFrame(true) |
- .setIsWebApk(mIsWebApk) |
+ .setWebApkPackageName(mWebApkPackageName) |
.setHasUserGesture(mHasUserGesture) |
.build(); |
OverrideUrlLoadingResult result = mUrlHandler.shouldOverrideUrlLoading(params); |
boolean startActivityCalled = false; |
boolean startChromeCalled = false; |
+ boolean startWebApkCalled = false; |
if (mDelegate.startActivityIntent != null) { |
startActivityCalled = true; |
String packageName = mDelegate.startActivityIntent.getPackage(); |
- startChromeCalled = |
- packageName != null && packageName.equals(mDelegate.getPackageName()); |
+ if (packageName != null) { |
+ startChromeCalled = packageName.equals(mDelegate.getPackageName()); |
+ startWebApkCalled = |
+ packageName.startsWith(WebApkConstants.WEBAPK_PACKAGE_PREFIX); |
+ } |
} |
assertEquals(expectedOverrideResult, result); |
assertEquals(expectStartIncognito, mDelegate.startIncognitoIntentCalled); |
assertEquals(expectStartActivity, startActivityCalled); |
assertEquals(expectStartChrome, startChromeCalled); |
+ assertEquals(expectStartWebApk, startWebApkCalled); |
assertEquals(expectStartFile, mDelegate.startFileIntentCalled); |
if (startActivityCalled && expectSaneIntent) { |