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