Commit 34ec1547 authored by Side Yilmaz's avatar Side Yilmaz Committed by Commit Bot

Add title visibility option to Incognito CCT.

This CL gives ability to Incognito CCT to show title on toolbar.

For screenshot:
https://drive.google.com/file/d/1WQFhK3yhVsF-OazSSrUh9d8mfpNb1ZeK

Bug: 1104180
Change-Id: I195ba2200d0994bb0aea5f06ce017ec81172e2a6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2537677
Commit-Queue: Side YILMAZ <sideyilmaz@chromium.org>
Reviewed-by: default avatarRohit Agarwal <roagarwal@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828235}
parent 9896ae77
...@@ -54,6 +54,7 @@ public class IncognitoCustomTabIntentDataProvider extends BrowserServicesIntentD ...@@ -54,6 +54,7 @@ public class IncognitoCustomTabIntentDataProvider extends BrowserServicesIntentD
private final int mToolbarColor; private final int mToolbarColor;
private final int mBottomBarColor; private final int mBottomBarColor;
private final int mNavigationBarColor; private final int mNavigationBarColor;
private final int mTitleVisibilityState;
private final Drawable mCloseButtonIcon; private final Drawable mCloseButtonIcon;
private final boolean mShowShareItem; private final boolean mShowShareItem;
private final List<Pair<String, PendingIntent>> mMenuEntries = new ArrayList<>(); private final List<Pair<String, PendingIntent>> mMenuEntries = new ArrayList<>();
...@@ -89,6 +90,8 @@ public class IncognitoCustomTabIntentDataProvider extends BrowserServicesIntentD ...@@ -89,6 +90,8 @@ public class IncognitoCustomTabIntentDataProvider extends BrowserServicesIntentD
mCloseButtonIcon = TintedDrawable.constructTintedDrawable(context, R.drawable.btn_close); mCloseButtonIcon = TintedDrawable.constructTintedDrawable(context, R.drawable.btn_close);
mShowShareItem = IntentUtils.safeGetBooleanExtra( mShowShareItem = IntentUtils.safeGetBooleanExtra(
intent, CustomTabsIntent.EXTRA_DEFAULT_SHARE_MENU_ITEM, false); intent, CustomTabsIntent.EXTRA_DEFAULT_SHARE_MENU_ITEM, false);
mTitleVisibilityState = IntentUtils.safeGetIntExtra(
intent, CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.NO_TITLE);
mUiType = getUiType(intent); mUiType = getUiType(intent);
updateExtraMenuItemsIfNecessary(intent); updateExtraMenuItemsIfNecessary(intent);
...@@ -255,6 +258,11 @@ public class IncognitoCustomTabIntentDataProvider extends BrowserServicesIntentD ...@@ -255,6 +258,11 @@ public class IncognitoCustomTabIntentDataProvider extends BrowserServicesIntentD
return mNavigationBarColor; return mNavigationBarColor;
} }
@Override
public int getTitleVisibilityState() {
return mTitleVisibilityState;
}
@Override @Override
public boolean isOpenedByChrome() { public boolean isOpenedByChrome() {
return mIsOpenedByChrome; return mIsOpenedByChrome;
......
...@@ -32,6 +32,7 @@ import android.view.MenuItem; ...@@ -32,6 +32,7 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import android.widget.TextView;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.content.res.AppCompatResources;
...@@ -125,6 +126,15 @@ public class CustomTabActivityIncognitoTest { ...@@ -125,6 +126,15 @@ public class CustomTabActivityIncognitoTest {
}); });
} }
private static boolean getTitleBarVisibility(CustomTabActivity activity)
throws ExecutionException {
return TestThreadUtils.runOnUiThreadBlocking(() -> {
CustomTabToolbar toolbar = activity.findViewById(R.id.toolbar);
TextView titleBar = toolbar.findViewById(R.id.title_bar);
return titleBar.getVisibility() == View.VISIBLE;
});
}
private void launchMenuItem() throws Exception { private void launchMenuItem() throws Exception {
Intent intent = createMinimalIncognitoCustomTabIntent(); Intent intent = createMinimalIncognitoCustomTabIntent();
CustomTabActivity activity = launchIncognitoCustomTab(intent); CustomTabActivity activity = launchIncognitoCustomTab(intent);
...@@ -390,4 +400,15 @@ public class CustomTabActivityIncognitoTest { ...@@ -390,4 +400,15 @@ public class CustomTabActivityIncognitoTest {
View bottomBarView = mCustomTabActivityTestRule.getActivity().findViewById(R.id.bottom_bar); View bottomBarView = mCustomTabActivityTestRule.getActivity().findViewById(R.id.bottom_bar);
assertTrue(bottomBarView == null); assertTrue(bottomBarView == null);
} }
@Test
@MediumTest
@Features.EnableFeatures({ChromeFeatureList.CCT_INCOGNITO})
public void ensureTitleBarIsVisibile() throws Exception {
Intent intent = createMinimalIncognitoCustomTabIntent();
intent.putExtra(
CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.SHOW_PAGE_TITLE);
CustomTabActivity activity = launchIncognitoCustomTab(intent);
Assert.assertTrue(getTitleBarVisibility(activity));
} }
}
...@@ -4,12 +4,19 @@ ...@@ -4,12 +4,19 @@
package org.chromium.chrome.browser.customtabs; package org.chromium.chrome.browser.customtabs;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.chromium.chrome.test.util.ViewUtils.waitForView;
import android.content.Intent; import android.content.Intent;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.view.View; import android.view.View;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.test.filters.MediumTest; import androidx.test.filters.MediumTest;
import org.junit.Before; import org.junit.Before;
...@@ -27,6 +34,7 @@ import org.chromium.chrome.browser.flags.ChromeFeatureList; ...@@ -27,6 +34,7 @@ import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.incognito.IncognitoDataTestUtils; import org.chromium.chrome.browser.incognito.IncognitoDataTestUtils;
import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate; import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate;
import org.chromium.chrome.test.util.ViewUtils;
import org.chromium.chrome.test.util.browser.Features; import org.chromium.chrome.test.util.browser.Features;
import org.chromium.net.test.EmbeddedTestServerRule; import org.chromium.net.test.EmbeddedTestServerRule;
import org.chromium.ui.test.util.RenderTestRule; import org.chromium.ui.test.util.RenderTestRule;
...@@ -92,10 +100,27 @@ public class IncognitoCustomTabActivityRenderTest { ...@@ -92,10 +100,27 @@ public class IncognitoCustomTabActivityRenderTest {
mRenderTestRule.render(toolbarView, renderTestId); mRenderTestRule.render(toolbarView, renderTestId);
} }
private void startActivityWithTitle(String renderTestId) throws IOException {
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(mIntent);
View toolbarView = mCustomTabActivityTestRule.getActivity().findViewById(R.id.toolbar);
onView(isRoot()).check(waitForView(withId(R.id.title_bar), ViewUtils.VIEW_VISIBLE));
mRenderTestRule.render(toolbarView, renderTestId);
}
@Test @Test
@MediumTest @MediumTest
@Feature("RenderTest") @Feature("RenderTest")
public void testCCTToolbar() throws IOException { public void testCCTToolbar() throws IOException {
startActivity("default_incognito_cct_toolbar_with_https_" + mRunWithHttps); startActivity("default_incognito_cct_toolbar_with_https_" + mRunWithHttps);
} }
@Test
@MediumTest
@Feature("RenderTest")
public void testCCTTitleBar() throws IOException {
mIntent.putExtra(
CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.SHOW_PAGE_TITLE);
startActivityWithTitle(
"default_incognito_cct_toolbar_with_title_bar_and_with_https_" + mRunWithHttps);
}
} }
\ No newline at end of file
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