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.test.UiThreadTest; | 7 import android.test.UiThreadTest; |
8 import android.test.suitebuilder.annotation.SmallTest; | 8 import android.test.suitebuilder.annotation.SmallTest; |
9 | 9 |
10 import org.chromium.base.ThreadUtils; | 10 import org.chromium.base.ThreadUtils; |
11 import org.chromium.base.annotations.SuppressFBWarnings; | 11 import org.chromium.base.annotations.SuppressFBWarnings; |
12 import org.chromium.base.test.util.CommandLineFlags; | |
13 import org.chromium.base.test.util.Feature; | 12 import org.chromium.base.test.util.Feature; |
14 import org.chromium.chrome.browser.ChromeSwitches; | |
15 import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem; | 13 import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem; |
16 import org.chromium.chrome.browser.bookmarks.BookmarkModel.AddBookmarkCallback; | |
17 import org.chromium.chrome.browser.profiles.Profile; | 14 import org.chromium.chrome.browser.profiles.Profile; |
18 import org.chromium.chrome.test.util.BookmarkTestUtil; | 15 import org.chromium.chrome.test.util.BookmarkTestUtil; |
19 import org.chromium.components.bookmarks.BookmarkId; | 16 import org.chromium.components.bookmarks.BookmarkId; |
20 import org.chromium.content.browser.test.NativeLibraryTestBase; | 17 import org.chromium.content.browser.test.NativeLibraryTestBase; |
21 | 18 |
22 import java.util.ArrayList; | 19 import java.util.ArrayList; |
23 import java.util.Arrays; | 20 import java.util.Arrays; |
24 import java.util.HashSet; | 21 import java.util.HashSet; |
25 import java.util.List; | 22 import java.util.List; |
26 import java.util.Stack; | 23 import java.util.Stack; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 BookmarkId folderC = mBookmarkModel.addFolder(mMobileNode, 0, "fc"); | 198 BookmarkId folderC = mBookmarkModel.addFolder(mMobileNode, 0, "fc"); |
202 verifyBookmark(folderC, "fc", null, true, mMobileNode); | 199 verifyBookmark(folderC, "fc", null, true, mMobileNode); |
203 | 200 |
204 BookmarkId bookmarkAA = addBookmark(folderA, 0, "aa", "http://aa.com"); | 201 BookmarkId bookmarkAA = addBookmark(folderA, 0, "aa", "http://aa.com"); |
205 verifyBookmark(bookmarkAA, "aa", "http://aa.com/", false, folderA); | 202 verifyBookmark(bookmarkAA, "aa", "http://aa.com/", false, folderA); |
206 | 203 |
207 BookmarkId folderAA = mBookmarkModel.addFolder(folderA, 0, "faa"); | 204 BookmarkId folderAA = mBookmarkModel.addFolder(folderA, 0, "faa"); |
208 verifyBookmark(folderAA, "faa", null, true, folderA); | 205 verifyBookmark(folderAA, "faa", null, true, folderA); |
209 } | 206 } |
210 | 207 |
211 @UiThreadTest | |
212 @SmallTest | |
213 @CommandLineFlags.Add({ChromeSwitches.ENABLE_OFFLINE_PAGES}) | |
214 @Feature({"Bookmark"}) | |
215 public void testOfflineBridgeLoaded() { | |
216 assertTrue(mBookmarkModel.getOfflinePageBridge() != null); | |
217 assertTrue(mBookmarkModel.getOfflinePageBridge().isOfflinePageModelLoade
d()); | |
218 } | |
219 | |
220 private BookmarkId addBookmark(final BookmarkId parent, final int index, fin
al String title, | 208 private BookmarkId addBookmark(final BookmarkId parent, final int index, fin
al String title, |
221 final String url) { | 209 final String url) { |
222 final AtomicReference<BookmarkId> result = new AtomicReference<BookmarkI
d>(); | 210 final AtomicReference<BookmarkId> result = new AtomicReference<BookmarkI
d>(); |
223 final Semaphore semaphore = new Semaphore(0); | 211 final Semaphore semaphore = new Semaphore(0); |
224 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 212 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
225 @Override | 213 @Override |
226 public void run() { | 214 public void run() { |
227 mBookmarkModel.addBookmarkAsync( | 215 result.set(mBookmarkModel.addBookmark(parent, index, title, url)
); |
228 parent, index, title, url, null, new AddBookmarkCallback
() { | 216 semaphore.release(); |
229 @Override | |
230 public void onBookmarkAdded( | |
231 final BookmarkId bookmarkId, int saveResult)
{ | |
232 result.set(bookmarkId); | |
233 semaphore.release(); | |
234 } | |
235 }); | |
236 } | 217 } |
237 }); | 218 }); |
238 try { | 219 try { |
239 if (semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS)) { | 220 if (semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS)) { |
240 return result.get(); | 221 return result.get(); |
241 } else { | 222 } else { |
242 return null; | 223 return null; |
243 } | 224 } |
244 } catch (InterruptedException e) { | 225 } catch (InterruptedException e) { |
245 return null; | 226 return null; |
(...skipping 19 matching lines...) Expand all Loading... |
265 HashSet<BookmarkId> expectedIdsCopy = new HashSet<>(expectedIds); | 246 HashSet<BookmarkId> expectedIdsCopy = new HashSet<>(expectedIds); |
266 assertEquals(expectedIdsCopy.size(), listToVerify.size()); | 247 assertEquals(expectedIdsCopy.size(), listToVerify.size()); |
267 for (BookmarkId id : listToVerify) { | 248 for (BookmarkId id : listToVerify) { |
268 assertNotNull(id); | 249 assertNotNull(id); |
269 assertTrue("List contains wrong element: ", expectedIdsCopy.contains
(id)); | 250 assertTrue("List contains wrong element: ", expectedIdsCopy.contains
(id)); |
270 expectedIdsCopy.remove(id); | 251 expectedIdsCopy.remove(id); |
271 } | 252 } |
272 assertTrue("List does not contain some expected bookmarks: ", expectedId
sCopy.isEmpty()); | 253 assertTrue("List does not contain some expected bookmarks: ", expectedId
sCopy.isEmpty()); |
273 } | 254 } |
274 } | 255 } |
OLD | NEW |