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

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

Issue 666673009: Removing NavigationClient dependencies from Tab. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the review comments. Created 6 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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; 5 package org.chromium.chrome.browser;
6 6
7 import android.graphics.Bitmap; 7 import android.graphics.Bitmap;
8 import android.test.suitebuilder.annotation.MediumTest; 8 import android.test.suitebuilder.annotation.MediumTest;
9 import android.test.suitebuilder.annotation.SmallTest; 9 import android.test.suitebuilder.annotation.SmallTest;
10 10
11 import org.chromium.base.ThreadUtils; 11 import org.chromium.base.ThreadUtils;
12 import org.chromium.base.test.util.Feature; 12 import org.chromium.base.test.util.Feature;
13 import org.chromium.base.test.util.UrlUtils; 13 import org.chromium.base.test.util.UrlUtils;
14 import org.chromium.chrome.shell.ChromeShellActivity; 14 import org.chromium.chrome.shell.ChromeShellActivity;
15 import org.chromium.chrome.shell.ChromeShellTestBase; 15 import org.chromium.chrome.shell.ChromeShellTestBase;
16 import org.chromium.content.browser.NavigationClient;
17 import org.chromium.content.browser.test.util.Criteria; 16 import org.chromium.content.browser.test.util.Criteria;
18 import org.chromium.content.browser.test.util.CriteriaHelper; 17 import org.chromium.content.browser.test.util.CriteriaHelper;
18 import org.chromium.content_public.browser.LoadUrlParams;
19 import org.chromium.content_public.browser.NavigationController;
19 import org.chromium.content_public.browser.NavigationEntry; 20 import org.chromium.content_public.browser.NavigationEntry;
20 import org.chromium.content_public.browser.NavigationHistory; 21 import org.chromium.content_public.browser.NavigationHistory;
21 22
22 import java.util.concurrent.Callable; 23 import java.util.concurrent.Callable;
23 import java.util.concurrent.ExecutionException; 24 import java.util.concurrent.ExecutionException;
24 25
25 /** 26 /**
26 * Tests for the navigation popup. 27 * Tests for the navigation popup.
27 */ 28 */
28 public class NavigationPopupTest extends ChromeShellTestBase { 29 public class NavigationPopupTest extends ChromeShellTestBase {
(...skipping 18 matching lines...) Expand all
47 } 48 }
48 49
49 // Exists solely to expose protected methods to this test. 50 // Exists solely to expose protected methods to this test.
50 private static class TestNavigationEntry extends NavigationEntry { 51 private static class TestNavigationEntry extends NavigationEntry {
51 public TestNavigationEntry(int index, String url, String virtualUrl, Str ing originalUrl, 52 public TestNavigationEntry(int index, String url, String virtualUrl, Str ing originalUrl,
52 String title, Bitmap favicon) { 53 String title, Bitmap favicon) {
53 super(index, url, virtualUrl, originalUrl, title, favicon); 54 super(index, url, virtualUrl, originalUrl, title, favicon);
54 } 55 }
55 } 56 }
56 57
57 private static class TestNavigationClient implements NavigationClient { 58 private static class TestNavigationController implements NavigationControlle r {
58 private TestNavigationHistory mHistory; 59 private TestNavigationHistory mHistory;
59 private int mNavigatedIndex = INVALID_NAVIGATION_INDEX; 60 private int mNavigatedIndex = INVALID_NAVIGATION_INDEX;
60 61
61 public TestNavigationClient() { 62 public TestNavigationController() {
62 mHistory = new TestNavigationHistory(); 63 mHistory = new TestNavigationHistory();
63 mHistory.addEntry(new TestNavigationEntry( 64 mHistory.addEntry(new TestNavigationEntry(
64 1, "about:blank", null, null, "About Blank", null)); 65 1, "about:blank", null, null, "About Blank", null));
65 mHistory.addEntry(new TestNavigationEntry( 66 mHistory.addEntry(new TestNavigationEntry(
66 5, UrlUtils.encodeHtmlDataUri("<html>1</html>"), null, null, null, null)); 67 5, UrlUtils.encodeHtmlDataUri("<html>1</html>"), null, null, null, null));
67 } 68 }
68 69
69 @Override 70 @Override
71 public boolean canGoBack() {
72 return false;
73 }
74
75 @Override
76 public boolean canGoForward() {
77 return false;
78 }
79
80 @Override
81 public boolean canGoToOffset(int offset) {
82 return false;
83 }
84
85 @Override
86 public void goToOffset(int offset) {
87 }
88
89 @Override
90 public void goBack() {
91 }
92
93 @Override
94 public void goForward() {
95 }
96
97 @Override
98 public void loadIfNecessary() {
99 }
100
101 @Override
102 public void requestRestoreLoad() {
103 }
104
105 @Override
106 public void reload(boolean checkForRepost) {
107 }
108
109 @Override
110 public void reloadIgnoringCache(boolean checkForRepost) {
111 }
112
113 @Override
114 public void cancelPendingReload() {
115 }
116
117 @Override
118 public void continuePendingReload() {
119 }
120
121 @Override
122 public void loadUrl(LoadUrlParams params) {
123 }
124
125 @Override
126 public void clearHistory() {
127 }
128
129 @Override
130 public NavigationHistory getNavigationHistory() {
131 return null;
132 }
133
134 @Override
135 public String getOriginalUrlForVisibleNavigationEntry() {
136 return null;
137 }
138
139 @Override
140 public void clearSslPreferences() {
141 }
142
143 @Override
144 public boolean getUseDesktopUserAgent() {
145 return false;
146 }
147
148 @Override
149 public void setUseDesktopUserAgent(boolean override, boolean reloadOnCha nge) {
150 }
151
152 @Override
153 public NavigationEntry getPendingEntry() {
154 return null;
155 }
156
157 @Override
70 public NavigationHistory getDirectedNavigationHistory(boolean isForward, int itemLimit) { 158 public NavigationHistory getDirectedNavigationHistory(boolean isForward, int itemLimit) {
71 return mHistory; 159 return mHistory;
72 } 160 }
73 161
74 @Override 162 @Override
75 public void goToNavigationIndex(int index) { 163 public void goToNavigationIndex(int index) {
76 mNavigatedIndex = index; 164 mNavigatedIndex = index;
77 } 165 }
78 } 166 }
79 167
80 @MediumTest 168 @MediumTest
81 @Feature({"Navigation"}) 169 @Feature({"Navigation"})
82 public void testFaviconFetching() throws InterruptedException { 170 public void testFaviconFetching() throws InterruptedException {
83 final TestNavigationClient client = new TestNavigationClient(); 171 final TestNavigationController controller = new TestNavigationController ();
84 final NavigationPopup popup = new NavigationPopup( 172 final NavigationPopup popup = new NavigationPopup(
85 mActivity, client, true); 173 mActivity, controller, true);
86 popup.setWidth(300); 174 popup.setWidth(300);
87 popup.setAnchorView(mActivity.getActiveContentViewCore().getContainerVie w()); 175 popup.setAnchorView(mActivity.getActiveContentViewCore().getContainerVie w());
88 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 176 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
89 @Override 177 @Override
90 public void run() { 178 public void run() {
91 popup.show(); 179 popup.show();
92 } 180 }
93 }); 181 });
94 182
95 assertTrue("All favicons did not get updated.", 183 assertTrue("All favicons did not get updated.",
96 CriteriaHelper.pollForCriteria(new Criteria() { 184 CriteriaHelper.pollForCriteria(new Criteria() {
97 @Override 185 @Override
98 public boolean isSatisfied() { 186 public boolean isSatisfied() {
99 try { 187 try {
100 return ThreadUtils.runOnUiThreadBlocking(new Callabl e<Boolean>() { 188 return ThreadUtils.runOnUiThreadBlocking(new Callabl e<Boolean>() {
101 @Override 189 @Override
102 public Boolean call() throws Exception { 190 public Boolean call() throws Exception {
103 NavigationHistory history = client.mHistory; 191 NavigationHistory history = controller.mHist ory;
104 for (int i = 0; i < history.getEntryCount(); i++) { 192 for (int i = 0; i < history.getEntryCount(); i++) {
105 if (history.getEntryAtIndex(i).getFavico n() == null) { 193 if (history.getEntryAtIndex(i).getFavico n() == null) {
106 return false; 194 return false;
107 } 195 }
108 } 196 }
109 return true; 197 return true;
110 } 198 }
111 }); 199 });
112 } catch (ExecutionException e) { 200 } catch (ExecutionException e) {
113 return false; 201 return false;
114 } 202 }
115 } 203 }
116 })); 204 }));
117 205
118 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 206 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
119 @Override 207 @Override
120 public void run() { 208 public void run() {
121 popup.dismiss(); 209 popup.dismiss();
122 } 210 }
123 }); 211 });
124 } 212 }
125 213
126 @SmallTest 214 @SmallTest
127 @Feature({"Navigation"}) 215 @Feature({"Navigation"})
128 public void testItemSelection() { 216 public void testItemSelection() {
129 final TestNavigationClient client = new TestNavigationClient(); 217 final TestNavigationController controller = new TestNavigationController ();
130 final NavigationPopup popup = new NavigationPopup( 218 final NavigationPopup popup = new NavigationPopup(
131 mActivity, client, true); 219 mActivity, controller, true);
132 popup.setWidth(300); 220 popup.setWidth(300);
133 popup.setAnchorView(mActivity.getActiveContentViewCore().getContainerVie w()); 221 popup.setAnchorView(mActivity.getActiveContentViewCore().getContainerVie w());
134 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 222 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
135 @Override 223 @Override
136 public void run() { 224 public void run() {
137 popup.show(); 225 popup.show();
138 } 226 }
139 }); 227 });
140 228
141 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 229 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
142 @Override 230 @Override
143 public void run() { 231 public void run() {
144 popup.performItemClick(1); 232 popup.performItemClick(1);
145 } 233 }
146 }); 234 });
147 235
148 assertFalse("Popup did not hide as expected.", popup.isShowing()); 236 assertFalse("Popup did not hide as expected.", popup.isShowing());
149 assertEquals("Popup attempted to navigate to the wrong index", 5, client .mNavigatedIndex); 237 assertEquals("Popup attempted to navigate to the wrong index", 5,
238 controller.mNavigatedIndex);
150 } 239 }
151 240
152 } 241 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698