Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 | |
|
Ted C
2014/10/23 16:23:27
remove extra blank line
AKVT
2014/10/23 16:39:24
Done.
| |
| 134 | |
| 135 @Override | |
| 136 public String getOriginalUrlForVisibleNavigationEntry() { | |
| 137 return null; | |
| 138 } | |
| 139 | |
| 140 @Override | |
| 141 public void clearSslPreferences() { | |
| 142 } | |
| 143 | |
| 144 @Override | |
| 145 public boolean getUseDesktopUserAgent() { | |
| 146 return false; | |
| 147 } | |
| 148 | |
| 149 @Override | |
| 150 public void setUseDesktopUserAgent(boolean override, boolean reloadOnCha nge) { | |
| 151 } | |
| 152 | |
| 153 @Override | |
| 154 public NavigationEntry getPendingEntry() { | |
| 155 return null; | |
| 156 } | |
| 157 | |
| 158 @Override | |
| 70 public NavigationHistory getDirectedNavigationHistory(boolean isForward, int itemLimit) { | 159 public NavigationHistory getDirectedNavigationHistory(boolean isForward, int itemLimit) { |
| 71 return mHistory; | 160 return mHistory; |
| 72 } | 161 } |
| 73 | 162 |
| 74 @Override | 163 @Override |
| 75 public void goToNavigationIndex(int index) { | 164 public void goToNavigationIndex(int index) { |
| 76 mNavigatedIndex = index; | 165 mNavigatedIndex = index; |
| 77 } | 166 } |
| 78 } | 167 } |
| 79 | 168 |
| 80 @MediumTest | 169 @MediumTest |
| 81 @Feature({"Navigation"}) | 170 @Feature({"Navigation"}) |
| 82 public void testFaviconFetching() throws InterruptedException { | 171 public void testFaviconFetching() throws InterruptedException { |
| 83 final TestNavigationClient client = new TestNavigationClient(); | 172 final TestNavigationController controller = new TestNavigationController (); |
| 84 final NavigationPopup popup = new NavigationPopup( | 173 final NavigationPopup popup = new NavigationPopup( |
| 85 mActivity, client, true); | 174 mActivity, controller, true); |
| 86 popup.setWidth(300); | 175 popup.setWidth(300); |
| 87 popup.setAnchorView(mActivity.getActiveContentViewCore().getContainerVie w()); | 176 popup.setAnchorView(mActivity.getActiveContentViewCore().getContainerVie w()); |
| 88 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 177 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 89 @Override | 178 @Override |
| 90 public void run() { | 179 public void run() { |
| 91 popup.show(); | 180 popup.show(); |
| 92 } | 181 } |
| 93 }); | 182 }); |
| 94 | 183 |
| 95 assertTrue("All favicons did not get updated.", | 184 assertTrue("All favicons did not get updated.", |
| 96 CriteriaHelper.pollForCriteria(new Criteria() { | 185 CriteriaHelper.pollForCriteria(new Criteria() { |
| 97 @Override | 186 @Override |
| 98 public boolean isSatisfied() { | 187 public boolean isSatisfied() { |
| 99 try { | 188 try { |
| 100 return ThreadUtils.runOnUiThreadBlocking(new Callabl e<Boolean>() { | 189 return ThreadUtils.runOnUiThreadBlocking(new Callabl e<Boolean>() { |
| 101 @Override | 190 @Override |
| 102 public Boolean call() throws Exception { | 191 public Boolean call() throws Exception { |
| 103 NavigationHistory history = client.mHistory; | 192 NavigationHistory history = controller.mHist ory; |
| 104 for (int i = 0; i < history.getEntryCount(); i++) { | 193 for (int i = 0; i < history.getEntryCount(); i++) { |
| 105 if (history.getEntryAtIndex(i).getFavico n() == null) { | 194 if (history.getEntryAtIndex(i).getFavico n() == null) { |
| 106 return false; | 195 return false; |
| 107 } | 196 } |
| 108 } | 197 } |
| 109 return true; | 198 return true; |
| 110 } | 199 } |
| 111 }); | 200 }); |
| 112 } catch (ExecutionException e) { | 201 } catch (ExecutionException e) { |
| 113 return false; | 202 return false; |
| 114 } | 203 } |
| 115 } | 204 } |
| 116 })); | 205 })); |
| 117 | 206 |
| 118 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 207 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 119 @Override | 208 @Override |
| 120 public void run() { | 209 public void run() { |
| 121 popup.dismiss(); | 210 popup.dismiss(); |
| 122 } | 211 } |
| 123 }); | 212 }); |
| 124 } | 213 } |
| 125 | 214 |
| 126 @SmallTest | 215 @SmallTest |
| 127 @Feature({"Navigation"}) | 216 @Feature({"Navigation"}) |
| 128 public void testItemSelection() { | 217 public void testItemSelection() { |
| 129 final TestNavigationClient client = new TestNavigationClient(); | 218 final TestNavigationController controller = new TestNavigationController (); |
| 130 final NavigationPopup popup = new NavigationPopup( | 219 final NavigationPopup popup = new NavigationPopup( |
| 131 mActivity, client, true); | 220 mActivity, controller, true); |
| 132 popup.setWidth(300); | 221 popup.setWidth(300); |
| 133 popup.setAnchorView(mActivity.getActiveContentViewCore().getContainerVie w()); | 222 popup.setAnchorView(mActivity.getActiveContentViewCore().getContainerVie w()); |
| 134 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 223 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 135 @Override | 224 @Override |
| 136 public void run() { | 225 public void run() { |
| 137 popup.show(); | 226 popup.show(); |
| 138 } | 227 } |
| 139 }); | 228 }); |
| 140 | 229 |
| 141 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 230 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 142 @Override | 231 @Override |
| 143 public void run() { | 232 public void run() { |
| 144 popup.performItemClick(1); | 233 popup.performItemClick(1); |
| 145 } | 234 } |
| 146 }); | 235 }); |
| 147 | 236 |
| 148 assertFalse("Popup did not hide as expected.", popup.isShowing()); | 237 assertFalse("Popup did not hide as expected.", popup.isShowing()); |
| 149 assertEquals("Popup attempted to navigate to the wrong index", 5, client .mNavigatedIndex); | 238 assertEquals("Popup attempted to navigate to the wrong index", 5, |
| 239 controller.mNavigatedIndex); | |
| 150 } | 240 } |
| 151 | 241 |
| 152 } | 242 } |
| OLD | NEW |