| 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.content.Intent; | 7 import android.content.Intent; |
| 8 import android.net.Uri; | 8 import android.net.Uri; |
| 9 import android.os.Environment; | 9 import android.os.Environment; |
| 10 import android.test.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 import org.chromium.content.browser.test.util.CallbackHelper; | 32 import org.chromium.content.browser.test.util.CallbackHelper; |
| 33 import org.chromium.content.browser.test.util.TouchCommon; | 33 import org.chromium.content.browser.test.util.TouchCommon; |
| 34 import org.chromium.net.test.EmbeddedTestServer; | 34 import org.chromium.net.test.EmbeddedTestServer; |
| 35 import org.chromium.ui.base.DeviceFormFactor; | 35 import org.chromium.ui.base.DeviceFormFactor; |
| 36 | 36 |
| 37 import java.util.ArrayList; | 37 import java.util.ArrayList; |
| 38 import java.util.concurrent.Callable; | 38 import java.util.concurrent.Callable; |
| 39 import java.util.concurrent.TimeoutException; | 39 import java.util.concurrent.TimeoutException; |
| 40 | 40 |
| 41 /** | 41 /** |
| 42 * Tests for the enhanced bookmark manager. | 42 * Tests for the bookmark manager. |
| 43 */ | 43 */ |
| 44 public class BookmarkTest extends ChromeActivityTestCaseBase<ChromeActivity> { | 44 public class BookmarkTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
| 45 | 45 |
| 46 public BookmarkTest() { | 46 public BookmarkTest() { |
| 47 super(ChromeActivity.class); | 47 super(ChromeActivity.class); |
| 48 mSkipCheckHttpServer = true; | 48 mSkipCheckHttpServer = true; |
| 49 } | 49 } |
| 50 | 50 |
| 51 private static final String TEST_PAGE = "/chrome/test/data/android/google.ht
ml"; | 51 private static final String TEST_PAGE = "/chrome/test/data/android/google.ht
ml"; |
| 52 private static final String TEST_PAGE_TITLE = "The Google"; | 52 private static final String TEST_PAGE_TITLE = "The Google"; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 loadedCallback.notifyCalled(); | 99 loadedCallback.notifyCalled(); |
| 100 mBookmarkModel.removeObserver(this); | 100 mBookmarkModel.removeObserver(this); |
| 101 } | 101 } |
| 102 }); | 102 }); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 }); | 105 }); |
| 106 try { | 106 try { |
| 107 loadedCallback.waitForCallback(0); | 107 loadedCallback.waitForCallback(0); |
| 108 } catch (TimeoutException e) { | 108 } catch (TimeoutException e) { |
| 109 Assert.fail("Enhanced Bookmark model did not load: Timeout."); | 109 Assert.fail("bookmark model did not load: Timeout."); |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 | 112 |
| 113 private void openBookmarkManager() throws InterruptedException { | 113 private void openBookmarkManager() throws InterruptedException { |
| 114 if (DeviceFormFactor.isTablet(getActivity())) { | 114 if (DeviceFormFactor.isTablet(getActivity())) { |
| 115 loadUrl(UrlConstants.BOOKMARKS_URL); | 115 loadUrl(UrlConstants.BOOKMARKS_URL); |
| 116 mItemsContainer = (BookmarkRecyclerView) getActivity().findViewById( | 116 mItemsContainer = (BookmarkRecyclerView) getActivity().findViewById( |
| 117 R.id.eb_items_container); | 117 R.id.bookmark_items_container); |
| 118 } else { | 118 } else { |
| 119 // phone | 119 // phone |
| 120 BookmarkActivity activity = ActivityUtils.waitForActivity(getInstrum
entation(), | 120 BookmarkActivity activity = ActivityUtils.waitForActivity(getInstrum
entation(), |
| 121 BookmarkActivity.class, new MenuUtils.MenuActivityTrigger( | 121 BookmarkActivity.class, new MenuUtils.MenuActivityTrigger( |
| 122 getInstrumentation(), getActivity(), R.id.all_bookma
rks_menu_id)); | 122 getInstrumentation(), getActivity(), R.id.all_bookma
rks_menu_id)); |
| 123 mItemsContainer = (BookmarkRecyclerView) activity.findViewById( | 123 mItemsContainer = (BookmarkRecyclerView) activity.findViewById( |
| 124 R.id.eb_items_container); | 124 R.id.bookmark_items_container); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 private void openBookmarkManager(final String url) throws InterruptedExcepti
on { | 128 private void openBookmarkManager(final String url) throws InterruptedExcepti
on { |
| 129 if (DeviceFormFactor.isTablet(getActivity())) { | 129 if (DeviceFormFactor.isTablet(getActivity())) { |
| 130 loadUrl(url); | 130 loadUrl(url); |
| 131 mItemsContainer = (BookmarkRecyclerView) getActivity().findViewById( | 131 mItemsContainer = (BookmarkRecyclerView) getActivity().findViewById( |
| 132 R.id.eb_items_container); | 132 R.id.bookmark_items_container); |
| 133 } else { | 133 } else { |
| 134 // phone | 134 // phone |
| 135 BookmarkActivity activity = ActivityUtils.waitForActivity(getInstrum
entation(), | 135 BookmarkActivity activity = ActivityUtils.waitForActivity(getInstrum
entation(), |
| 136 BookmarkActivity.class, new Runnable() { | 136 BookmarkActivity.class, new Runnable() { |
| 137 @Override | 137 @Override |
| 138 public void run() { | 138 public void run() { |
| 139 Intent intent = new Intent(getActivity(), | 139 Intent intent = new Intent(getActivity(), |
| 140 BookmarkActivity.class); | 140 BookmarkActivity.class); |
| 141 intent.setData(Uri.parse(url)); | 141 intent.setData(Uri.parse(url)); |
| 142 getActivity().startActivity(intent); | 142 getActivity().startActivity(intent); |
| 143 } | 143 } |
| 144 }); | 144 }); |
| 145 mItemsContainer = (BookmarkRecyclerView) activity.findViewById( | 145 mItemsContainer = (BookmarkRecyclerView) activity.findViewById( |
| 146 R.id.eb_items_container); | 146 R.id.bookmark_items_container); |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 private boolean isItemPresentInBookmarkList(final String expectedTitle) { | 150 private boolean isItemPresentInBookmarkList(final String expectedTitle) { |
| 151 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean
>() { | 151 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean
>() { |
| 152 @Override | 152 @Override |
| 153 public Boolean call() throws Exception { | 153 public Boolean call() throws Exception { |
| 154 for (int i = 0; i < mItemsContainer.getAdapter().getItemCount();
i++) { | 154 for (int i = 0; i < mItemsContainer.getAdapter().getItemCount();
i++) { |
| 155 BookmarkId item = mItemsContainer.getAdapter().getItem(i); | 155 BookmarkId item = mItemsContainer.getAdapter().getItem(i); |
| 156 if (item == null) continue; | 156 if (item == null) continue; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 if (TextUtils.equals(((TextView) v).getText().toString(), ex
pectedText)) { | 289 if (TextUtils.equals(((TextView) v).getText().toString(), ex
pectedText)) { |
| 290 matchingViews.add(v); | 290 matchingViews.add(v); |
| 291 } | 291 } |
| 292 } | 292 } |
| 293 Assert.assertEquals("Exactly one item should be present.", 1, ma
tchingViews.size()); | 293 Assert.assertEquals("Exactly one item should be present.", 1, ma
tchingViews.size()); |
| 294 return matchingViews.get(0); | 294 return matchingViews.get(0); |
| 295 } | 295 } |
| 296 }); | 296 }); |
| 297 } | 297 } |
| 298 } | 298 } |
| OLD | NEW |