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

Side by Side Diff: android_webview/javatests/src/org/chromium/android_webview/test/NavigationHistoryTest.java

Issue 11028094: [android_webview] Use AwContents loadUrl method instead of ContentViewCore. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase yet again Created 8 years, 2 months 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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.android_webview.test; 5 package org.chromium.android_webview.test;
6 6
7 import android.test.FlakyTest; 7 import android.test.FlakyTest;
8 import android.test.suitebuilder.annotation.SmallTest; 8 import android.test.suitebuilder.annotation.SmallTest;
9 9
10 import org.chromium.android_webview.AwContents;
10 import org.chromium.android_webview.test.util.CommonResources; 11 import org.chromium.android_webview.test.util.CommonResources;
11 import org.chromium.android_webview.test.util.TestWebServer; 12 import org.chromium.android_webview.test.util.TestWebServer;
12 import org.chromium.base.ThreadUtils; 13 import org.chromium.base.ThreadUtils;
13 import org.chromium.base.test.util.DisabledTest; 14 import org.chromium.base.test.util.DisabledTest;
14 import org.chromium.content.browser.ContentViewCore;
15 import org.chromium.content.browser.NavigationEntry; 15 import org.chromium.content.browser.NavigationEntry;
16 import org.chromium.content.browser.NavigationHistory; 16 import org.chromium.content.browser.NavigationHistory;
17 import org.chromium.content.browser.test.util.HistoryUtils; 17 import org.chromium.content.browser.test.util.HistoryUtils;
18 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; 18 import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
19 19
20 import java.util.concurrent.Callable; 20 import java.util.concurrent.Callable;
21 21
22 public class NavigationHistoryTest extends AndroidWebViewTestBase { 22 public class NavigationHistoryTest extends AndroidWebViewTestBase {
23 23
24 private TestAwContentsClient mContentsClient; 24 private TestAwContentsClient mContentsClient;
25 private ContentViewCore mContentViewCore; 25 private AwContents mAwContents;
26 26
27 @Override 27 @Override
28 public void setUp() throws Exception { 28 public void setUp() throws Exception {
29 super.setUp(); 29 super.setUp();
30 mContentsClient = new TestAwContentsClient(); 30 mContentsClient = new TestAwContentsClient();
31 mContentViewCore = 31 final AwTestContainerView testContainerView =
32 createAwTestContainerViewOnMainSync(mContentsClient).getContentV iewCore(); 32 createAwTestContainerViewOnMainSync(mContentsClient);
33 mAwContents = testContainerView.getAwContents();
33 } 34 }
34 35
35 private NavigationHistory getNavigationHistory(final ContentViewCore content ViewCore) 36 private NavigationHistory getNavigationHistory(final AwContents awContents)
36 throws Exception { 37 throws Exception {
37 return ThreadUtils.runOnUiThreadBlocking(new Callable<NavigationHistory> () { 38 return ThreadUtils.runOnUiThreadBlocking(new Callable<NavigationHistory> () {
38 @Override 39 @Override
39 public NavigationHistory call() { 40 public NavigationHistory call() {
40 return contentViewCore.getNavigationHistory(); 41 return awContents.getContentViewCore().getNavigationHistory();
41 } 42 }
42 }); 43 });
43 } 44 }
44 45
45 private void checkHistoryItem(NavigationEntry item, String url, String origi nalUrl, 46 private void checkHistoryItem(NavigationEntry item, String url, String origi nalUrl,
46 String title, boolean faviconNull) { 47 String title, boolean faviconNull) {
47 assertEquals(url, item.getUrl()); 48 assertEquals(url, item.getUrl());
48 assertEquals(originalUrl, item.getOriginalUrl()); 49 assertEquals(originalUrl, item.getOriginalUrl());
49 assertEquals(title, item.getTitle()); 50 assertEquals(title, item.getTitle());
50 if (faviconNull) { 51 if (faviconNull) {
51 assertNull(item.getFavicon()); 52 assertNull(item.getFavicon());
52 } else { 53 } else {
53 assertNotNull(item.getFavicon()); 54 assertNotNull(item.getFavicon());
54 } 55 }
55 } 56 }
56 57
57 /* 58 /*
58 * @SmallTest 59 * @SmallTest
59 * Bug 6776361 60 * Bug 6776361
60 */ 61 */
61 @FlakyTest 62 @FlakyTest
62 public void testNavigateOneUrl() throws Throwable { 63 public void testNavigateOneUrl() throws Throwable {
63 NavigationHistory history = getNavigationHistory(mContentViewCore); 64 NavigationHistory history = getNavigationHistory(mAwContents);
64 assertEquals(0, history.getEntryCount()); 65 assertEquals(0, history.getEntryCount());
65 66
66 loadUrlSync(mContentViewCore, mContentsClient.getOnPageFinishedHelper(), 67 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
67 "chrome://newtab/"); 68 "chrome://newtab/");
68 history = getNavigationHistory(mContentViewCore); 69 history = getNavigationHistory(mAwContents);
69 checkHistoryItem(history.getEntryAtIndex(0), 70 checkHistoryItem(history.getEntryAtIndex(0),
70 "chrome://newtab/#bookmarks", 71 "chrome://newtab/#bookmarks",
71 "chrome://newtab/", 72 "chrome://newtab/",
72 "New tab", 73 "New tab",
73 true); 74 true);
74 75
75 assertEquals(0, history.getCurrentEntryIndex()); 76 assertEquals(0, history.getCurrentEntryIndex());
76 } 77 }
77 78
78 @SmallTest 79 @SmallTest
79 public void testNavigateTwoUrls() throws Throwable { 80 public void testNavigateTwoUrls() throws Throwable {
80 NavigationHistory list = getNavigationHistory(mContentViewCore); 81 NavigationHistory list = getNavigationHistory(mAwContents);
81 assertEquals(0, list.getEntryCount()); 82 assertEquals(0, list.getEntryCount());
82 83
83 final TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHel per = 84 final TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHel per =
84 mContentsClient.getOnPageFinishedHelper(); 85 mContentsClient.getOnPageFinishedHelper();
85 loadUrlSync(mContentViewCore, onPageFinishedHelper, "chrome://newtab/"); 86 loadUrlSync(mAwContents, onPageFinishedHelper, "chrome://newtab/");
86 loadUrlSync(mContentViewCore, onPageFinishedHelper, "chrome://version"); 87 loadUrlSync(mAwContents, onPageFinishedHelper, "chrome://version");
87 88
88 list = getNavigationHistory(mContentViewCore); 89 list = getNavigationHistory(mAwContents);
89 90
90 // Make sure there is a new entry entry the list 91 // Make sure there is a new entry entry the list
91 assertEquals(2, list.getEntryCount()); 92 assertEquals(2, list.getEntryCount());
92 93
93 // Make sure the first entry is still okay 94 // Make sure the first entry is still okay
94 checkHistoryItem(list.getEntryAtIndex(0), 95 checkHistoryItem(list.getEntryAtIndex(0),
95 "chrome://newtab/#bookmarks", 96 "chrome://newtab/#bookmarks",
96 "chrome://newtab/", 97 "chrome://newtab/",
97 "New tab", 98 "New tab",
98 true); 99 true);
99 100
100 // Make sure the second entry was added properly 101 // Make sure the second entry was added properly
101 checkHistoryItem(list.getEntryAtIndex(1), 102 checkHistoryItem(list.getEntryAtIndex(1),
102 "chrome://version/", 103 "chrome://version/",
103 "chrome://version/", 104 "chrome://version/",
104 "About Version", 105 "About Version",
105 true); 106 true);
106 107
107 assertEquals(1, list.getCurrentEntryIndex()); 108 assertEquals(1, list.getCurrentEntryIndex());
108 109
109 } 110 }
110 111
111 @SmallTest 112 @SmallTest
112 public void testNavigateTwoUrlsAndBack() throws Throwable { 113 public void testNavigateTwoUrlsAndBack() throws Throwable {
113 final TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHel per = 114 final TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHel per =
114 mContentsClient.getOnPageFinishedHelper(); 115 mContentsClient.getOnPageFinishedHelper();
115 NavigationHistory list = getNavigationHistory(mContentViewCore); 116 NavigationHistory list = getNavigationHistory(mAwContents);
116 assertEquals(0, list.getEntryCount()); 117 assertEquals(0, list.getEntryCount());
117 118
118 loadUrlSync(mContentViewCore, onPageFinishedHelper, "chrome://newtab/"); 119 loadUrlSync(mAwContents, onPageFinishedHelper, "chrome://newtab/");
119 loadUrlSync(mContentViewCore, onPageFinishedHelper, "chrome://version"); 120 loadUrlSync(mAwContents, onPageFinishedHelper, "chrome://version");
120 HistoryUtils.goBackSync(getInstrumentation(), mContentViewCore, onPageFi nishedHelper); 121 HistoryUtils.goBackSync(getInstrumentation(), mAwContents.getContentView Core(),
121 list = getNavigationHistory(mContentViewCore); 122 onPageFinishedHelper);
123 list = getNavigationHistory(mAwContents);
122 124
123 // Make sure the first entry is still okay 125 // Make sure the first entry is still okay
124 checkHistoryItem(list.getEntryAtIndex(0), 126 checkHistoryItem(list.getEntryAtIndex(0),
125 "chrome://newtab/#bookmarks", 127 "chrome://newtab/#bookmarks",
126 "chrome://newtab/", 128 "chrome://newtab/",
127 "New tab", 129 "New tab",
128 true); 130 true);
129 131
130 // Make sure the second entry is still okay 132 // Make sure the second entry is still okay
131 checkHistoryItem(list.getEntryAtIndex(1), 133 checkHistoryItem(list.getEntryAtIndex(1),
132 "chrome://version/", 134 "chrome://version/",
133 "chrome://version/", 135 "chrome://version/",
134 "About Version", 136 "About Version",
135 true); 137 true);
136 138
137 // Make sure the current index is back to 0 139 // Make sure the current index is back to 0
138 assertEquals(0, list.getCurrentEntryIndex()); 140 assertEquals(0, list.getCurrentEntryIndex());
139 } 141 }
140 142
141 /** 143 /**
142 * Disabled until favicons are getting fetched when using ContentView. 144 * Disabled until favicons are getting fetched when using ContentView.
143 * 145 *
144 * @SmallTest 146 * @SmallTest
145 * @throws Throwable 147 * @throws Throwable
146 */ 148 */
147 @DisabledTest 149 @DisabledTest
148 public void testFavicon() throws Throwable { 150 public void testFavicon() throws Throwable {
149 NavigationHistory list = getNavigationHistory(mContentViewCore); 151 NavigationHistory list = getNavigationHistory(mAwContents);
150 String url; 152 String url;
151 153
152 TestWebServer webServer = null; 154 TestWebServer webServer = null;
153 try { 155 try {
154 webServer = new TestWebServer(false); 156 webServer = new TestWebServer(false);
155 157
156 webServer.setResponseBase64("/" + CommonResources.FAVICON_FILENAME, 158 webServer.setResponseBase64("/" + CommonResources.FAVICON_FILENAME,
157 CommonResources.FAVICON_DATA_BASE64, CommonResources.getImag ePngHeaders(false)); 159 CommonResources.FAVICON_DATA_BASE64, CommonResources.getImag ePngHeaders(false));
158 url = webServer.setResponse("/favicon.html", CommonResources.FAVICON _STATIC_HTML, null); 160 url = webServer.setResponse("/favicon.html", CommonResources.FAVICON _STATIC_HTML, null);
159 161
160 assertEquals(0, list.getEntryCount()); 162 assertEquals(0, list.getEntryCount());
161 getContentSettingsOnUiThread(mContentViewCore).setImagesEnabled(true ); 163 getContentSettingsOnUiThread(mAwContents).setImagesEnabled(true);
162 loadUrlSync(mContentViewCore, mContentsClient.getOnPageFinishedHelpe r(), url); 164 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url);
163 165
164 } finally { 166 } finally {
165 if (webServer != null) webServer.shutdown(); 167 if (webServer != null) webServer.shutdown();
166 } 168 }
167 169
168 list = getNavigationHistory(mContentViewCore); 170 list = getNavigationHistory(mAwContents);
169 171
170 // Make sure the first entry is still okay. 172 // Make sure the first entry is still okay.
171 checkHistoryItem(list.getEntryAtIndex(0), url, url, "", false); 173 checkHistoryItem(list.getEntryAtIndex(0), url, url, "", false);
172 } 174 }
173 } 175 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698