| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser; | |
| 6 | |
| 7 import android.graphics.Bitmap; | |
| 8 import android.test.suitebuilder.annotation.MediumTest; | |
| 9 import android.test.suitebuilder.annotation.SmallTest; | |
| 10 | |
| 11 import org.chromium.base.ThreadUtils; | |
| 12 import org.chromium.base.test.util.Feature; | |
| 13 import org.chromium.base.test.util.UrlUtils; | |
| 14 import org.chromium.chrome.shell.ChromeShellActivity; | |
| 15 import org.chromium.chrome.shell.ChromeShellTestBase; | |
| 16 import org.chromium.content.browser.test.util.Criteria; | |
| 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; | |
| 20 import org.chromium.content_public.browser.NavigationEntry; | |
| 21 import org.chromium.content_public.browser.NavigationHistory; | |
| 22 | |
| 23 import java.util.concurrent.Callable; | |
| 24 import java.util.concurrent.ExecutionException; | |
| 25 | |
| 26 /** | |
| 27 * Tests for the navigation popup. | |
| 28 */ | |
| 29 public class NavigationPopupTest extends ChromeShellTestBase { | |
| 30 | |
| 31 private static final int INVALID_NAVIGATION_INDEX = -1; | |
| 32 | |
| 33 private ChromeShellActivity mActivity; | |
| 34 | |
| 35 @Override | |
| 36 public void setUp() throws Exception { | |
| 37 super.setUp(); | |
| 38 | |
| 39 mActivity = launchChromeShellWithBlankPage(); | |
| 40 } | |
| 41 | |
| 42 // Exists solely to expose protected methods to this test. | |
| 43 private static class TestNavigationHistory extends NavigationHistory { | |
| 44 @Override | |
| 45 public void addEntry(NavigationEntry entry) { | |
| 46 super.addEntry(entry); | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 // Exists solely to expose protected methods to this test. | |
| 51 private static class TestNavigationEntry extends NavigationEntry { | |
| 52 public TestNavigationEntry(int index, String url, String virtualUrl, Str
ing originalUrl, | |
| 53 String title, Bitmap favicon, int transition) { | |
| 54 super(index, url, virtualUrl, originalUrl, title, favicon, transitio
n); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 private static class TestNavigationController implements NavigationControlle
r { | |
| 59 private final TestNavigationHistory mHistory; | |
| 60 private int mNavigatedIndex = INVALID_NAVIGATION_INDEX; | |
| 61 | |
| 62 public TestNavigationController() { | |
| 63 mHistory = new TestNavigationHistory(); | |
| 64 mHistory.addEntry(new TestNavigationEntry( | |
| 65 1, "about:blank", null, null, "About Blank", null, 0)); | |
| 66 mHistory.addEntry(new TestNavigationEntry( | |
| 67 5, UrlUtils.encodeHtmlDataUri("<html>1</html>"), null, null,
null, null, 0)); | |
| 68 } | |
| 69 | |
| 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 boolean isInitialNavigation() { | |
| 99 return false; | |
| 100 } | |
| 101 | |
| 102 @Override | |
| 103 public void loadIfNecessary() { | |
| 104 } | |
| 105 | |
| 106 @Override | |
| 107 public void requestRestoreLoad() { | |
| 108 } | |
| 109 | |
| 110 @Override | |
| 111 public void reload(boolean checkForRepost) { | |
| 112 } | |
| 113 | |
| 114 @Override | |
| 115 public void reloadIgnoringCache(boolean checkForRepost) { | |
| 116 } | |
| 117 | |
| 118 @Override | |
| 119 public void cancelPendingReload() { | |
| 120 } | |
| 121 | |
| 122 @Override | |
| 123 public void continuePendingReload() { | |
| 124 } | |
| 125 | |
| 126 @Override | |
| 127 public void loadUrl(LoadUrlParams params) { | |
| 128 } | |
| 129 | |
| 130 @Override | |
| 131 public void clearHistory() { | |
| 132 } | |
| 133 | |
| 134 @Override | |
| 135 public NavigationHistory getNavigationHistory() { | |
| 136 return null; | |
| 137 } | |
| 138 | |
| 139 @Override | |
| 140 public String getOriginalUrlForVisibleNavigationEntry() { | |
| 141 return null; | |
| 142 } | |
| 143 | |
| 144 @Override | |
| 145 public void clearSslPreferences() { | |
| 146 } | |
| 147 | |
| 148 @Override | |
| 149 public boolean getUseDesktopUserAgent() { | |
| 150 return false; | |
| 151 } | |
| 152 | |
| 153 @Override | |
| 154 public void setUseDesktopUserAgent(boolean override, boolean reloadOnCha
nge) { | |
| 155 } | |
| 156 | |
| 157 @Override | |
| 158 public NavigationEntry getEntryAtIndex(int index) { | |
| 159 return null; | |
| 160 } | |
| 161 | |
| 162 @Override | |
| 163 public NavigationEntry getPendingEntry() { | |
| 164 return null; | |
| 165 } | |
| 166 | |
| 167 @Override | |
| 168 public NavigationHistory getDirectedNavigationHistory(boolean isForward,
int itemLimit) { | |
| 169 return mHistory; | |
| 170 } | |
| 171 | |
| 172 @Override | |
| 173 public void goToNavigationIndex(int index) { | |
| 174 mNavigatedIndex = index; | |
| 175 } | |
| 176 | |
| 177 @Override | |
| 178 public int getLastCommittedEntryIndex() { | |
| 179 return -1; | |
| 180 } | |
| 181 | |
| 182 @Override | |
| 183 public boolean removeEntryAtIndex(int index) { | |
| 184 return false; | |
| 185 } | |
| 186 | |
| 187 @Override | |
| 188 public boolean canCopyStateOver() { | |
| 189 return false; | |
| 190 } | |
| 191 | |
| 192 @Override | |
| 193 public boolean canPruneAllButLastCommitted() { | |
| 194 return false; | |
| 195 } | |
| 196 | |
| 197 @Override | |
| 198 public void copyStateFrom(NavigationController source) { | |
| 199 } | |
| 200 | |
| 201 @Override | |
| 202 public void copyStateFromAndPrune(NavigationController source, boolean r
eplaceEntry) { | |
| 203 } | |
| 204 } | |
| 205 | |
| 206 @MediumTest | |
| 207 @Feature({"Navigation"}) | |
| 208 public void testFaviconFetching() throws InterruptedException { | |
| 209 final TestNavigationController controller = new TestNavigationController
(); | |
| 210 final NavigationPopup popup = new NavigationPopup( | |
| 211 mActivity, controller, true); | |
| 212 popup.setWidth(300); | |
| 213 popup.setAnchorView(mActivity.getActiveContentViewCore().getContainerVie
w()); | |
| 214 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
| 215 @Override | |
| 216 public void run() { | |
| 217 popup.show(); | |
| 218 } | |
| 219 }); | |
| 220 | |
| 221 assertTrue("All favicons did not get updated.", | |
| 222 CriteriaHelper.pollForCriteria(new Criteria() { | |
| 223 @Override | |
| 224 public boolean isSatisfied() { | |
| 225 try { | |
| 226 return ThreadUtils.runOnUiThreadBlocking(new Callabl
e<Boolean>() { | |
| 227 @Override | |
| 228 public Boolean call() throws Exception { | |
| 229 NavigationHistory history = controller.mHist
ory; | |
| 230 for (int i = 0; i < history.getEntryCount();
i++) { | |
| 231 if (history.getEntryAtIndex(i).getFavico
n() == null) { | |
| 232 return false; | |
| 233 } | |
| 234 } | |
| 235 return true; | |
| 236 } | |
| 237 }); | |
| 238 } catch (ExecutionException e) { | |
| 239 return false; | |
| 240 } | |
| 241 } | |
| 242 })); | |
| 243 | |
| 244 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
| 245 @Override | |
| 246 public void run() { | |
| 247 popup.dismiss(); | |
| 248 } | |
| 249 }); | |
| 250 } | |
| 251 | |
| 252 @SmallTest | |
| 253 @Feature({"Navigation"}) | |
| 254 public void testItemSelection() { | |
| 255 final TestNavigationController controller = new TestNavigationController
(); | |
| 256 final NavigationPopup popup = new NavigationPopup( | |
| 257 mActivity, controller, true); | |
| 258 popup.setWidth(300); | |
| 259 popup.setAnchorView(mActivity.getActiveContentViewCore().getContainerVie
w()); | |
| 260 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
| 261 @Override | |
| 262 public void run() { | |
| 263 popup.show(); | |
| 264 } | |
| 265 }); | |
| 266 | |
| 267 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
| 268 @Override | |
| 269 public void run() { | |
| 270 popup.performItemClick(1); | |
| 271 } | |
| 272 }); | |
| 273 | |
| 274 assertFalse("Popup did not hide as expected.", popup.isShowing()); | |
| 275 assertEquals("Popup attempted to navigate to the wrong index", 5, | |
| 276 controller.mNavigatedIndex); | |
| 277 } | |
| 278 | |
| 279 } | |
| OLD | NEW |