OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.suggestions; | 5 package org.chromium.chrome.browser.suggestions; |
6 | 6 |
7 import static org.hamcrest.CoreMatchers.is; | 7 import static org.hamcrest.CoreMatchers.is; |
8 import static org.junit.Assert.assertNotNull; | 8 import static org.junit.Assert.assertNotNull; |
9 import static org.junit.Assert.assertThat; | 9 import static org.junit.Assert.assertThat; |
10 import static org.junit.Assert.fail; | 10 import static org.junit.Assert.fail; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 import org.robolectric.annotation.Implementation; | 46 import org.robolectric.annotation.Implementation; |
47 import org.robolectric.annotation.Implements; | 47 import org.robolectric.annotation.Implements; |
48 import org.robolectric.shadows.ShadowResources; | 48 import org.robolectric.shadows.ShadowResources; |
49 | 49 |
50 import org.chromium.base.Callback; | 50 import org.chromium.base.Callback; |
51 import org.chromium.chrome.R; | 51 import org.chromium.chrome.R; |
52 import org.chromium.chrome.browser.ChromeFeatureList; | 52 import org.chromium.chrome.browser.ChromeFeatureList; |
53 import org.chromium.chrome.browser.Features; | 53 import org.chromium.chrome.browser.Features; |
54 import org.chromium.chrome.browser.favicon.LargeIconBridge.LargeIconCallback; | 54 import org.chromium.chrome.browser.favicon.LargeIconBridge.LargeIconCallback; |
55 import org.chromium.chrome.browser.ntp.ContextMenuManager; | 55 import org.chromium.chrome.browser.ntp.ContextMenuManager; |
56 import org.chromium.chrome.browser.ntp.NTPTileSource; | |
57 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; | 56 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; |
58 import org.chromium.testing.local.LocalRobolectricTestRunner; | 57 import org.chromium.testing.local.LocalRobolectricTestRunner; |
59 | 58 |
60 /** | 59 /** |
61 * Unit tests for {@link TileGroup}. | 60 * Unit tests for {@link TileGroup}. |
62 */ | 61 */ |
63 @RunWith(LocalRobolectricTestRunner.class) | 62 @RunWith(LocalRobolectricTestRunner.class) |
64 @Config(manifest = Config.NONE, sdk = 21, | 63 @Config(manifest = Config.NONE, sdk = 21, |
65 shadows = {TileGroupTest.TileShadowResources.class, | 64 shadows = {TileGroupTest.TileShadowResources.class, |
66 TileGroupTest.ShadowLayoutInflater.class}) | 65 TileGroupTest.ShadowLayoutInflater.class}) |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 } | 353 } |
355 | 354 |
356 @Test | 355 @Test |
357 public void testIconLoadingWhenTileNotRegistered() { | 356 public void testIconLoadingWhenTileNotRegistered() { |
358 SuggestionsUiDelegate uiDelegate = mock(SuggestionsUiDelegate.class); | 357 SuggestionsUiDelegate uiDelegate = mock(SuggestionsUiDelegate.class); |
359 TileGroup tileGroup = new TileGroup(RuntimeEnvironment.application, uiDe
legate, | 358 TileGroup tileGroup = new TileGroup(RuntimeEnvironment.application, uiDe
legate, |
360 mock(ContextMenuManager.class), mTileGroupDelegate, mTileGroupOb
server, | 359 mock(ContextMenuManager.class), mTileGroupDelegate, mTileGroupOb
server, |
361 mock(OfflinePageBridge.class), TILE_TITLE_LINES); | 360 mock(OfflinePageBridge.class), TILE_TITLE_LINES); |
362 tileGroup.startObserving(MAX_TILES_TO_FETCH); | 361 tileGroup.startObserving(MAX_TILES_TO_FETCH); |
363 reset(mTileGroupObserver); | 362 reset(mTileGroupObserver); |
364 Tile tile = new Tile("title", URLS[0], "", 0, NTPTileSource.POPULAR); | 363 Tile tile = new Tile("title", URLS[0], "", 0, TileSource.POPULAR); |
365 | 364 |
366 ViewGroup layout = new FrameLayout(RuntimeEnvironment.application, null)
; | 365 ViewGroup layout = new FrameLayout(RuntimeEnvironment.application, null)
; |
367 tileGroup.buildTileView(tile, layout, /* trackLoadTask = */ true, /* con
densed = */ false); | 366 tileGroup.buildTileView(tile, layout, /* trackLoadTask = */ true, /* con
densed = */ false); |
368 verify(mTileGroupObserver).onLoadTaskAdded(); | 367 verify(mTileGroupObserver).onLoadTaskAdded(); |
369 | 368 |
370 ArgumentCaptor<LargeIconCallback> captor = ArgumentCaptor.forClass(Large
IconCallback.class); | 369 ArgumentCaptor<LargeIconCallback> captor = ArgumentCaptor.forClass(Large
IconCallback.class); |
371 verify(uiDelegate).getLargeIconForUrl(any(String.class), anyInt(), capto
r.capture()); | 370 verify(uiDelegate).getLargeIconForUrl(any(String.class), anyInt(), capto
r.capture()); |
372 captor.getValue().onLargeIconAvailable(mock(Bitmap.class), Color.BLACK,
false); | 371 captor.getValue().onLargeIconAvailable(mock(Bitmap.class), Color.BLACK,
false); |
373 | 372 |
374 verify(mTileGroupObserver).onLoadTaskCompleted(); | 373 verify(mTileGroupObserver).onLoadTaskCompleted(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 @LayoutRes | 466 @LayoutRes |
468 int layoutId = invocation.getArgument(0); | 467 int layoutId = invocation.getArgument(0); |
469 if (layoutId != R.layout.tile_view) fail("Unexpected
resource id."); | 468 if (layoutId != R.layout.tile_view) fail("Unexpected
resource id."); |
470 return createMockTileView(); | 469 return createMockTileView(); |
471 } | 470 } |
472 }); | 471 }); |
473 return layoutInflater; | 472 return layoutInflater; |
474 } | 473 } |
475 } | 474 } |
476 } | 475 } |
OLD | NEW |