Commit f69f5369 authored by Theresa Wellington's avatar Theresa Wellington Committed by Commit Bot

[Android] Hide bookmarks edit button until bookmarks fully loaded

We attempt to hide the bookmark edit button until the model is loaded,
but a call to show the normal menu group in
SelectableListToolbar#showNormalView() makes the edit icon visible
again. Override #showNormalView() in BookmarkActionBar and set the edit
icon to invisible until search delegate is set. Also adds a test to prevent
regressions.

BUG=778024

Change-Id: I4a4311358a7828587eb01adfab2b0a2baa3069db
Reviewed-on: https://chromium-review.googlesource.com/738316Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Theresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512329}
parent fc1ca454
......@@ -129,6 +129,16 @@ public class BookmarkActionBar extends SelectableListToolbar<BookmarkId>
getMenu().findItem(R.id.edit_menu_id).setVisible(false);
}
@Override
protected void showNormalView() {
super.showNormalView();
if (mDelegate == null) {
getMenu().findItem(R.id.search_menu_id).setVisible(false);
getMenu().findItem(R.id.edit_menu_id).setVisible(false);
}
}
// BookmarkUIObserver implementations.
@Override
......
......@@ -220,6 +220,7 @@ public class BookmarkTest {
openBookmarkManager();
BookmarkDelegate delegate =
((BookmarkItemsAdapter) mItemsContainer.getAdapter()).getDelegateForTesting();
Assert.assertEquals(BookmarkUIState.STATE_FOLDER, delegate.getCurrentState());
Assert.assertEquals("chrome-native://bookmarks/folder/3",
BookmarkUtils.getLastUsedUrl(mActivityTestRule.getActivity()));
......@@ -227,31 +228,43 @@ public class BookmarkTest {
@Test
@MediumTest
public void testTopLevelFolders() throws InterruptedException {
public void testFolderNavigation() throws InterruptedException, ExecutionException {
BookmarkId testFolder = addFolder(TEST_FOLDER_TITLE);
openBookmarkManager();
final BookmarkDelegate delegate =
((BookmarkItemsAdapter) mItemsContainer.getAdapter()).getDelegateForTesting();
final BookmarkActionBar toolbar = ((BookmarkManager) delegate).getToolbarForTests();
// Open the "Mobile bookmarks" folder.
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
delegate.openFolder(mBookmarkModel.getMobileFolderId());
}
});
ThreadUtils.runOnUiThreadBlocking(
() -> { delegate.openFolder(mBookmarkModel.getMobileFolderId()); });
// Check that we are in the mobile bookmarks folder.
Assert.assertEquals("Mobile bookmarks", toolbar.getTitle());
Assert.assertEquals(SelectableListToolbar.NAVIGATION_BUTTON_BACK,
toolbar.getNavigationButtonForTests());
Assert.assertFalse(toolbar.getMenu().findItem(R.id.edit_menu_id).isVisible());
// Open the new test folder.
ThreadUtils.runOnUiThreadBlocking(() -> { delegate.openFolder(testFolder); });
// Check that we are in the editable test folder.
Assert.assertEquals(TEST_FOLDER_TITLE, toolbar.getTitle());
Assert.assertEquals(SelectableListToolbar.NAVIGATION_BUTTON_BACK,
toolbar.getNavigationButtonForTests());
Assert.assertTrue(toolbar.getMenu().findItem(R.id.edit_menu_id).isVisible());
// Call BookmarkActionBar#onClick() to activate the navigation button.
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
toolbar.onClick(toolbar);
}
});
ThreadUtils.runOnUiThreadBlocking(() -> { toolbar.onClick(toolbar); });
// Check that we are back in the mobile folder
Assert.assertEquals("Mobile bookmarks", toolbar.getTitle());
Assert.assertEquals(SelectableListToolbar.NAVIGATION_BUTTON_BACK,
toolbar.getNavigationButtonForTests());
Assert.assertFalse(toolbar.getMenu().findItem(R.id.edit_menu_id).isVisible());
// Call BookmarkActionBar#onClick() to activate the navigation button.
ThreadUtils.runOnUiThreadBlocking(() -> { toolbar.onClick(toolbar); });
// Check that we are in the root folder.
Assert.assertEquals("Bookmarks", toolbar.getTitle());
......@@ -370,6 +383,20 @@ public class BookmarkTest {
BookmarkManager.preventLoadingForTesting(false);
}
@Test
@MediumTest
public void testEditHiddenWhileStillLoading() throws Exception {
BookmarkManager.preventLoadingForTesting(true);
openBookmarkManager();
final BookmarkActionBar toolbar =
mBookmarkActivity.getManagerForTesting().getToolbarForTests();
Assert.assertFalse(toolbar.getMenu().findItem(R.id.edit_menu_id).isVisible());
BookmarkManager.preventLoadingForTesting(false);
}
/**
* Asserts the number of bookmark items being shown, taking large device deviders into account.
*
......
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