Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/bookmarks/BookmarkTest.java

Issue 1688033002: Rename EnhancedBookmarks to Bookmarks, part 1. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments from #2 Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.enhancedbookmarks; 5 package org.chromium.chrome.browser.bookmarks;
6 6
7 import android.content.Intent; 7 import android.content.Intent;
8 import android.net.Uri; 8 import android.net.Uri;
9 import android.test.suitebuilder.annotation.SmallTest; 9 import android.test.suitebuilder.annotation.SmallTest;
10 import android.text.TextUtils; 10 import android.text.TextUtils;
11 import android.view.View; 11 import android.view.View;
12 import android.view.ViewGroup; 12 import android.view.ViewGroup;
13 import android.widget.TextView; 13 import android.widget.TextView;
14 14
15 import junit.framework.Assert; 15 import junit.framework.Assert;
(...skipping 17 matching lines...) Expand all
33 import org.chromium.content.browser.test.util.TouchCommon; 33 import org.chromium.content.browser.test.util.TouchCommon;
34 import org.chromium.ui.base.DeviceFormFactor; 34 import org.chromium.ui.base.DeviceFormFactor;
35 35
36 import java.util.ArrayList; 36 import java.util.ArrayList;
37 import java.util.concurrent.Callable; 37 import java.util.concurrent.Callable;
38 import java.util.concurrent.TimeoutException; 38 import java.util.concurrent.TimeoutException;
39 39
40 /** 40 /**
41 * Tests for the enhanced bookmark manager. 41 * Tests for the enhanced bookmark manager.
42 */ 42 */
43 public class EnhancedBookmarkTest extends ChromeActivityTestCaseBase<ChromeActiv ity> { 43 public class BookmarkTest extends ChromeActivityTestCaseBase<ChromeActivity> {
44 44
45 public EnhancedBookmarkTest() { 45 public BookmarkTest() {
46 super(ChromeActivity.class); 46 super(ChromeActivity.class);
47 } 47 }
48 48
49 private static final String TEST_PAGE = TestHttpServerClient.getUrl( 49 private static final String TEST_PAGE = TestHttpServerClient.getUrl(
50 "chrome/test/data/android/google.html"); 50 "chrome/test/data/android/google.html");
51 private static final String TEST_PAGE_TITLE = "The Google"; 51 private static final String TEST_PAGE_TITLE = "The Google";
52 52
53 private EnhancedBookmarksModel mBookmarkModel; 53 private BookmarkModel mBookmarkModel;
54 protected EnhancedBookmarkRecyclerView mItemsContainer; 54 protected BookmarkRecyclerView mItemsContainer;
55 55
56 @Override 56 @Override
57 public void startMainActivity() throws InterruptedException { 57 public void startMainActivity() throws InterruptedException {
58 startMainActivityFromLauncher(); 58 startMainActivityFromLauncher();
59 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 59 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
60 @Override 60 @Override
61 public void run() { 61 public void run() {
62 mBookmarkModel = new EnhancedBookmarksModel( 62 mBookmarkModel = new BookmarkModel(
63 getActivity().getActivityTab().getProfile()); 63 getActivity().getActivityTab().getProfile());
64 } 64 }
65 }); 65 });
66 waitForBookmarkModelLoaded(); 66 waitForBookmarkModelLoaded();
67 } 67 }
68 68
69 private void waitForBookmarkModelLoaded() throws InterruptedException { 69 private void waitForBookmarkModelLoaded() throws InterruptedException {
70 final CallbackHelper loadedCallback = new CallbackHelper(); 70 final CallbackHelper loadedCallback = new CallbackHelper();
71 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 71 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
72 @Override 72 @Override
(...skipping 16 matching lines...) Expand all
89 try { 89 try {
90 loadedCallback.waitForCallback(0); 90 loadedCallback.waitForCallback(0);
91 } catch (TimeoutException e) { 91 } catch (TimeoutException e) {
92 Assert.fail("Enhanced Bookmark model did not load: Timeout."); 92 Assert.fail("Enhanced Bookmark model did not load: Timeout.");
93 } 93 }
94 } 94 }
95 95
96 private void openBookmarkManager() throws InterruptedException { 96 private void openBookmarkManager() throws InterruptedException {
97 if (DeviceFormFactor.isTablet(getActivity())) { 97 if (DeviceFormFactor.isTablet(getActivity())) {
98 loadUrl(UrlConstants.BOOKMARKS_URL); 98 loadUrl(UrlConstants.BOOKMARKS_URL);
99 mItemsContainer = (EnhancedBookmarkRecyclerView) getActivity().findV iewById( 99 mItemsContainer = (BookmarkRecyclerView) getActivity().findViewById(
100 R.id.eb_items_container); 100 R.id.eb_items_container);
101 } else { 101 } else {
102 // phone 102 // phone
103 EnhancedBookmarkActivity activity = ActivityUtils.waitForActivity(ge tInstrumentation(), 103 BookmarkActivity activity = ActivityUtils.waitForActivity(getInstrum entation(),
104 EnhancedBookmarkActivity.class, new MenuUtils.MenuActivityTr igger( 104 BookmarkActivity.class, new MenuUtils.MenuActivityTrigger(
105 getInstrumentation(), getActivity(), R.id.all_bookma rks_menu_id)); 105 getInstrumentation(), getActivity(), R.id.all_bookma rks_menu_id));
106 mItemsContainer = (EnhancedBookmarkRecyclerView) activity.findViewBy Id( 106 mItemsContainer = (BookmarkRecyclerView) activity.findViewById(
107 R.id.eb_items_container); 107 R.id.eb_items_container);
108 } 108 }
109 } 109 }
110 110
111 private void openBookmarkManager(final String url) throws InterruptedExcepti on { 111 private void openBookmarkManager(final String url) throws InterruptedExcepti on {
112 if (DeviceFormFactor.isTablet(getActivity())) { 112 if (DeviceFormFactor.isTablet(getActivity())) {
113 loadUrl(url); 113 loadUrl(url);
114 mItemsContainer = (EnhancedBookmarkRecyclerView) getActivity().findV iewById( 114 mItemsContainer = (BookmarkRecyclerView) getActivity().findViewById(
115 R.id.eb_items_container); 115 R.id.eb_items_container);
116 } else { 116 } else {
117 // phone 117 // phone
118 EnhancedBookmarkActivity activity = ActivityUtils.waitForActivity(ge tInstrumentation(), 118 BookmarkActivity activity = ActivityUtils.waitForActivity(getInstrum entation(),
119 EnhancedBookmarkActivity.class, new Runnable() { 119 BookmarkActivity.class, new Runnable() {
120 @Override 120 @Override
121 public void run() { 121 public void run() {
122 Intent intent = new Intent(getActivity(), 122 Intent intent = new Intent(getActivity(),
123 EnhancedBookmarkActivity.class); 123 BookmarkActivity.class);
124 intent.setData(Uri.parse(url)); 124 intent.setData(Uri.parse(url));
125 getActivity().startActivity(intent); 125 getActivity().startActivity(intent);
126 } 126 }
127 }); 127 });
128 mItemsContainer = (EnhancedBookmarkRecyclerView) activity.findViewBy Id( 128 mItemsContainer = (BookmarkRecyclerView) activity.findViewById(
129 R.id.eb_items_container); 129 R.id.eb_items_container);
130 } 130 }
131 } 131 }
132 132
133 private boolean isItemPresentInBookmarkList(final String expectedTitle) { 133 private boolean isItemPresentInBookmarkList(final String expectedTitle) {
134 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean >() { 134 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean >() {
135 @Override 135 @Override
136 public Boolean call() throws Exception { 136 public Boolean call() throws Exception {
137 for (int i = 0; i < mItemsContainer.getAdapter().getItemCount(); i++) { 137 for (int i = 0; i < mItemsContainer.getAdapter().getItemCount(); i++) {
138 BookmarkId item = mItemsContainer.getAdapter().getItem(i); 138 BookmarkId item = mItemsContainer.getAdapter().getItem(i);
139 if (item == null) continue; 139 if (item == null) continue;
140 140
141 String actualTitle = mBookmarkModel.getBookmarkTitle(item); 141 String actualTitle = mBookmarkModel.getBookmarkTitle(item);
142 if (TextUtils.equals(actualTitle, expectedTitle)) { 142 if (TextUtils.equals(actualTitle, expectedTitle)) {
143 return true; 143 return true;
144 } 144 }
145 } 145 }
146 return false; 146 return false;
147 } 147 }
148 }); 148 });
149 } 149 }
150 150
151 @SmallTest 151 @SmallTest
152 public void testAddBookmark() throws InterruptedException { 152 public void testAddBookmark() throws InterruptedException {
153 loadUrl(TEST_PAGE); 153 loadUrl(TEST_PAGE);
154 // Click star button to bookmark the curent tab. 154 // Click star button to bookmark the curent tab.
155 MenuUtils.invokeCustomMenuActionSync(getInstrumentation(), getActivity() , 155 MenuUtils.invokeCustomMenuActionSync(getInstrumentation(), getActivity() ,
156 R.id.bookmark_this_page_id); 156 R.id.bookmark_this_page_id);
157 // All actions with EnhancedBookmarksModel needs to run on UI thread. 157 // All actions with BookmarkModel needs to run on UI thread.
158 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 158 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
159 @Override 159 @Override
160 public void run() { 160 public void run() {
161 long bookmarkIdLong = getActivity().getActivityTab().getUserBook markId(); 161 long bookmarkIdLong = getActivity().getActivityTab().getUserBook markId();
162 BookmarkId id = new BookmarkId(bookmarkIdLong, BookmarkType.NORM AL); 162 BookmarkId id = new BookmarkId(bookmarkIdLong, BookmarkType.NORM AL);
163 assertTrue("The test page is not added as bookmark: ", 163 assertTrue("The test page is not added as bookmark: ",
164 mBookmarkModel.doesBookmarkExist(id)); 164 mBookmarkModel.doesBookmarkExist(id));
165 BookmarkItem item = mBookmarkModel.getBookmarkById(id); 165 BookmarkItem item = mBookmarkModel.getBookmarkById(id);
166 assertEquals(mBookmarkModel.getDefaultFolder(), item.getParentId ()); 166 assertEquals(mBookmarkModel.getDefaultFolder(), item.getParentId ());
167 assertEquals(TEST_PAGE, item.getUrl()); 167 assertEquals(TEST_PAGE, item.getUrl());
(...skipping 23 matching lines...) Expand all
191 }); 191 });
192 assertEquals(TEST_PAGE_TITLE, getActivity().getActivityTab().getTitle()) ; 192 assertEquals(TEST_PAGE_TITLE, getActivity().getActivityTab().getTitle()) ;
193 } 193 }
194 194
195 @SmallTest 195 @SmallTest
196 public void testUrlComposition() { 196 public void testUrlComposition() {
197 BookmarkId mobileId = mBookmarkModel.getMobileFolderId(); 197 BookmarkId mobileId = mBookmarkModel.getMobileFolderId();
198 BookmarkId bookmarkBarId = mBookmarkModel.getDesktopFolderId(); 198 BookmarkId bookmarkBarId = mBookmarkModel.getDesktopFolderId();
199 BookmarkId otherId = mBookmarkModel.getOtherFolderId(); 199 BookmarkId otherId = mBookmarkModel.getOtherFolderId();
200 assertEquals("chrome-native://bookmarks/folder/" + mobileId, 200 assertEquals("chrome-native://bookmarks/folder/" + mobileId,
201 EnhancedBookmarkUIState.createFolderUrl(mobileId).toString()); 201 BookmarkUIState.createFolderUrl(mobileId).toString());
202 assertEquals("chrome-native://bookmarks/folder/" + bookmarkBarId, 202 assertEquals("chrome-native://bookmarks/folder/" + bookmarkBarId,
203 EnhancedBookmarkUIState.createFolderUrl(bookmarkBarId).toString( )); 203 BookmarkUIState.createFolderUrl(bookmarkBarId).toString());
204 assertEquals("chrome-native://bookmarks/folder/" + otherId, 204 assertEquals("chrome-native://bookmarks/folder/" + otherId,
205 EnhancedBookmarkUIState.createFolderUrl(otherId).toString()); 205 BookmarkUIState.createFolderUrl(otherId).toString());
206 206
207 assertEquals("chrome-native://bookmarks/filter/OFFLINE_PAGES", EnhancedB ookmarkUIState 207 assertEquals("chrome-native://bookmarks/filter/OFFLINE_PAGES", BookmarkU IState
208 .createFilterUrl(EnhancedBookmarkFilter.OFFLINE_PAGES, true).toS tring()); 208 .createFilterUrl(BookmarkFilter.OFFLINE_PAGES, true).toString()) ;
209 assertEquals( 209 assertEquals(
210 "chrome-native://bookmarks/filter/OFFLINE_PAGES?persist=0", 210 "chrome-native://bookmarks/filter/OFFLINE_PAGES?persist=0",
211 EnhancedBookmarkUIState.createFilterUrl(EnhancedBookmarkFilter.O FFLINE_PAGES, 211 BookmarkUIState.createFilterUrl(BookmarkFilter.OFFLINE_PAGES,
212 false).toString()); 212 false).toString());
213 } 213 }
214 214
215 @SmallTest 215 @SmallTest
216 public void testOpenBookmarkManager() throws InterruptedException { 216 public void testOpenBookmarkManager() throws InterruptedException {
217 openBookmarkManager(); 217 openBookmarkManager();
218 EnhancedBookmarkDelegate delegate = mItemsContainer.getDelegateForTestin g(); 218 BookmarkDelegate delegate = mItemsContainer.getDelegateForTesting();
219 assertEquals(EnhancedBookmarkUIState.STATE_ALL_BOOKMARKS, delegate.getCu rrentState()); 219 assertEquals(BookmarkUIState.STATE_ALL_BOOKMARKS, delegate.getCurrentSta te());
220 assertEquals(UrlConstants.BOOKMARKS_URL, 220 assertEquals(UrlConstants.BOOKMARKS_URL,
221 EnhancedBookmarkUtils.getLastUsedUrl(getActivity())); 221 BookmarkUtils.getLastUsedUrl(getActivity()));
222 } 222 }
223 223
224 @SmallTest 224 @SmallTest
225 @CommandLineFlags.Add(ChromeSwitches.ENABLE_OFFLINE_PAGES) 225 @CommandLineFlags.Add(ChromeSwitches.ENABLE_OFFLINE_PAGES)
226 public void testOpenBookmarkManagerInOfflinePagePersist() throws Interrupted Exception { 226 public void testOpenBookmarkManagerInOfflinePagePersist() throws Interrupted Exception {
227 EnhancedBookmarkUtils.setLastUsedUrl(getActivity(), UrlConstants.BOOKMAR KS_URL); 227 BookmarkUtils.setLastUsedUrl(getActivity(), UrlConstants.BOOKMARKS_URL);
228 String url = "chrome-native://bookmarks/filter/OFFLINE_PAGES"; 228 String url = "chrome-native://bookmarks/filter/OFFLINE_PAGES";
229 openBookmarkManager(url); 229 openBookmarkManager(url);
230 EnhancedBookmarkDelegate delegate = mItemsContainer.getDelegateForTestin g(); 230 BookmarkDelegate delegate = mItemsContainer.getDelegateForTesting();
231 assertEquals(EnhancedBookmarkUIState.STATE_FILTER, delegate.getCurrentSt ate()); 231 assertEquals(BookmarkUIState.STATE_FILTER, delegate.getCurrentState());
232 assertEquals(url, EnhancedBookmarkUtils.getLastUsedUrl(getActivity())); 232 assertEquals(url, BookmarkUtils.getLastUsedUrl(getActivity()));
233 } 233 }
234 234
235 @SmallTest 235 @SmallTest
236 @CommandLineFlags.Add(ChromeSwitches.ENABLE_OFFLINE_PAGES) 236 @CommandLineFlags.Add(ChromeSwitches.ENABLE_OFFLINE_PAGES)
237 public void testOpenBookmarkManagerInOfflinePageNoPersist() throws Interrupt edException { 237 public void testOpenBookmarkManagerInOfflinePageNoPersist() throws Interrupt edException {
238 EnhancedBookmarkUtils.setLastUsedUrl(getActivity(), UrlConstants.BOOKMAR KS_URL); 238 BookmarkUtils.setLastUsedUrl(getActivity(), UrlConstants.BOOKMARKS_URL);
239 String url = "chrome-native://bookmarks/filter/OFFLINE_PAGES?persist=0"; 239 String url = "chrome-native://bookmarks/filter/OFFLINE_PAGES?persist=0";
240 openBookmarkManager(url); 240 openBookmarkManager(url);
241 EnhancedBookmarkDelegate delegate = mItemsContainer.getDelegateForTestin g(); 241 BookmarkDelegate delegate = mItemsContainer.getDelegateForTesting();
242 assertEquals(EnhancedBookmarkUIState.STATE_FILTER, delegate.getCurrentSt ate()); 242 assertEquals(BookmarkUIState.STATE_FILTER, delegate.getCurrentState());
243 assertEquals(UrlConstants.BOOKMARKS_URL, 243 assertEquals(UrlConstants.BOOKMARKS_URL,
244 EnhancedBookmarkUtils.getLastUsedUrl(getActivity())); 244 BookmarkUtils.getLastUsedUrl(getActivity()));
245 } 245 }
246 246
247 @SmallTest 247 @SmallTest
248 @CommandLineFlags.Add(ChromeSwitches.DISABLE_OFFLINE_PAGES) 248 @CommandLineFlags.Add(ChromeSwitches.DISABLE_OFFLINE_PAGES)
249 public void testOpenBookmarkManagerInOfflinePageWhenDisabled() throws Interr uptedException { 249 public void testOpenBookmarkManagerInOfflinePageWhenDisabled() throws Interr uptedException {
250 openBookmarkManager("chrome-native://bookmarks/filter/OFFLINE_PAGES"); 250 openBookmarkManager("chrome-native://bookmarks/filter/OFFLINE_PAGES");
251 EnhancedBookmarkDelegate delegate = mItemsContainer.getDelegateForTestin g(); 251 BookmarkDelegate delegate = mItemsContainer.getDelegateForTesting();
252 assertEquals(EnhancedBookmarkUIState.STATE_ALL_BOOKMARKS, delegate.getCu rrentState()); 252 assertEquals(BookmarkUIState.STATE_ALL_BOOKMARKS, delegate.getCurrentSta te());
253 } 253 }
254 254
255 /** 255 /**
256 * Returns the View that has the given text. 256 * Returns the View that has the given text.
257 * 257 *
258 * @param viewGroup The group to which the view belongs. 258 * @param viewGroup The group to which the view belongs.
259 * @param expectedText The expected description text. 259 * @param expectedText The expected description text.
260 * @return The unique view, if one exists. Throws an exception if one doesn' t exist. 260 * @return The unique view, if one exists. Throws an exception if one doesn' t exist.
261 */ 261 */
262 private static View getViewWithText(final ViewGroup viewGroup, final String expectedText) { 262 private static View getViewWithText(final ViewGroup viewGroup, final String expectedText) {
263 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<View>() { 263 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<View>() {
264 @Override 264 @Override
265 public View call() throws Exception { 265 public View call() throws Exception {
266 ArrayList<View> outViews = new ArrayList<View>(); 266 ArrayList<View> outViews = new ArrayList<View>();
267 ArrayList<View> matchingViews = new ArrayList<View>(); 267 ArrayList<View> matchingViews = new ArrayList<View>();
268 viewGroup.findViewsWithText(outViews, expectedText, View.FIND_VI EWS_WITH_TEXT); 268 viewGroup.findViewsWithText(outViews, expectedText, View.FIND_VI EWS_WITH_TEXT);
269 // outViews includes all views whose text contains expectedText as a 269 // outViews includes all views whose text contains expectedText as a
270 // case-insensitive substring. Filter these views to find only e xact string matches. 270 // case-insensitive substring. Filter these views to find only e xact string matches.
271 for (View v : outViews) { 271 for (View v : outViews) {
272 if (TextUtils.equals(((TextView) v).getText().toString(), ex pectedText)) { 272 if (TextUtils.equals(((TextView) v).getText().toString(), ex pectedText)) {
273 matchingViews.add(v); 273 matchingViews.add(v);
274 } 274 }
275 } 275 }
276 Assert.assertEquals("Exactly one item should be present.", 1, ma tchingViews.size()); 276 Assert.assertEquals("Exactly one item should be present.", 1, ma tchingViews.size());
277 return matchingViews.get(0); 277 return matchingViews.get(0);
278 } 278 }
279 }); 279 });
280 } 280 }
281 } 281 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698