OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.ntp.cards; | 5 package org.chromium.chrome.browser.ntp.cards; |
6 | 6 |
7 import android.content.res.Resources; | 7 import android.content.res.Resources; |
8 import android.support.test.filters.MediumTest; | 8 import android.support.test.filters.MediumTest; |
9 import android.support.v7.widget.RecyclerView; | 9 import android.support.v7.widget.RecyclerView; |
10 import android.support.v7.widget.RecyclerView.ViewHolder; | 10 import android.support.v7.widget.RecyclerView.ViewHolder; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 private String[] mSiteSuggestionUrls; | 68 private String[] mSiteSuggestionUrls; |
69 private FakeMostVisitedSites mMostVisitedSites; | 69 private FakeMostVisitedSites mMostVisitedSites; |
70 private EmbeddedTestServer mTestServer; | 70 private EmbeddedTestServer mTestServer; |
71 private FakeSuggestionsSource mSource; | 71 private FakeSuggestionsSource mSource; |
72 | 72 |
73 @Override | 73 @Override |
74 protected void setUp() throws Exception { | 74 protected void setUp() throws Exception { |
75 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation
().getContext()); | 75 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation
().getContext()); |
76 mSiteSuggestionUrls = new String[] {mTestServer.getURL(TEST_PAGE)}; | 76 mSiteSuggestionUrls = new String[] {mTestServer.getURL(TEST_PAGE)}; |
77 | 77 |
| 78 mMostVisitedSites = new FakeMostVisitedSites(); |
| 79 mMostVisitedSites.setTileSuggestions(FAKE_MOST_VISITED_TITLES, mSiteSugg
estionUrls, |
| 80 FAKE_MOST_VISITED_WHITELIST_ICON_PATHS, FAKE_MOST_VISITED_SOURCE
S); |
| 81 TileGroupDelegateImpl.setMostVisitedSitesForTests(mMostVisitedSites); |
| 82 |
78 mSource = new FakeSuggestionsSource(); | 83 mSource = new FakeSuggestionsSource(); |
79 mSource.setInfoForCategory(TEST_CATEGORY, | 84 mSource.setInfoForCategory(TEST_CATEGORY, |
80 new SuggestionsCategoryInfo(TEST_CATEGORY, "Suggestions test tit
le", | 85 new SuggestionsCategoryInfo(TEST_CATEGORY, "Suggestions test tit
le", |
81 ContentSuggestionsCardLayout.FULL_CARD, /*hasFetchAction
=*/true, | 86 ContentSuggestionsCardLayout.FULL_CARD, /*hasFetchAction
=*/true, |
82 /*hasViewAllAction=*/false, /*showIfEmpty=*/true, "noSug
gestionsMessage")); | 87 /*hasViewAllAction=*/false, /*showIfEmpty=*/true, "noSug
gestionsMessage")); |
83 mSource.setStatusForCategory(TEST_CATEGORY, CategoryStatus.INITIALIZING)
; | 88 mSource.setStatusForCategory(TEST_CATEGORY, CategoryStatus.INITIALIZING)
; |
84 NewTabPage.setSuggestionsSourceForTests(mSource); | 89 NewTabPage.setSuggestionsSourceForTests(mSource); |
85 | 90 |
86 super.setUp(); | 91 super.setUp(); |
87 } | 92 } |
88 | 93 |
89 @Override | 94 @Override |
90 protected void tearDown() throws Exception { | 95 protected void tearDown() throws Exception { |
91 TileGroupDelegateImpl.setMostVisitedSitesForTests(null); | 96 TileGroupDelegateImpl.setMostVisitedSitesForTests(null); |
92 NewTabPage.setSuggestionsSourceForTests(null); | 97 NewTabPage.setSuggestionsSourceForTests(null); |
93 mTestServer.stopAndDestroyServer(); | 98 mTestServer.stopAndDestroyServer(); |
94 | 99 |
95 super.tearDown(); | 100 super.tearDown(); |
96 } | 101 } |
97 | 102 |
98 @Override | 103 @Override |
99 public void startMainActivity() throws InterruptedException { | 104 public void startMainActivity() throws InterruptedException { |
100 startMainActivityOnBlankPage(); | 105 startMainActivityWithURL(UrlConstants.NTP_URL); |
101 mTab = getActivity().getActivityTab(); | 106 mTab = getActivity().getActivityTab(); |
102 | |
103 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
104 @Override | |
105 public void run() { | |
106 // Create FakeMostVisitedSites after starting the activity, sinc
e it depends on | |
107 // native code. | |
108 mMostVisitedSites = new FakeMostVisitedSites(mTab.getProfile()); | |
109 mMostVisitedSites.setTileSuggestions(FAKE_MOST_VISITED_TITLES, m
SiteSuggestionUrls, | |
110 FAKE_MOST_VISITED_WHITELIST_ICON_PATHS, FAKE_MOST_VISITE
D_SOURCES); | |
111 } | |
112 }); | |
113 TileGroupDelegateImpl.setMostVisitedSitesForTests(mMostVisitedSites); | |
114 | |
115 loadUrl(UrlConstants.NTP_URL); | |
116 NewTabPageTestUtils.waitForNtpLoaded(mTab); | 107 NewTabPageTestUtils.waitForNtpLoaded(mTab); |
117 | 108 |
118 assertTrue(mTab.getNativePage() instanceof NewTabPage); | 109 assertTrue(mTab.getNativePage() instanceof NewTabPage); |
119 mNtp = (NewTabPage) mTab.getNativePage(); | 110 mNtp = (NewTabPage) mTab.getNativePage(); |
120 } | 111 } |
121 | 112 |
122 @MediumTest | 113 @MediumTest |
123 @Feature({"NewTabPage"}) | 114 @Feature({"NewTabPage"}) |
124 public void testClickSuggestion() throws InterruptedException { | 115 public void testClickSuggestion() throws InterruptedException { |
125 setSuggestionsAndWaitForUpdate(10); | 116 setSuggestionsAndWaitForUpdate(10); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 TestTouchUtils.longClickView(getInstrumentation(), view); | 407 TestTouchUtils.longClickView(getInstrumentation(), view); |
417 assertTrue( | 408 assertTrue( |
418 getInstrumentation().invokeContextMenuAction(getActivity(), cont
extMenuItemId, 0)); | 409 getInstrumentation().invokeContextMenuAction(getActivity(), cont
extMenuItemId, 0)); |
419 } | 410 } |
420 | 411 |
421 | 412 |
422 private static void assertArrayEquals(int[] expected, int[] actual) { | 413 private static void assertArrayEquals(int[] expected, int[] actual) { |
423 assertEquals(Arrays.toString(expected), Arrays.toString(actual)); | 414 assertEquals(Arrays.toString(expected), Arrays.toString(actual)); |
424 } | 415 } |
425 } | 416 } |
OLD | NEW |