Commit 7d8451ab authored by Bernhard Bauer's avatar Bernhard Bauer Committed by Commit Bot

Fix variable typo in CustomTabIntentDataProvider.getButtonParamsForId()

Also, get the correct child to update in
CustomTabToolbar.updateCustomActionButton().

Bug: b/73160522, 822277
Change-Id: Ia77234d6023a1049d506684bda3aaaa7e96cd405
Reviewed-on: https://chromium-review.googlesource.com/964444
Commit-Queue: Bernhard Bauer <bauerb@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543660}
parent 22f1175d
......@@ -484,7 +484,10 @@ public class CustomTabActivity extends ChromeActivity {
@Override
public boolean updateCustomButton(int id, Bitmap bitmap, String description) {
CustomButtonParams params = mIntentDataProvider.getButtonParamsForId(id);
if (params == null) return false;
if (params == null) {
Log.w(TAG, "Custom toolbar button with ID %d not found", id);
return false;
}
params.update(bitmap, description);
if (params.showOnToolbar()) {
......@@ -492,10 +495,7 @@ public class CustomTabActivity extends ChromeActivity {
return false;
}
int index = mIntentDataProvider.getCustomToolbarButtonIndexForId(id);
if (index == -1) {
Log.w(TAG, "Invalid ID for custom toolbar button: %s", id);
return false;
}
assert index != -1;
getToolbarManager().updateCustomActionButton(
index, params.getIcon(getResources()), description);
} else {
......
......@@ -411,7 +411,7 @@ public class CustomTabIntentDataProvider extends BrowserSessionDataProvider {
*/
public int getCustomToolbarButtonIndexForId(int id) {
for (int i = 0; i < mToolbarButtons.size(); i++) {
if (mToolbarButtons.get(i).getId() == i) return i;
if (mToolbarButtons.get(i).getId() == id) return i;
}
return -1;
}
......
......@@ -215,7 +215,8 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
@Override
public void updateCustomActionButton(int index, Drawable drawable, String description) {
ImageButton button = (ImageButton) mCustomActionButtons.getChildAt(index);
ImageButton button = (ImageButton) mCustomActionButtons.getChildAt(
mCustomActionButtons.getChildCount() - 1 - index);
assert button != null;
updateCustomActionButtonVisuals(button, drawable, description);
}
......
......@@ -126,6 +126,7 @@ import org.chromium.ui.mojom.WindowOpenDisposition;
import org.chromium.ui.test.util.UiRestriction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
......@@ -323,6 +324,14 @@ public class CustomTabActivityTest {
return bundle;
}
private Bundle makeUpdateVisualsBundle(int id, Bitmap icon, String description) {
Bundle bundle = new Bundle();
bundle.putInt(CustomTabsIntent.KEY_ID, id);
bundle.putParcelable(CustomTabsIntent.KEY_ICON, icon);
bundle.putString(CustomTabsIntent.KEY_DESCRIPTION, description);
return bundle;
}
private void openAppMenuAndAssertMenuShown() {
ThreadUtils.runOnUiThread(
(Runnable) () -> getActivity().onMenuOrKeyboardAction(R.id.show_menu, false));
......@@ -964,6 +973,18 @@ public class CustomTabActivityTest {
onFinished1.waitForCallback("Pending Intent was not sent.");
Assert.assertThat(onFinished1.getCallbackIntent().getDataString(), equalTo(mTestPage));
Assert.assertNull(onFinished2.getCallbackIntent());
CustomTabsConnection connection = CustomTabsConnection.getInstance();
int id = toolbarItems.get(0).getInt(CustomTabsIntent.KEY_ID);
Bundle updateActionButtonBundle =
makeUpdateVisualsBundle(id, expectedIcon2, "Bestest testest");
Bundle updateVisualsBundle = new Bundle();
updateVisualsBundle.putParcelableArrayList(CustomTabsIntent.EXTRA_TOOLBAR_ITEMS,
new ArrayList<>(Arrays.asList(updateActionButtonBundle)));
CustomTabsSessionToken token = CustomTabsSessionToken.getSessionTokenFromIntent(intent);
Assert.assertTrue(connection.updateVisuals(token, updateVisualsBundle));
Assert.assertEquals("Bestest testest", actionButton.getContentDescription());
}
/**
......
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