OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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.graphics.Bitmap; | 7 import android.graphics.Bitmap; |
8 import android.support.test.filters.SmallTest; | 8 import android.support.test.filters.SmallTest; |
9 | 9 |
10 import org.chromium.android_webview.AwContents; | 10 import org.chromium.android_webview.AwContents; |
11 import org.chromium.android_webview.AwSettings; | 11 import org.chromium.android_webview.AwSettings; |
12 import org.chromium.android_webview.test.util.CommonResources; | 12 import org.chromium.android_webview.test.util.CommonResources; |
13 import org.chromium.base.test.util.Feature; | 13 import org.chromium.base.test.util.Feature; |
14 import org.chromium.base.test.util.Restriction; | 14 import org.chromium.base.test.util.Restriction; |
15 import org.chromium.content.browser.test.util.HistoryUtils; | 15 import org.chromium.content.browser.test.util.HistoryUtils; |
16 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; | 16 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; |
17 import org.chromium.content_public.browser.WebContents; | 17 import org.chromium.content_public.browser.WebContents; |
| 18 import org.chromium.content_public.common.ContentUrlConstants; |
18 import org.chromium.net.test.util.TestWebServer; | 19 import org.chromium.net.test.util.TestWebServer; |
19 | 20 |
20 import java.io.File; | 21 import java.io.File; |
21 import java.io.FileOutputStream; | 22 import java.io.FileOutputStream; |
22 import java.util.concurrent.Callable; | 23 import java.util.concurrent.Callable; |
23 | 24 |
24 /** | 25 /** |
25 * Tests for the {@link android.webkit.WebView#loadDataWithBaseURL(String, Strin
g, String, String, | 26 * Tests for the {@link android.webkit.WebView#loadDataWithBaseURL(String, Strin
g, String, String, |
26 * String)} method. | 27 * String)} method. |
27 */ | 28 */ |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 161 } |
161 } | 162 } |
162 | 163 |
163 @SmallTest | 164 @SmallTest |
164 @Feature({"AndroidWebView"}) | 165 @Feature({"AndroidWebView"}) |
165 public void testNullBaseUrl() throws Throwable { | 166 public void testNullBaseUrl() throws Throwable { |
166 getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true); | 167 getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true); |
167 final String pageHtml = "<html><body onload='document.title=document.loc
ation.href'>" | 168 final String pageHtml = "<html><body onload='document.title=document.loc
ation.href'>" |
168 + "</body></html>"; | 169 + "</body></html>"; |
169 loadDataWithBaseUrlSync(pageHtml, "text/html", false, null, null); | 170 loadDataWithBaseUrlSync(pageHtml, "text/html", false, null, null); |
170 assertEquals("about:blank", getTitleOnUiThread(mAwContents)); | 171 assertEquals(ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL, getTitleOnUiTh
read(mAwContents)); |
171 } | 172 } |
172 | 173 |
173 @SmallTest | 174 @SmallTest |
174 @Feature({"AndroidWebView"}) | 175 @Feature({"AndroidWebView"}) |
175 public void testInvalidBaseUrl() throws Throwable { | 176 public void testInvalidBaseUrl() throws Throwable { |
176 final String invalidBaseUrl = "http://"; | 177 final String invalidBaseUrl = "http://"; |
177 getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true); | 178 getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true); |
178 loadDataWithBaseUrlSync( | 179 loadDataWithBaseUrlSync( |
179 CommonResources.ABOUT_HTML, "text/html", false, invalidBaseUrl,
null); | 180 CommonResources.ABOUT_HTML, "text/html", false, invalidBaseUrl,
null); |
180 // Verify that the load succeeds. The actual base url is undefined. | 181 // Verify that the load succeeds. The actual base url is undefined. |
181 assertEquals(CommonResources.ABOUT_TITLE, getTitleOnUiThread(mAwContents
)); | 182 assertEquals(CommonResources.ABOUT_TITLE, getTitleOnUiThread(mAwContents
)); |
182 } | 183 } |
183 | 184 |
184 @SmallTest | 185 @SmallTest |
185 @Feature({"AndroidWebView"}) | 186 @Feature({"AndroidWebView"}) |
186 public void testloadDataWithBaseUrlCallsOnPageStarted() throws Throwable { | 187 public void testloadDataWithBaseUrlCallsOnPageStarted() throws Throwable { |
187 final String baseUrl = "http://base.com/"; | 188 final String baseUrl = "http://base.com/"; |
188 TestCallbackHelperContainer.OnPageStartedHelper onPageStartedHelper = | 189 TestCallbackHelperContainer.OnPageStartedHelper onPageStartedHelper = |
189 mContentsClient.getOnPageStartedHelper(); | 190 mContentsClient.getOnPageStartedHelper(); |
190 final int callCount = onPageStartedHelper.getCallCount(); | 191 final int callCount = onPageStartedHelper.getCallCount(); |
191 loadDataWithBaseUrlAsync(mAwContents, CommonResources.ABOUT_HTML, "text/
html", false, | 192 loadDataWithBaseUrlAsync(mAwContents, CommonResources.ABOUT_HTML, "text/
html", false, |
192 baseUrl, "about:blank"); | 193 baseUrl, ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL); |
193 onPageStartedHelper.waitForCallback(callCount); | 194 onPageStartedHelper.waitForCallback(callCount); |
194 assertEquals(baseUrl, onPageStartedHelper.getUrl()); | 195 assertEquals(baseUrl, onPageStartedHelper.getUrl()); |
195 } | 196 } |
196 | 197 |
197 @SmallTest | 198 @SmallTest |
198 @Feature({"AndroidWebView"}) | 199 @Feature({"AndroidWebView"}) |
199 public void testHistoryUrl() throws Throwable { | 200 public void testHistoryUrl() throws Throwable { |
200 | 201 |
201 final String pageHtml = "<html><body>Hello, world!</body></html>"; | 202 final String pageHtml = "<html><body>Hello, world!</body></html>"; |
202 final String baseUrl = "http://example.com"; | 203 final String baseUrl = "http://example.com"; |
203 // TODO(mnaganov): Use the same string as Android CTS suite uses | 204 // TODO(mnaganov): Use the same string as Android CTS suite uses |
204 // once GURL issue is resolved (http://code.google.com/p/google-url/issu
es/detail?id=29) | 205 // once GURL issue is resolved (http://code.google.com/p/google-url/issu
es/detail?id=29) |
205 final String historyUrl = "http://history.com/"; | 206 final String historyUrl = "http://history.com/"; |
206 loadDataWithBaseUrlSync(pageHtml, "text/html", false, baseUrl, historyUr
l); | 207 loadDataWithBaseUrlSync(pageHtml, "text/html", false, baseUrl, historyUr
l); |
207 assertEquals(historyUrl, HistoryUtils.getUrlOnUiThread( | 208 assertEquals(historyUrl, HistoryUtils.getUrlOnUiThread( |
208 getInstrumentation(), mWebContents)); | 209 getInstrumentation(), mWebContents)); |
209 | 210 |
210 loadDataWithBaseUrlSync(pageHtml, "text/html", false, baseUrl, null); | 211 loadDataWithBaseUrlSync(pageHtml, "text/html", false, baseUrl, null); |
211 assertEquals("about:blank", HistoryUtils.getUrlOnUiThread( | 212 assertEquals(ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL, |
212 getInstrumentation(), mWebContents)); | 213 HistoryUtils.getUrlOnUiThread(getInstrumentation(), mWebContents
)); |
213 } | 214 } |
214 | 215 |
215 @SmallTest | 216 @SmallTest |
216 @Feature({"AndroidWebView"}) | 217 @Feature({"AndroidWebView"}) |
217 public void testOnPageFinishedUrlIsBaseUrl() throws Throwable { | 218 public void testOnPageFinishedUrlIsBaseUrl() throws Throwable { |
218 final String pageHtml = "<html><body>Hello, world!</body></html>"; | 219 final String pageHtml = "<html><body>Hello, world!</body></html>"; |
219 final String baseUrl = "http://example.com/"; | 220 final String baseUrl = "http://example.com/"; |
220 loadDataWithBaseUrlSync(pageHtml, "text/html", false, baseUrl, baseUrl); | 221 loadDataWithBaseUrlSync(pageHtml, "text/html", false, baseUrl, baseUrl); |
221 loadDataWithBaseUrlSync(pageHtml, "text/html", false, baseUrl, baseUrl); | 222 loadDataWithBaseUrlSync(pageHtml, "text/html", false, baseUrl, baseUrl); |
222 TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = | 223 TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 mContentsClient.getOnPageFinishedHelper(); | 409 mContentsClient.getOnPageFinishedHelper(); |
409 final int callCount = onPageFinishedHelper.getCallCount(); | 410 final int callCount = onPageFinishedHelper.getCallCount(); |
410 getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true); | 411 getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true); |
411 loadDataWithBaseUrlAsync(mAwContents, pageHtml, "text/html", false, inva
lidBaseUrl, null); | 412 loadDataWithBaseUrlAsync(mAwContents, pageHtml, "text/html", false, inva
lidBaseUrl, null); |
412 loadUrlAsync(mAwContents, "javascript:42"); | 413 loadUrlAsync(mAwContents, "javascript:42"); |
413 onPageFinishedHelper.waitForCallback(callCount); | 414 onPageFinishedHelper.waitForCallback(callCount); |
414 // Verify that the load succeeds. The actual base url is undefined. | 415 // Verify that the load succeeds. The actual base url is undefined. |
415 assertEquals(CommonResources.ABOUT_TITLE, getTitleOnUiThread(mAwContents
)); | 416 assertEquals(CommonResources.ABOUT_TITLE, getTitleOnUiThread(mAwContents
)); |
416 } | 417 } |
417 } | 418 } |
OLD | NEW |