Commit 27a234f7 authored by Anna Malova's avatar Anna Malova Committed by Commit Bot

Close CCT when X button is pressed if dynamic module has not been loaded

because of failure.

Bug: 908484
Change-Id: I19d7c285f679bcce3a25b06c883f978b5c4e95cb
Reviewed-on: https://chromium-review.googlesource.com/c/1350978
Commit-Queue: Anna Malova <amalova@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611119}
parent ec2fc8ad
...@@ -345,11 +345,16 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent ...@@ -345,11 +345,16 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent
mModuleCallback = new LoadModuleCallback(); mModuleCallback = new LoadModuleCallback();
moduleLoader.addCallbackAndIncrementUseCount(mModuleCallback); moduleLoader.addCallbackAndIncrementUseCount(mModuleCallback);
getComponent().resolveCloseButtonNavigator() getComponent().resolveCloseButtonNavigator().setLandingPageCriteria(url ->
.setLandingPageCriteria(this::isModuleManagedUrl); (isModuleLoading() || isModuleLoaded()) && isModuleManagedUrl(url));
} }
private boolean isModuleLoading() { private boolean isModuleLoaded() {
return mModuleActivityDelegate != null;
}
@VisibleForTesting
public boolean isModuleLoading() {
return mModuleCallback != null; return mModuleCallback != null;
} }
...@@ -360,6 +365,8 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent ...@@ -360,6 +365,8 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent
private class LoadModuleCallback implements Callback<ModuleEntryPoint> { private class LoadModuleCallback implements Callback<ModuleEntryPoint> {
@Override @Override
public void onResult(@Nullable ModuleEntryPoint entryPoint) { public void onResult(@Nullable ModuleEntryPoint entryPoint) {
mModuleCallback = null;
if (entryPoint == null) return; if (entryPoint == null) return;
mModuleEntryPoint = entryPoint; mModuleEntryPoint = entryPoint;
...@@ -375,7 +382,6 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent ...@@ -375,7 +382,6 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent
mConnection.setActivityDelegateForSession(mSession, mModuleActivityDelegate, mConnection.setActivityDelegateForSession(mSession, mModuleActivityDelegate,
mModuleEntryPoint.getModuleVersion()); mModuleEntryPoint.getModuleVersion());
mModuleCallback = null;
// Initialise the PostMessageHandler for the current web contents. // Initialise the PostMessageHandler for the current web contents.
maybeInitialiseDynamicModulePostMessageHandler( maybeInitialiseDynamicModulePostMessageHandler(
......
...@@ -1238,6 +1238,49 @@ public class CustomTabActivityTest { ...@@ -1238,6 +1238,49 @@ public class CustomTabActivityTest {
ClickUtils.clickButton(cctActivity.findViewById(R.id.close_button))); ClickUtils.clickButton(cctActivity.findViewById(R.id.close_button)));
} }
/**
This test executes the following workflow assuming dynamic module loading fails:
- moduleManagedUrl1 -> nav1.1 - nav1.2
- User hits the close button, thereby closes CCT
*/
@Test
@SmallTest
public void testCloseButtonBehaviourDynamicModuleLoadFails()
throws InterruptedException, ExecutionException, TimeoutException {
String moduleManagedUrl = mTestServer.getURL(
"/chrome/test/data/android/about.html");
// Open CCT with moduleManagedUrl1 and navigate
// moduleManagedUrl1 -> nav1.1 - nav1.2
// Make an intent with nonexistent class name so module loading fails.
ComponentName componentName =
new ComponentName(CustomTabsDynamicModuleTestUtils.FAKE_MODULE_PACKAGE_NAME,
"ClassName");
Intent intent = CustomTabsDynamicModuleTestUtils.makeDynamicModuleIntent(
componentName, moduleManagedUrl, "^" + moduleManagedUrl+ "$");
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(intent);
CustomTabActivity cctActivity = mCustomTabActivityTestRule.getActivity();
// Wait until ModuleLoader tries to load a module.
CriteriaHelper.pollUiThread(new Criteria() {
@Override
public boolean isSatisfied() {
return !cctActivity.isModuleLoading();
}
});
mCustomTabActivityTestRule.loadUrlInTab(mTestPage, PageTransition.LINK,
cctActivity.getActivityTab());
mCustomTabActivityTestRule.loadUrlInTab(mTestPage2, PageTransition.LINK,
cctActivity.getActivityTab());
// click close button and wait while cct is hidden
runAndWaitForActivityStopped(() ->
ClickUtils.clickButton(cctActivity.findViewById(R.id.close_button)));
}
@Test @Test
@SmallTest @SmallTest
@RetryOnFailure @RetryOnFailure
......
...@@ -155,13 +155,24 @@ public class CustomTabsDynamicModuleTestUtils { ...@@ -155,13 +155,24 @@ public class CustomTabsDynamicModuleTestUtils {
/** /**
* Creates the simplest intent that is sufficient to let {@link ChromeLauncherActivity} launch * Creates the simplest intent that is sufficient to let {@link ChromeLauncherActivity} launch
* the {@link CustomTabActivity} with dynamic module. * the {@link CustomTabActivity} with fake dynamic module.
*
* @see #makeDynamicModuleIntent(ComponentName, String, String)
*/ */
public static Intent makeDynamicModuleIntent(String url, @Nullable String managedUrlsRegex) { public static Intent makeDynamicModuleIntent(String url, @Nullable String managedUrlsRegex) {
return makeDynamicModuleIntent(FAKE_MODULE_COMPONENT_NAME, url, managedUrlsRegex);
}
/**
* Creates the simplest intent that is sufficient to let {@link ChromeLauncherActivity} launch
* the {@link CustomTabActivity} with dynamic module.
*/
public static Intent makeDynamicModuleIntent(
ComponentName componentName, String url, @Nullable String managedUrlsRegex) {
Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent( Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(
InstrumentationRegistry.getTargetContext(), url); InstrumentationRegistry.getTargetContext(), url);
intent.putExtra(EXTRA_MODULE_PACKAGE_NAME, FAKE_MODULE_PACKAGE_NAME); intent.putExtra(EXTRA_MODULE_PACKAGE_NAME, componentName.getPackageName());
intent.putExtra(EXTRA_MODULE_CLASS_NAME, FAKE_MODULE_CLASS_NAME); intent.putExtra(EXTRA_MODULE_CLASS_NAME, componentName.getClassName());
if (managedUrlsRegex != null) { if (managedUrlsRegex != null) {
intent.putExtra(CustomTabIntentDataProvider.EXTRA_MODULE_MANAGED_URLS_REGEX, intent.putExtra(CustomTabIntentDataProvider.EXTRA_MODULE_MANAGED_URLS_REGEX,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment