Commit 7b3e51dd authored by Yoland Yan's avatar Yoland Yan Committed by Commit Bot

Convert LoadDataWithBaseUrlTest to JUnit4

RestrictionSkipCheck should initialize CommandLine if it is not
initialized for checking device type.

Bug: 755825
Change-Id: Ied37da84ead33b6f2208c61ab5ed07f7b008d3a0
Reviewed-on: https://chromium-review.googlesource.com/616255
Commit-Queue: Yoland Yan <yolandyan@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505895}
parent 7c39cd5c
...@@ -5,8 +5,15 @@ ...@@ -5,8 +5,15 @@
package org.chromium.android_webview.test; package org.chromium.android_webview.test;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.android_webview.AwContents; import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.AwSettings; import org.chromium.android_webview.AwSettings;
import org.chromium.android_webview.test.util.CommonResources; import org.chromium.android_webview.test.util.CommonResources;
...@@ -25,18 +32,20 @@ import java.io.FileOutputStream; ...@@ -25,18 +32,20 @@ import java.io.FileOutputStream;
* Tests for the {@link android.webkit.WebView#loadDataWithBaseURL(String, String, String, String, * Tests for the {@link android.webkit.WebView#loadDataWithBaseURL(String, String, String, String,
* String)} method. * String)} method.
*/ */
public class LoadDataWithBaseUrlTest extends AwTestBase { @RunWith(AwJUnit4ClassRunner.class)
public class LoadDataWithBaseUrlTest {
@Rule
public AwActivityTestRule mActivityTestRule = new AwActivityTestRule();
private TestAwContentsClient mContentsClient; private TestAwContentsClient mContentsClient;
private AwContents mAwContents; private AwContents mAwContents;
private WebContents mWebContents; private WebContents mWebContents;
@Override @Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
mContentsClient = new TestAwContentsClient(); mContentsClient = new TestAwContentsClient();
final AwTestContainerView testContainerView = final AwTestContainerView testContainerView =
createAwTestContainerViewOnMainSync(mContentsClient); mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsClient);
mAwContents = testContainerView.getAwContents(); mAwContents = testContainerView.getAwContents();
mWebContents = mAwContents.getWebContents(); mWebContents = mAwContents.getWebContents();
} }
...@@ -44,8 +53,9 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -44,8 +53,9 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
protected void loadDataWithBaseUrlSync( protected void loadDataWithBaseUrlSync(
final String data, final String mimeType, final boolean isBase64Encoded, final String data, final String mimeType, final boolean isBase64Encoded,
final String baseUrl, final String historyUrl) throws Throwable { final String baseUrl, final String historyUrl) throws Throwable {
loadDataWithBaseUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), mActivityTestRule.loadDataWithBaseUrlSync(mAwContents,
data, mimeType, isBase64Encoded, baseUrl, historyUrl); mContentsClient.getOnPageFinishedHelper(), data, mimeType, isBase64Encoded, baseUrl,
historyUrl);
} }
private static final String SCRIPT_FILE = "/script.js"; private static final String SCRIPT_FILE = "/script.js";
...@@ -84,7 +94,7 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -84,7 +94,7 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
+ "</html>"; + "</html>";
} }
@Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testImageLoad() throws Throwable { public void testImageLoad() throws Throwable {
...@@ -93,7 +103,7 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -93,7 +103,7 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
webServer.setResponseBase64("/" + CommonResources.FAVICON_FILENAME, webServer.setResponseBase64("/" + CommonResources.FAVICON_FILENAME,
CommonResources.FAVICON_DATA_BASE64, CommonResources.getImagePngHeaders(true)); CommonResources.FAVICON_DATA_BASE64, CommonResources.getImagePngHeaders(true));
AwSettings contentSettings = getAwSettingsOnUiThread(mAwContents); AwSettings contentSettings = mActivityTestRule.getAwSettingsOnUiThread(mAwContents);
contentSettings.setImagesEnabled(true); contentSettings.setImagesEnabled(true);
contentSettings.setJavaScriptEnabled(true); contentSettings.setJavaScriptEnabled(true);
...@@ -101,12 +111,13 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -101,12 +111,13 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
CommonResources.getOnImageLoadedHtml(CommonResources.FAVICON_FILENAME), CommonResources.getOnImageLoadedHtml(CommonResources.FAVICON_FILENAME),
"text/html", false, webServer.getBaseUrl(), null); "text/html", false, webServer.getBaseUrl(), null);
assertEquals("5", getTitleOnUiThread(mAwContents)); Assert.assertEquals("5", mActivityTestRule.getTitleOnUiThread(mAwContents));
} finally { } finally {
webServer.shutdown(); webServer.shutdown();
} }
} }
@Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testScriptLoad() throws Throwable { public void testScriptLoad() throws Throwable {
...@@ -116,14 +127,15 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -116,14 +127,15 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
CommonResources.getTextJavascriptHeaders(true)); CommonResources.getTextJavascriptHeaders(true));
final String pageHtml = getScriptFileTestPageHtml(scriptUrl); final String pageHtml = getScriptFileTestPageHtml(scriptUrl);
getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true); mActivityTestRule.getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true);
loadDataWithBaseUrlSync(pageHtml, "text/html", false, webServer.getBaseUrl(), null); loadDataWithBaseUrlSync(pageHtml, "text/html", false, webServer.getBaseUrl(), null);
assertEquals(SCRIPT_LOADED, getTitleOnUiThread(mAwContents)); Assert.assertEquals(SCRIPT_LOADED, mActivityTestRule.getTitleOnUiThread(mAwContents));
} finally { } finally {
webServer.shutdown(); webServer.shutdown();
} }
} }
@Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testSameOrigin() throws Throwable { public void testSameOrigin() throws Throwable {
...@@ -133,14 +145,15 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -133,14 +145,15 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
CommonResources.ABOUT_HTML, CommonResources.getTextHtmlHeaders(true)); CommonResources.ABOUT_HTML, CommonResources.getTextHtmlHeaders(true));
final String html = getCrossOriginAccessTestPageHtml(frameUrl); final String html = getCrossOriginAccessTestPageHtml(frameUrl);
getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true); mActivityTestRule.getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true);
loadDataWithBaseUrlSync(html, "text/html", false, webServer.getBaseUrl(), null); loadDataWithBaseUrlSync(html, "text/html", false, webServer.getBaseUrl(), null);
assertEquals(frameUrl, getTitleOnUiThread(mAwContents)); Assert.assertEquals(frameUrl, mActivityTestRule.getTitleOnUiThread(mAwContents));
} finally { } finally {
webServer.shutdown(); webServer.shutdown();
} }
} }
@Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testCrossOrigin() throws Throwable { public void testCrossOrigin() throws Throwable {
...@@ -151,36 +164,41 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -151,36 +164,41 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
final String html = getCrossOriginAccessTestPageHtml(frameUrl); final String html = getCrossOriginAccessTestPageHtml(frameUrl);
final String baseUrl = webServer.getBaseUrl().replaceFirst("localhost", "127.0.0.1"); final String baseUrl = webServer.getBaseUrl().replaceFirst("localhost", "127.0.0.1");
getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true); mActivityTestRule.getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true);
loadDataWithBaseUrlSync(html, "text/html", false, baseUrl, null); loadDataWithBaseUrlSync(html, "text/html", false, baseUrl, null);
assertEquals("Exception", getTitleOnUiThread(mAwContents)); Assert.assertEquals("Exception", mActivityTestRule.getTitleOnUiThread(mAwContents));
} finally { } finally {
webServer.shutdown(); webServer.shutdown();
} }
} }
@Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testNullBaseUrl() throws Throwable { public void testNullBaseUrl() throws Throwable {
getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true); mActivityTestRule.getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true);
final String pageHtml = "<html><body onload='document.title=document.location.href'>" final String pageHtml = "<html><body onload='document.title=document.location.href'>"
+ "</body></html>"; + "</body></html>";
loadDataWithBaseUrlSync(pageHtml, "text/html", false, null, null); loadDataWithBaseUrlSync(pageHtml, "text/html", false, null, null);
assertEquals(ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL, getTitleOnUiThread(mAwContents)); Assert.assertEquals(ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL,
mActivityTestRule.getTitleOnUiThread(mAwContents));
} }
@Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testInvalidBaseUrl() throws Throwable { public void testInvalidBaseUrl() throws Throwable {
final String invalidBaseUrl = "http://"; final String invalidBaseUrl = "http://";
getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true); mActivityTestRule.getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true);
loadDataWithBaseUrlSync( loadDataWithBaseUrlSync(
CommonResources.ABOUT_HTML, "text/html", false, invalidBaseUrl, null); CommonResources.ABOUT_HTML, "text/html", false, invalidBaseUrl, null);
// Verify that the load succeeds. The actual base url is undefined. // Verify that the load succeeds. The actual base url is undefined.
assertEquals(CommonResources.ABOUT_TITLE, getTitleOnUiThread(mAwContents)); Assert.assertEquals(
CommonResources.ABOUT_TITLE, mActivityTestRule.getTitleOnUiThread(mAwContents));
} }
@Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testloadDataWithBaseUrlCallsOnPageStarted() throws Throwable { public void testloadDataWithBaseUrlCallsOnPageStarted() throws Throwable {
...@@ -191,34 +209,38 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -191,34 +209,38 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
mContentsClient.getOnPageFinishedHelper(); mContentsClient.getOnPageFinishedHelper();
final int pageStartedCount = onPageStartedHelper.getCallCount(); final int pageStartedCount = onPageStartedHelper.getCallCount();
final int pageFinishedCount = onPageFinishedHelper.getCallCount(); final int pageFinishedCount = onPageFinishedHelper.getCallCount();
loadDataWithBaseUrlAsync(mAwContents, CommonResources.ABOUT_HTML, "text/html", false, mActivityTestRule.loadDataWithBaseUrlAsync(
mAwContents, CommonResources.ABOUT_HTML, "text/html", false,
baseUrl, ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL); baseUrl, ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL);
onPageStartedHelper.waitForCallback(pageStartedCount); onPageStartedHelper.waitForCallback(pageStartedCount);
assertEquals(baseUrl, onPageStartedHelper.getUrl()); Assert.assertEquals(baseUrl, onPageStartedHelper.getUrl());
onPageFinishedHelper.waitForCallback(pageFinishedCount); onPageFinishedHelper.waitForCallback(pageFinishedCount);
assertEquals("onPageStarted should only be called once", pageStartedCount + 1, Assert.assertEquals("onPageStarted should only be called once", pageStartedCount + 1,
onPageStartedHelper.getCallCount()); onPageStartedHelper.getCallCount());
} }
@Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testHistoryUrl() throws Throwable { public void testHistoryUrl() throws Throwable {
final String pageHtml = "<html><body>Hello, world!</body></html>"; final String pageHtml = "<html><body>Hello, world!</body></html>";
final String baseUrl = "http://example.com"; final String baseUrl = "http://example.com";
// TODO(mnaganov): Use the same string as Android CTS suite uses // TODO(mnaganov): Use the same string as Android CTS suite uses
// once GURL issue is resolved (http://code.google.com/p/google-url/issues/detail?id=29) // once GURL issue is resolved (http://code.google.com/p/google-url/issues/detail?id=29)
final String historyUrl = "http://history.com/"; final String historyUrl = "http://history.com/";
loadDataWithBaseUrlSync(pageHtml, "text/html", false, baseUrl, historyUrl); loadDataWithBaseUrlSync(pageHtml, "text/html", false, baseUrl, historyUrl);
assertEquals(historyUrl, HistoryUtils.getUrlOnUiThread( Assert.assertEquals(historyUrl,
getInstrumentation(), mWebContents)); HistoryUtils.getUrlOnUiThread(
InstrumentationRegistry.getInstrumentation(), mWebContents));
loadDataWithBaseUrlSync(pageHtml, "text/html", false, baseUrl, null); loadDataWithBaseUrlSync(pageHtml, "text/html", false, baseUrl, null);
assertEquals(ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL, Assert.assertEquals(ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL,
HistoryUtils.getUrlOnUiThread(getInstrumentation(), mWebContents)); HistoryUtils.getUrlOnUiThread(
InstrumentationRegistry.getInstrumentation(), mWebContents));
} }
@Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testOnPageFinishedUrlIsBaseUrl() throws Throwable { public void testOnPageFinishedUrlIsBaseUrl() throws Throwable {
...@@ -228,19 +250,22 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -228,19 +250,22 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
loadDataWithBaseUrlSync(pageHtml, "text/html", false, baseUrl, baseUrl); loadDataWithBaseUrlSync(pageHtml, "text/html", false, baseUrl, baseUrl);
TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
mContentsClient.getOnPageFinishedHelper(); mContentsClient.getOnPageFinishedHelper();
assertEquals(baseUrl, onPageFinishedHelper.getUrl()); Assert.assertEquals(baseUrl, onPageFinishedHelper.getUrl());
} }
@Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testHistoryUrlIgnoredWithDataSchemeBaseUrl() throws Throwable { public void testHistoryUrlIgnoredWithDataSchemeBaseUrl() throws Throwable {
final String pageHtml = "<html><body>bar</body></html>"; final String pageHtml = "<html><body>bar</body></html>";
final String historyUrl = "http://history.com/"; final String historyUrl = "http://history.com/";
loadDataWithBaseUrlSync(pageHtml, "text/html", false, "data:foo", historyUrl); loadDataWithBaseUrlSync(pageHtml, "text/html", false, "data:foo", historyUrl);
assertEquals("data:text/html," + pageHtml, HistoryUtils.getUrlOnUiThread( Assert.assertEquals("data:text/html," + pageHtml,
getInstrumentation(), mWebContents)); HistoryUtils.getUrlOnUiThread(
InstrumentationRegistry.getInstrumentation(), mWebContents));
} }
@Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testHistoryUrlNavigation() throws Throwable { public void testHistoryUrlNavigation() throws Throwable {
...@@ -254,7 +279,7 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -254,7 +279,7 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
+ "<body>" + page1Title + "</body></html>"; + "<body>" + page1Title + "</body></html>";
loadDataWithBaseUrlSync(page1Html, "text/html", false, null, historyUrl); loadDataWithBaseUrlSync(page1Html, "text/html", false, null, historyUrl);
assertEquals(page1Title, getTitleOnUiThread(mAwContents)); Assert.assertEquals(page1Title, mActivityTestRule.getTitleOnUiThread(mAwContents));
final String page2Title = "Page2"; final String page2Title = "Page2";
final String page2Html = "<html><head><title>" + page2Title + "</title>" final String page2Html = "<html><head><title>" + page2Title + "</title>"
...@@ -262,12 +287,14 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -262,12 +287,14 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
final TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = final TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
mContentsClient.getOnPageFinishedHelper(); mContentsClient.getOnPageFinishedHelper();
loadDataSync(mAwContents, onPageFinishedHelper, page2Html, "text/html", false); mActivityTestRule.loadDataSync(
assertEquals(page2Title, getTitleOnUiThread(mAwContents)); mAwContents, onPageFinishedHelper, page2Html, "text/html", false);
Assert.assertEquals(page2Title, mActivityTestRule.getTitleOnUiThread(mAwContents));
HistoryUtils.goBackSync(getInstrumentation(), mWebContents, onPageFinishedHelper); HistoryUtils.goBackSync(InstrumentationRegistry.getInstrumentation(), mWebContents,
onPageFinishedHelper);
// The title of first page loaded with loadDataWithBaseUrl. // The title of first page loaded with loadDataWithBaseUrl.
assertEquals(page1Title, getTitleOnUiThread(mAwContents)); Assert.assertEquals(page1Title, mActivityTestRule.getTitleOnUiThread(mAwContents));
} finally { } finally {
webServer.shutdown(); webServer.shutdown();
} }
...@@ -288,20 +315,21 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -288,20 +315,21 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
loadDataWithBaseUrlSync(data, "text/html", false, baseUrl, null); loadDataWithBaseUrlSync(data, "text/html", false, baseUrl, null);
pollInstrumentationThread(() -> { AwActivityTestRule.pollInstrumentationThread(() -> {
String title = getTitleOnUiThread(mAwContents); String title = mActivityTestRule.getTitleOnUiThread(mAwContents);
return imageLoaded.equals(title) || imageNotLoaded.equals(title); return imageLoaded.equals(title) || imageNotLoaded.equals(title);
}); });
return imageLoaded.equals(getTitleOnUiThread(mAwContents)); return imageLoaded.equals(mActivityTestRule.getTitleOnUiThread(mAwContents));
} }
@Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
@SuppressWarnings("Finally") @SuppressWarnings("Finally")
public void testLoadDataWithBaseUrlAccessingFile() throws Throwable { public void testLoadDataWithBaseUrlAccessingFile() throws Throwable {
// Create a temporary file on the filesystem we can try to read. // Create a temporary file on the filesystem we can try to read.
File cacheDir = getActivity().getCacheDir(); File cacheDir = mActivityTestRule.getActivity().getCacheDir();
File tempImage = File.createTempFile("test_image", ".png", cacheDir); File tempImage = File.createTempFile("test_image", ".png", cacheDir);
Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565); Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565);
FileOutputStream fos = new FileOutputStream(tempImage); FileOutputStream fos = new FileOutputStream(tempImage);
...@@ -312,7 +340,7 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -312,7 +340,7 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
} }
String imagePath = tempImage.getAbsolutePath(); String imagePath = tempImage.getAbsolutePath();
AwSettings contentSettings = getAwSettingsOnUiThread(mAwContents); AwSettings contentSettings = mActivityTestRule.getAwSettingsOnUiThread(mAwContents);
contentSettings.setImagesEnabled(true); contentSettings.setImagesEnabled(true);
contentSettings.setJavaScriptEnabled(true); contentSettings.setJavaScriptEnabled(true);
...@@ -324,39 +352,41 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -324,39 +352,41 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
String token = "" + System.currentTimeMillis(); String token = "" + System.currentTimeMillis();
// All access to file://, including android_asset and android_res is blocked // All access to file://, including android_asset and android_res is blocked
// with a data: base URL, regardless of AwSettings.getAllowFileAccess(). // with a data: base URL, regardless of AwSettings.getAllowFileAccess().
assertFalse(canAccessFileFromData(dataBaseUrl, Assert.assertFalse(canAccessFileFromData(
"file:///android_asset/asset_icon.png?" + token)); dataBaseUrl, "file:///android_asset/asset_icon.png?" + token));
assertFalse(canAccessFileFromData(dataBaseUrl, Assert.assertFalse(canAccessFileFromData(
"file:///android_res/raw/resource_icon.png?" + token)); dataBaseUrl, "file:///android_res/raw/resource_icon.png?" + token));
assertFalse(canAccessFileFromData(dataBaseUrl, "file://" + imagePath + "?" + token)); Assert.assertFalse(
canAccessFileFromData(dataBaseUrl, "file://" + imagePath + "?" + token));
// WebView always has access to android_asset and android_res for non-data // WebView always has access to android_asset and android_res for non-data
// base URLs and can access other file:// URLs based on the value of // base URLs and can access other file:// URLs based on the value of
// AwSettings.getAllowFileAccess(). // AwSettings.getAllowFileAccess().
assertTrue(canAccessFileFromData(nonDataBaseUrl, Assert.assertTrue(canAccessFileFromData(
"file:///android_asset/asset_icon.png?" + token)); nonDataBaseUrl, "file:///android_asset/asset_icon.png?" + token));
assertTrue(canAccessFileFromData(nonDataBaseUrl, Assert.assertTrue(canAccessFileFromData(
"file:///android_res/raw/resource_icon.png?" + token)); nonDataBaseUrl, "file:///android_res/raw/resource_icon.png?" + token));
assertFalse(canAccessFileFromData(nonDataBaseUrl, Assert.assertFalse(
"file://" + imagePath + "?" + token)); canAccessFileFromData(nonDataBaseUrl, "file://" + imagePath + "?" + token));
token += "a"; token += "a";
mAwContents.getSettings().setAllowFileAccess(true); mAwContents.getSettings().setAllowFileAccess(true);
// We should still be unable to access any file:// with when loading with a // We should still be unable to access any file:// with when loading with a
// data: base URL, but we should now be able to access the wider file system // data: base URL, but we should now be able to access the wider file system
// (still restricted by OS-level permission checks) with a non-data base URL. // (still restricted by OS-level permission checks) with a non-data base URL.
assertFalse(canAccessFileFromData(dataBaseUrl, Assert.assertFalse(canAccessFileFromData(
"file:///android_asset/asset_icon.png?" + token)); dataBaseUrl, "file:///android_asset/asset_icon.png?" + token));
assertFalse(canAccessFileFromData(dataBaseUrl, Assert.assertFalse(canAccessFileFromData(
"file:///android_res/raw/resource_icon.png?" + token)); dataBaseUrl, "file:///android_res/raw/resource_icon.png?" + token));
assertFalse(canAccessFileFromData(dataBaseUrl, "file://" + imagePath + "?" + token)); Assert.assertFalse(
canAccessFileFromData(dataBaseUrl, "file://" + imagePath + "?" + token));
assertTrue(canAccessFileFromData(nonDataBaseUrl,
"file:///android_asset/asset_icon.png?" + token)); Assert.assertTrue(canAccessFileFromData(
assertTrue(canAccessFileFromData(nonDataBaseUrl, nonDataBaseUrl, "file:///android_asset/asset_icon.png?" + token));
"file:///android_res/raw/resource_icon.png?" + token)); Assert.assertTrue(canAccessFileFromData(
assertTrue(canAccessFileFromData(nonDataBaseUrl, nonDataBaseUrl, "file:///android_res/raw/resource_icon.png?" + token));
"file://" + imagePath + "?" + token)); Assert.assertTrue(
canAccessFileFromData(nonDataBaseUrl, "file://" + imagePath + "?" + token));
} finally { } finally {
if (!tempImage.delete()) throw new AssertionError(); if (!tempImage.delete()) throw new AssertionError();
} }
...@@ -365,6 +395,7 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -365,6 +395,7 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
/** /**
* Disallowed from running on Svelte devices due to OOM errors: crbug.com/598013 * Disallowed from running on Svelte devices due to OOM errors: crbug.com/598013
*/ */
@Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
@Restriction(Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE)
...@@ -380,12 +411,14 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -380,12 +411,14 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
while (i < doc.length()) doc.setCharAt(i++, 'A'); while (i < doc.length()) doc.setCharAt(i++, 'A');
doc.append("--><script>window.gotToEndOfBody=true;</script></body></html>"); doc.append("--><script>window.gotToEndOfBody=true;</script></body></html>");
enableJavaScriptOnUiThread(mAwContents); mActivityTestRule.enableJavaScriptOnUiThread(mAwContents);
loadDataWithBaseUrlSync(doc.toString(), "text/html", false, null, null); loadDataWithBaseUrlSync(doc.toString(), "text/html", false, null, null);
assertEquals("true", executeJavaScriptAndWaitForResult(mAwContents, mContentsClient, Assert.assertEquals("true",
"window.gotToEndOfBody")); mActivityTestRule.executeJavaScriptAndWaitForResult(
mAwContents, mContentsClient, "window.gotToEndOfBody"));
} }
@Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testOnPageFinishedWhenInterrupted() throws Throwable { public void testOnPageFinishedWhenInterrupted() throws Throwable {
...@@ -397,12 +430,14 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -397,12 +430,14 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
final TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = final TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
mContentsClient.getOnPageFinishedHelper(); mContentsClient.getOnPageFinishedHelper();
final int callCount = onPageFinishedHelper.getCallCount(); final int callCount = onPageFinishedHelper.getCallCount();
loadDataWithBaseUrlAsync(mAwContents, pageHtml, "text/html", false, baseUrl, null); mActivityTestRule.loadDataWithBaseUrlAsync(
loadUrlAsync(mAwContents, "javascript:42"); mAwContents, pageHtml, "text/html", false, baseUrl, null);
mActivityTestRule.loadUrlAsync(mAwContents, "javascript:42");
onPageFinishedHelper.waitForCallback(callCount); onPageFinishedHelper.waitForCallback(callCount);
assertEquals(baseUrl, onPageFinishedHelper.getUrl()); Assert.assertEquals(baseUrl, onPageFinishedHelper.getUrl());
} }
@Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testOnPageFinishedWithInvalidBaseUrlWhenInterrupted() throws Throwable { public void testOnPageFinishedWithInvalidBaseUrlWhenInterrupted() throws Throwable {
...@@ -411,11 +446,13 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { ...@@ -411,11 +446,13 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
final TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = final TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
mContentsClient.getOnPageFinishedHelper(); mContentsClient.getOnPageFinishedHelper();
final int callCount = onPageFinishedHelper.getCallCount(); final int callCount = onPageFinishedHelper.getCallCount();
getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true); mActivityTestRule.getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true);
loadDataWithBaseUrlAsync(mAwContents, pageHtml, "text/html", false, invalidBaseUrl, null); mActivityTestRule.loadDataWithBaseUrlAsync(
loadUrlAsync(mAwContents, "javascript:42"); mAwContents, pageHtml, "text/html", false, invalidBaseUrl, null);
mActivityTestRule.loadUrlAsync(mAwContents, "javascript:42");
onPageFinishedHelper.waitForCallback(callCount); onPageFinishedHelper.waitForCallback(callCount);
// Verify that the load succeeds. The actual base url is undefined. // Verify that the load succeeds. The actual base url is undefined.
assertEquals(CommonResources.ABOUT_TITLE, getTitleOnUiThread(mAwContents)); Assert.assertEquals(
CommonResources.ABOUT_TITLE, mActivityTestRule.getTitleOnUiThread(mAwContents));
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment