| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.bookmarks; | 5 package org.chromium.chrome.browser.bookmarks; |
| 6 | 6 |
| 7 import android.support.test.InstrumentationRegistry; |
| 7 import android.support.test.filters.MediumTest; | 8 import android.support.test.filters.MediumTest; |
| 8 import android.support.test.filters.SmallTest; | 9 import android.support.test.filters.SmallTest; |
| 9 import android.support.v7.widget.RecyclerView; | 10 import android.support.v7.widget.RecyclerView; |
| 10 import android.support.v7.widget.RecyclerView.Adapter; | 11 import android.support.v7.widget.RecyclerView.Adapter; |
| 11 import android.text.TextUtils; | 12 import android.text.TextUtils; |
| 12 import android.view.View; | 13 import android.view.View; |
| 13 import android.view.ViewGroup; | 14 import android.view.ViewGroup; |
| 14 import android.widget.TextView; | 15 import android.widget.TextView; |
| 15 | 16 |
| 16 import junit.framework.Assert; | 17 import org.junit.After; |
| 18 import org.junit.Assert; |
| 19 import org.junit.Before; |
| 20 import org.junit.Rule; |
| 21 import org.junit.Test; |
| 22 import org.junit.runner.RunWith; |
| 17 | 23 |
| 18 import org.chromium.base.ThreadUtils; | 24 import org.chromium.base.ThreadUtils; |
| 25 import org.chromium.base.test.util.CommandLineFlags; |
| 19 import org.chromium.base.test.util.RetryOnFailure; | 26 import org.chromium.base.test.util.RetryOnFailure; |
| 20 import org.chromium.chrome.R; | 27 import org.chromium.chrome.R; |
| 21 import org.chromium.chrome.browser.ChromeActivity; | 28 import org.chromium.chrome.browser.ChromeActivity; |
| 29 import org.chromium.chrome.browser.ChromeSwitches; |
| 22 import org.chromium.chrome.browser.UrlConstants; | 30 import org.chromium.chrome.browser.UrlConstants; |
| 23 import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem; | 31 import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem; |
| 24 import org.chromium.chrome.browser.widget.selection.SelectableListToolbar; | 32 import org.chromium.chrome.browser.widget.selection.SelectableListToolbar; |
| 25 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 33 import org.chromium.chrome.test.ChromeActivityTestRule; |
| 34 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
| 26 import org.chromium.chrome.test.util.ActivityUtils; | 35 import org.chromium.chrome.test.util.ActivityUtils; |
| 27 import org.chromium.chrome.test.util.BookmarkTestUtil; | 36 import org.chromium.chrome.test.util.BookmarkTestUtil; |
| 28 import org.chromium.chrome.test.util.ChromeTabUtils; | 37 import org.chromium.chrome.test.util.ChromeTabUtils; |
| 29 import org.chromium.chrome.test.util.MenuUtils; | 38 import org.chromium.chrome.test.util.MenuUtils; |
| 30 import org.chromium.components.bookmarks.BookmarkId; | 39 import org.chromium.components.bookmarks.BookmarkId; |
| 31 import org.chromium.components.bookmarks.BookmarkType; | 40 import org.chromium.components.bookmarks.BookmarkType; |
| 32 import org.chromium.content.browser.test.util.TouchCommon; | 41 import org.chromium.content.browser.test.util.TouchCommon; |
| 33 import org.chromium.net.test.EmbeddedTestServer; | 42 import org.chromium.net.test.EmbeddedTestServer; |
| 34 import org.chromium.ui.base.DeviceFormFactor; | 43 import org.chromium.ui.base.DeviceFormFactor; |
| 35 | 44 |
| 36 import java.util.ArrayList; | 45 import java.util.ArrayList; |
| 37 import java.util.concurrent.Callable; | 46 import java.util.concurrent.Callable; |
| 38 import java.util.concurrent.ExecutionException; | 47 import java.util.concurrent.ExecutionException; |
| 39 | 48 |
| 40 /** | 49 /** |
| 41 * Tests for the bookmark manager. | 50 * Tests for the bookmark manager. |
| 42 */ | 51 */ |
| 52 @RunWith(ChromeJUnit4ClassRunner.class) |
| 53 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
| 54 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
| 43 @RetryOnFailure | 55 @RetryOnFailure |
| 44 public class BookmarkTest extends ChromeActivityTestCaseBase<ChromeActivity> { | 56 public class BookmarkTest { |
| 45 | 57 @Rule |
| 46 public BookmarkTest() { | 58 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = |
| 47 super(ChromeActivity.class); | 59 new ChromeActivityTestRule<>(ChromeActivity.class); |
| 48 } | |
| 49 | 60 |
| 50 private static final String TEST_PAGE_URL_GOOGLE = "/chrome/test/data/androi
d/google.html"; | 61 private static final String TEST_PAGE_URL_GOOGLE = "/chrome/test/data/androi
d/google.html"; |
| 51 private static final String TEST_PAGE_TITLE_GOOGLE = "The Google"; | 62 private static final String TEST_PAGE_TITLE_GOOGLE = "The Google"; |
| 52 private static final String TEST_PAGE_TITLE_GOOGLE2 = "Google"; | 63 private static final String TEST_PAGE_TITLE_GOOGLE2 = "Google"; |
| 53 private static final String TEST_PAGE_URL_FOO = "/chrome/test/data/android/t
est.html"; | 64 private static final String TEST_PAGE_URL_FOO = "/chrome/test/data/android/t
est.html"; |
| 54 private static final String TEST_PAGE_TITLE_FOO = "Foo"; | 65 private static final String TEST_PAGE_TITLE_FOO = "Foo"; |
| 55 | 66 |
| 56 private BookmarkModel mBookmarkModel; | 67 private BookmarkModel mBookmarkModel; |
| 57 protected RecyclerView mItemsContainer; | 68 protected RecyclerView mItemsContainer; |
| 58 private String mTestPage; | 69 private String mTestPage; |
| 59 private String mTestPageFoo; | 70 private String mTestPageFoo; |
| 60 private EmbeddedTestServer mTestServer; | 71 private EmbeddedTestServer mTestServer; |
| 61 | 72 |
| 62 @Override | 73 @Before |
| 63 protected void setUp() throws Exception { | 74 public void setUp() throws Exception { |
| 64 super.setUp(); | 75 mActivityTestRule.startMainActivityFromLauncher(); |
| 65 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation
().getContext()); | 76 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 77 @Override |
| 78 public void run() { |
| 79 mBookmarkModel = new BookmarkModel( |
| 80 mActivityTestRule.getActivity().getActivityTab().getProf
ile()); |
| 81 } |
| 82 }); |
| 83 BookmarkTestUtil.waitForBookmarkModelLoaded(); |
| 84 mTestServer = EmbeddedTestServer.createAndStartServer( |
| 85 InstrumentationRegistry.getInstrumentation().getContext()); |
| 66 mTestPage = mTestServer.getURL(TEST_PAGE_URL_GOOGLE); | 86 mTestPage = mTestServer.getURL(TEST_PAGE_URL_GOOGLE); |
| 67 mTestPageFoo = mTestServer.getURL(TEST_PAGE_URL_FOO); | 87 mTestPageFoo = mTestServer.getURL(TEST_PAGE_URL_FOO); |
| 68 } | 88 } |
| 69 | 89 |
| 70 @Override | 90 @After |
| 71 protected void tearDown() throws Exception { | 91 public void tearDown() throws Exception { |
| 72 mTestServer.stopAndDestroyServer(); | 92 if (mTestServer != null) { |
| 73 super.tearDown(); | 93 mTestServer.stopAndDestroyServer(); |
| 74 } | 94 } |
| 75 | |
| 76 @Override | |
| 77 public void startMainActivity() throws InterruptedException { | |
| 78 startMainActivityFromLauncher(); | |
| 79 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
| 80 @Override | |
| 81 public void run() { | |
| 82 mBookmarkModel = new BookmarkModel(getActivity().getActivityTab(
).getProfile()); | |
| 83 } | |
| 84 }); | |
| 85 BookmarkTestUtil.waitForBookmarkModelLoaded(); | |
| 86 } | 95 } |
| 87 | 96 |
| 88 private void openBookmarkManager() throws InterruptedException { | 97 private void openBookmarkManager() throws InterruptedException { |
| 89 if (DeviceFormFactor.isTablet(getActivity())) { | 98 if (DeviceFormFactor.isTablet(mActivityTestRule.getActivity())) { |
| 90 loadUrl(UrlConstants.BOOKMARKS_URL); | 99 mActivityTestRule.loadUrl(UrlConstants.BOOKMARKS_URL); |
| 91 mItemsContainer = (RecyclerView) getActivity().findViewById(R.id.rec
ycler_view); | 100 mItemsContainer = |
| 101 (RecyclerView) mActivityTestRule.getActivity().findViewById(
R.id.recycler_view); |
| 92 } else { | 102 } else { |
| 93 // phone | 103 // phone |
| 94 BookmarkActivity activity = ActivityUtils.waitForActivity(getInstrum
entation(), | 104 BookmarkActivity activity = ActivityUtils.waitForActivity( |
| 95 BookmarkActivity.class, new MenuUtils.MenuActivityTrigger( | 105 InstrumentationRegistry.getInstrumentation(), BookmarkActivi
ty.class, |
| 96 getInstrumentation(), getActivity(), R.id.all_bookma
rks_menu_id)); | 106 new MenuUtils.MenuActivityTrigger(InstrumentationRegistry.ge
tInstrumentation(), |
| 107 mActivityTestRule.getActivity(), R.id.all_bookmarks_
menu_id)); |
| 97 mItemsContainer = (RecyclerView) activity.findViewById(R.id.recycler
_view); | 108 mItemsContainer = (RecyclerView) activity.findViewById(R.id.recycler
_view); |
| 98 } | 109 } |
| 99 } | 110 } |
| 100 | 111 |
| 101 private boolean isItemPresentInBookmarkList(final String expectedTitle) { | 112 private boolean isItemPresentInBookmarkList(final String expectedTitle) { |
| 102 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean
>() { | 113 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean
>() { |
| 103 @Override | 114 @Override |
| 104 public Boolean call() throws Exception { | 115 public Boolean call() throws Exception { |
| 105 for (int i = 0; i < mItemsContainer.getAdapter().getItemCount();
i++) { | 116 for (int i = 0; i < mItemsContainer.getAdapter().getItemCount();
i++) { |
| 106 BookmarkId item = | 117 BookmarkId item = |
| 107 ((BookmarkItemsAdapter) mItemsContainer.getAdapter()
).getItem(i); | 118 ((BookmarkItemsAdapter) mItemsContainer.getAdapter()
).getItem(i); |
| 108 if (item == null) continue; | 119 if (item == null) continue; |
| 109 | 120 |
| 110 String actualTitle = mBookmarkModel.getBookmarkTitle(item); | 121 String actualTitle = mBookmarkModel.getBookmarkTitle(item); |
| 111 if (TextUtils.equals(actualTitle, expectedTitle)) { | 122 if (TextUtils.equals(actualTitle, expectedTitle)) { |
| 112 return true; | 123 return true; |
| 113 } | 124 } |
| 114 } | 125 } |
| 115 return false; | 126 return false; |
| 116 } | 127 } |
| 117 }); | 128 }); |
| 118 } | 129 } |
| 119 | 130 |
| 131 @Test |
| 120 @SmallTest | 132 @SmallTest |
| 121 public void testAddBookmark() throws InterruptedException { | 133 public void testAddBookmark() throws InterruptedException { |
| 122 loadUrl(mTestPage); | 134 mActivityTestRule.loadUrl(mTestPage); |
| 123 // Click star button to bookmark the curent tab. | 135 // Click star button to bookmark the curent tab. |
| 124 MenuUtils.invokeCustomMenuActionSync(getInstrumentation(), getActivity()
, | 136 MenuUtils.invokeCustomMenuActionSync(InstrumentationRegistry.getInstrume
ntation(), |
| 125 R.id.bookmark_this_page_id); | 137 mActivityTestRule.getActivity(), R.id.bookmark_this_page_id); |
| 126 // All actions with BookmarkModel needs to run on UI thread. | 138 // All actions with BookmarkModel needs to run on UI thread. |
| 127 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 139 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 128 @Override | 140 @Override |
| 129 public void run() { | 141 public void run() { |
| 130 long bookmarkIdLong = getActivity().getActivityTab().getUserBook
markId(); | 142 long bookmarkIdLong = |
| 143 mActivityTestRule.getActivity().getActivityTab().getUser
BookmarkId(); |
| 131 BookmarkId id = new BookmarkId(bookmarkIdLong, BookmarkType.NORM
AL); | 144 BookmarkId id = new BookmarkId(bookmarkIdLong, BookmarkType.NORM
AL); |
| 132 assertTrue("The test page is not added as bookmark: ", | 145 Assert.assertTrue("The test page is not added as bookmark: ", |
| 133 mBookmarkModel.doesBookmarkExist(id)); | 146 mBookmarkModel.doesBookmarkExist(id)); |
| 134 BookmarkItem item = mBookmarkModel.getBookmarkById(id); | 147 BookmarkItem item = mBookmarkModel.getBookmarkById(id); |
| 135 assertEquals(mBookmarkModel.getDefaultFolder(), item.getParentId
()); | 148 Assert.assertEquals(mBookmarkModel.getDefaultFolder(), item.getP
arentId()); |
| 136 assertEquals(mTestPage, item.getUrl()); | 149 Assert.assertEquals(mTestPage, item.getUrl()); |
| 137 assertEquals(TEST_PAGE_TITLE_GOOGLE, item.getTitle()); | 150 Assert.assertEquals(TEST_PAGE_TITLE_GOOGLE, item.getTitle()); |
| 138 } | 151 } |
| 139 }); | 152 }); |
| 140 } | 153 } |
| 141 | 154 |
| 155 @Test |
| 142 @SmallTest | 156 @SmallTest |
| 143 public void testOpenBookmark() throws InterruptedException, ExecutionExcepti
on { | 157 public void testOpenBookmark() throws InterruptedException, ExecutionExcepti
on { |
| 144 addBookmark(TEST_PAGE_TITLE_GOOGLE, mTestPage); | 158 addBookmark(TEST_PAGE_TITLE_GOOGLE, mTestPage); |
| 145 openBookmarkManager(); | 159 openBookmarkManager(); |
| 146 assertTrue("Grid view does not contain added bookmark: ", | 160 Assert.assertTrue("Grid view does not contain added bookmark: ", |
| 147 isItemPresentInBookmarkList(TEST_PAGE_TITLE_GOOGLE)); | 161 isItemPresentInBookmarkList(TEST_PAGE_TITLE_GOOGLE)); |
| 148 final View tile = getViewWithText(mItemsContainer, TEST_PAGE_TITLE_GOOGL
E); | 162 final View tile = getViewWithText(mItemsContainer, TEST_PAGE_TITLE_GOOGL
E); |
| 149 ChromeTabUtils.waitForTabPageLoaded(getActivity().getActivityTab(), new
Runnable() { | 163 ChromeTabUtils.waitForTabPageLoaded( |
| 150 @Override | 164 mActivityTestRule.getActivity().getActivityTab(), new Runnable()
{ |
| 151 public void run() { | 165 @Override |
| 152 TouchCommon.singleClickView(tile); | 166 public void run() { |
| 153 } | 167 TouchCommon.singleClickView(tile); |
| 154 }); | 168 } |
| 155 assertEquals(TEST_PAGE_TITLE_GOOGLE, getActivity().getActivityTab().getT
itle()); | 169 }); |
| 170 Assert.assertEquals(TEST_PAGE_TITLE_GOOGLE, |
| 171 mActivityTestRule.getActivity().getActivityTab().getTitle()); |
| 156 } | 172 } |
| 157 | 173 |
| 174 @Test |
| 158 @SmallTest | 175 @SmallTest |
| 159 public void testUrlComposition() { | 176 public void testUrlComposition() { |
| 160 BookmarkId mobileId = mBookmarkModel.getMobileFolderId(); | 177 BookmarkId mobileId = mBookmarkModel.getMobileFolderId(); |
| 161 BookmarkId bookmarkBarId = mBookmarkModel.getDesktopFolderId(); | 178 BookmarkId bookmarkBarId = mBookmarkModel.getDesktopFolderId(); |
| 162 BookmarkId otherId = mBookmarkModel.getOtherFolderId(); | 179 BookmarkId otherId = mBookmarkModel.getOtherFolderId(); |
| 163 assertEquals("chrome-native://bookmarks/folder/" + mobileId, | 180 Assert.assertEquals("chrome-native://bookmarks/folder/" + mobileId, |
| 164 BookmarkUIState.createFolderUrl(mobileId).toString()); | 181 BookmarkUIState.createFolderUrl(mobileId).toString()); |
| 165 assertEquals("chrome-native://bookmarks/folder/" + bookmarkBarId, | 182 Assert.assertEquals("chrome-native://bookmarks/folder/" + bookmarkBarId, |
| 166 BookmarkUIState.createFolderUrl(bookmarkBarId).toString()); | 183 BookmarkUIState.createFolderUrl(bookmarkBarId).toString()); |
| 167 assertEquals("chrome-native://bookmarks/folder/" + otherId, | 184 Assert.assertEquals("chrome-native://bookmarks/folder/" + otherId, |
| 168 BookmarkUIState.createFolderUrl(otherId).toString()); | 185 BookmarkUIState.createFolderUrl(otherId).toString()); |
| 169 } | 186 } |
| 170 | 187 |
| 188 @Test |
| 171 @SmallTest | 189 @SmallTest |
| 172 public void testOpenBookmarkManager() throws InterruptedException { | 190 public void testOpenBookmarkManager() throws InterruptedException { |
| 173 openBookmarkManager(); | 191 openBookmarkManager(); |
| 174 BookmarkDelegate delegate = | 192 BookmarkDelegate delegate = |
| 175 ((BookmarkItemsAdapter) mItemsContainer.getAdapter()).getDelegat
eForTesting(); | 193 ((BookmarkItemsAdapter) mItemsContainer.getAdapter()).getDelegat
eForTesting(); |
| 176 assertEquals(BookmarkUIState.STATE_FOLDER, delegate.getCurrentState()); | 194 Assert.assertEquals(BookmarkUIState.STATE_FOLDER, delegate.getCurrentSta
te()); |
| 177 assertEquals("chrome-native://bookmarks/folder/3", | 195 Assert.assertEquals("chrome-native://bookmarks/folder/3", |
| 178 BookmarkUtils.getLastUsedUrl(getActivity())); | 196 BookmarkUtils.getLastUsedUrl(mActivityTestRule.getActivity())); |
| 179 } | 197 } |
| 180 | 198 |
| 199 @Test |
| 181 @MediumTest | 200 @MediumTest |
| 182 public void testTopLevelFolders() throws InterruptedException { | 201 public void testTopLevelFolders() throws InterruptedException { |
| 183 openBookmarkManager(); | 202 openBookmarkManager(); |
| 184 final BookmarkDelegate delegate = | 203 final BookmarkDelegate delegate = |
| 185 ((BookmarkItemsAdapter) mItemsContainer.getAdapter()).getDelegat
eForTesting(); | 204 ((BookmarkItemsAdapter) mItemsContainer.getAdapter()).getDelegat
eForTesting(); |
| 186 final BookmarkActionBar toolbar = ((BookmarkManager) delegate).getToolba
rForTests(); | 205 final BookmarkActionBar toolbar = ((BookmarkManager) delegate).getToolba
rForTests(); |
| 187 | 206 |
| 188 // Open the "Mobile bookmarks" folder. | 207 // Open the "Mobile bookmarks" folder. |
| 189 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 208 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 190 @Override | 209 @Override |
| 191 public void run() { | 210 public void run() { |
| 192 delegate.openFolder(mBookmarkModel.getMobileFolderId()); | 211 delegate.openFolder(mBookmarkModel.getMobileFolderId()); |
| 193 } | 212 } |
| 194 }); | 213 }); |
| 195 | 214 |
| 196 assertEquals(SelectableListToolbar.NAVIGATION_BUTTON_BACK, | 215 Assert.assertEquals(SelectableListToolbar.NAVIGATION_BUTTON_BACK, |
| 197 toolbar.getNavigationButtonForTests()); | 216 toolbar.getNavigationButtonForTests()); |
| 198 assertFalse(toolbar.getMenu().findItem(R.id.edit_menu_id).isVisible()); | 217 Assert.assertFalse(toolbar.getMenu().findItem(R.id.edit_menu_id).isVisib
le()); |
| 199 | 218 |
| 200 // Call BookmarkActionBar#onClick() to activate the navigation button. | 219 // Call BookmarkActionBar#onClick() to activate the navigation button. |
| 201 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 220 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 202 @Override | 221 @Override |
| 203 public void run() { | 222 public void run() { |
| 204 toolbar.onClick(toolbar); | 223 toolbar.onClick(toolbar); |
| 205 } | 224 } |
| 206 }); | 225 }); |
| 207 | 226 |
| 208 // Check that we are in the root folder. | 227 // Check that we are in the root folder. |
| 209 assertEquals("Bookmarks", toolbar.getTitle()); | 228 Assert.assertEquals("Bookmarks", toolbar.getTitle()); |
| 210 assertEquals(SelectableListToolbar.NAVIGATION_BUTTON_NONE, | 229 Assert.assertEquals(SelectableListToolbar.NAVIGATION_BUTTON_NONE, |
| 211 toolbar.getNavigationButtonForTests()); | 230 toolbar.getNavigationButtonForTests()); |
| 212 assertFalse(toolbar.getMenu().findItem(R.id.edit_menu_id).isVisible()); | 231 Assert.assertFalse(toolbar.getMenu().findItem(R.id.edit_menu_id).isVisib
le()); |
| 213 } | 232 } |
| 214 | 233 |
| 234 @Test |
| 215 @MediumTest | 235 @MediumTest |
| 216 public void testSearchBookmarks() throws Exception { | 236 public void testSearchBookmarks() throws Exception { |
| 217 BookmarkPromoHeader.setShouldShowForTests(); | 237 BookmarkPromoHeader.setShouldShowForTests(); |
| 218 addBookmark(TEST_PAGE_TITLE_GOOGLE, mTestPage); | 238 addBookmark(TEST_PAGE_TITLE_GOOGLE, mTestPage); |
| 219 addBookmark(TEST_PAGE_TITLE_FOO, mTestPageFoo); | 239 addBookmark(TEST_PAGE_TITLE_FOO, mTestPageFoo); |
| 220 openBookmarkManager(); | 240 openBookmarkManager(); |
| 221 | 241 |
| 222 BookmarkItemsAdapter adapter = ((BookmarkItemsAdapter) mItemsContainer.g
etAdapter()); | 242 BookmarkItemsAdapter adapter = ((BookmarkItemsAdapter) mItemsContainer.g
etAdapter()); |
| 223 final BookmarkDelegate delegate = adapter.getDelegateForTesting(); | 243 final BookmarkDelegate delegate = adapter.getDelegateForTesting(); |
| 224 | 244 |
| 225 assertEquals(BookmarkUIState.STATE_FOLDER, delegate.getCurrentState()); | 245 Assert.assertEquals(BookmarkUIState.STATE_FOLDER, delegate.getCurrentSta
te()); |
| 226 assertBookmarkItems("Wrong number of items before starting search.", 3,
adapter, delegate); | 246 assertBookmarkItems("Wrong number of items before starting search.", 3,
adapter, delegate); |
| 227 | 247 |
| 228 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 248 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 229 @Override | 249 @Override |
| 230 public void run() { | 250 public void run() { |
| 231 delegate.openSearchUI(); | 251 delegate.openSearchUI(); |
| 232 } | 252 } |
| 233 }); | 253 }); |
| 234 | 254 |
| 235 assertEquals(BookmarkUIState.STATE_SEARCHING, delegate.getCurrentState()
); | 255 Assert.assertEquals(BookmarkUIState.STATE_SEARCHING, delegate.getCurrent
State()); |
| 236 assertBookmarkItems( | 256 assertBookmarkItems( |
| 237 "Wrong number of items after showing search UI. The promo should
be hidden.", 2, | 257 "Wrong number of items after showing search UI. The promo should
be hidden.", 2, |
| 238 adapter, delegate); | 258 adapter, delegate); |
| 239 | 259 |
| 240 searchBookmarks("Google"); | 260 searchBookmarks("Google"); |
| 241 assertBookmarkItems("Wrong number of items after searching.", 1, | 261 assertBookmarkItems("Wrong number of items after searching.", 1, |
| 242 mItemsContainer.getAdapter(), delegate); | 262 mItemsContainer.getAdapter(), delegate); |
| 243 | 263 |
| 244 BookmarkId newBookmark = addBookmark(TEST_PAGE_TITLE_GOOGLE2, mTestPage)
; | 264 BookmarkId newBookmark = addBookmark(TEST_PAGE_TITLE_GOOGLE2, mTestPage)
; |
| 245 assertBookmarkItems("Wrong number of items after bookmark added while se
arching.", 2, | 265 assertBookmarkItems("Wrong number of items after bookmark added while se
arching.", 2, |
| 246 mItemsContainer.getAdapter(), delegate); | 266 mItemsContainer.getAdapter(), delegate); |
| 247 | 267 |
| 248 removeBookmark(newBookmark); | 268 removeBookmark(newBookmark); |
| 249 assertBookmarkItems("Wrong number of items after bookmark removed while
searching.", 1, | 269 assertBookmarkItems("Wrong number of items after bookmark removed while
searching.", 1, |
| 250 mItemsContainer.getAdapter(), delegate); | 270 mItemsContainer.getAdapter(), delegate); |
| 251 | 271 |
| 252 searchBookmarks("Non-existent page"); | 272 searchBookmarks("Non-existent page"); |
| 253 assertBookmarkItems("Wrong number of items after searching for non-exist
ent item.", 0, | 273 assertBookmarkItems("Wrong number of items after searching for non-exist
ent item.", 0, |
| 254 mItemsContainer.getAdapter(), delegate); | 274 mItemsContainer.getAdapter(), delegate); |
| 255 | 275 |
| 256 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 276 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 257 @Override | 277 @Override |
| 258 public void run() { | 278 public void run() { |
| 259 delegate.closeSearchUI(); | 279 delegate.closeSearchUI(); |
| 260 } | 280 } |
| 261 }); | 281 }); |
| 262 assertBookmarkItems("Wrong number of items after closing search UI.", 3, | 282 assertBookmarkItems("Wrong number of items after closing search UI.", 3, |
| 263 mItemsContainer.getAdapter(), delegate); | 283 mItemsContainer.getAdapter(), delegate); |
| 264 assertEquals(BookmarkUIState.STATE_FOLDER, delegate.getCurrentState()); | 284 Assert.assertEquals(BookmarkUIState.STATE_FOLDER, delegate.getCurrentSta
te()); |
| 265 } | 285 } |
| 266 | 286 |
| 267 /** | 287 /** |
| 268 * Asserts the number of bookmark items being shown, taking large device dev
iders into account. | 288 * Asserts the number of bookmark items being shown, taking large device dev
iders into account. |
| 269 * | 289 * |
| 270 * @param errorMessage Error message to display in case the ass
ert fails. | 290 * @param errorMessage Error message to display in case the ass
ert fails. |
| 271 * @param exepectedOnRegularDevice Expected count of items on small tablets
. | 291 * @param exepectedOnRegularDevice Expected count of items on small tablets
. |
| 272 * @param adapter Adapter to retrieve the bookmark item co
unt from. | 292 * @param adapter Adapter to retrieve the bookmark item co
unt from. |
| 273 * @param delegate BookmarkDelegate to check the bookmark U
I state. | 293 * @param delegate BookmarkDelegate to check the bookmark U
I state. |
| 274 */ | 294 */ |
| 275 private void assertBookmarkItems(final String errorMessage, final int exepec
tedOnRegularDevice, | 295 private void assertBookmarkItems(final String errorMessage, final int exepec
tedOnRegularDevice, |
| 276 final Adapter adapter, final BookmarkDelegate delegate) { | 296 final Adapter adapter, final BookmarkDelegate delegate) { |
| 277 // TODO(twellington): Remove after bookmarks redesign is complete. | 297 // TODO(twellington): Remove after bookmarks redesign is complete. |
| 278 // The +1 for large devices stems from the divider being added to the st
ate folder for now, | 298 // The +1 for large devices stems from the divider being added to the st
ate folder for now, |
| 279 // which will offset all counts by one. | 299 // which will offset all counts by one. |
| 280 final int expectedCount = DeviceFormFactor.isLargeTablet(getActivity()) | 300 final int expectedCount = DeviceFormFactor.isLargeTablet(mActivityTestRu
le.getActivity()) |
| 281 && BookmarkUIState.STATE_FOLDER == delegate.getCurrentSt
ate() | 301 && BookmarkUIState.STATE_FOLDER == delegate.getCurrentSt
ate() |
| 282 ? exepectedOnRegularDevice + 1 | 302 ? exepectedOnRegularDevice + 1 |
| 283 : exepectedOnRegularDevice; | 303 : exepectedOnRegularDevice; |
| 284 assertEquals(errorMessage, expectedCount, adapter.getItemCount()); | 304 Assert.assertEquals(errorMessage, expectedCount, adapter.getItemCount())
; |
| 285 } | 305 } |
| 286 | 306 |
| 287 /** | 307 /** |
| 288 * Returns the View that has the given text. | 308 * Returns the View that has the given text. |
| 289 * | 309 * |
| 290 * @param viewGroup The group to which the view belongs. | 310 * @param viewGroup The group to which the view belongs. |
| 291 * @param expectedText The expected description text. | 311 * @param expectedText The expected description text. |
| 292 * @return The unique view, if one exists. Throws an exception if one doesn'
t exist. | 312 * @return The unique view, if one exists. Throws an exception if one doesn'
t exist. |
| 293 */ | 313 */ |
| 294 private static View getViewWithText(final ViewGroup viewGroup, final String
expectedText) { | 314 private static View getViewWithText(final ViewGroup viewGroup, final String
expectedText) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 351 |
| 332 private void searchBookmarks(final String query) { | 352 private void searchBookmarks(final String query) { |
| 333 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 353 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 334 @Override | 354 @Override |
| 335 public void run() { | 355 public void run() { |
| 336 ((BookmarkItemsAdapter) mItemsContainer.getAdapter()).search(que
ry); | 356 ((BookmarkItemsAdapter) mItemsContainer.getAdapter()).search(que
ry); |
| 337 } | 357 } |
| 338 }); | 358 }); |
| 339 } | 359 } |
| 340 } | 360 } |
| OLD | NEW |