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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/UrlSchemeTest.java

Issue 2473153005: Revert of Increase test coverage for Content:// urls (Closed)
Patch Set: Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/android/javatests/src/org/chromium/chrome/test/TestContentProvider.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/javatests/src/org/chromium/chrome/browser/UrlSchemeTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/UrlSchemeTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/UrlSchemeTest.java
index 9a3a1806ea5459045f5dbbc3a83cac6453acc01e..9431398bee63dce5b9e644de7a5a3e4af38bc5e5 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/UrlSchemeTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/UrlSchemeTest.java
@@ -16,38 +16,19 @@
import org.chromium.base.test.util.UrlUtils;
import org.chromium.chrome.test.ChromeActivityTestCaseBase;
import org.chromium.chrome.test.TestContentProvider;
-import org.chromium.content.browser.test.util.Criteria;
-import org.chromium.content.browser.test.util.CriteriaHelper;
-import org.chromium.net.test.EmbeddedTestServer;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.Callable;
+
/** Test suite for different Android URL schemes. */
@RetryOnFailure
public class UrlSchemeTest extends ChromeActivityTestCaseBase<ChromeActivity> {
- private static final String SIMPLE_SRC = "simple.html";
- private static final String SIMPLE_IMAGE = "google.png";
-
- private EmbeddedTestServer mTestServer;
public UrlSchemeTest() {
super(ChromeActivity.class);
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- TestContentProvider.resetResourceRequestCounts(getInstrumentation().getTargetContext());
- mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
- }
-
- @Override
- protected void tearDown() throws Exception {
- mTestServer.stopAndDestroyServer();
- super.tearDown();
}
/**
@@ -58,7 +39,8 @@
@MediumTest
@Feature({"Navigation"})
public void testContentProviderResourceRequestCount() throws IOException {
- String resource = SIMPLE_SRC;
+ String resource = "test_reset";
+ resetResourceRequestCountInContentProvider(resource);
ensureResourceRequestCountInContentProvider(resource, 0);
// Make a request to the content provider.
Uri uri = Uri.parse(createContentUrl(resource));
@@ -71,6 +53,8 @@
if (inputStream != null) inputStream.close();
}
ensureResourceRequestCountInContentProvider(resource, 1);
+ resetResourceRequestCountInContentProvider(resource);
+ ensureResourceRequestCountInContentProvider(resource, 0);
}
/**
@@ -79,89 +63,19 @@
@MediumTest
@Feature({"Navigation"})
public void testContentUrlAccess() throws InterruptedException {
- String resource = SIMPLE_SRC;
+ String resource = "content_disabled_by_default";
+ resetResourceRequestCountInContentProvider(resource);
loadUrl(createContentUrl(resource));
ensureResourceRequestCountInContentProviderNotLessThan(resource, 1);
}
- /**
- * Make sure a Content url *CANNOT* access the contents of an iframe that is loaded as a
- * content URL.
- */
- @MediumTest
- @Feature({"Navigation"})
- public void testContentUrlIframeAccessFromContentUrl() throws Throwable {
- final String resource = "page_with_iframe_as_content_url.html";
- final String iframe = "simple_iframe.html";
- final String iframeId = "iframe_test_id";
-
- final String script = "var ifrm = document.getElementById('" + iframeId + "');"
- + "try {"
- + " var a = ifrm.contentWindow.document.body.textContent;"
- + "} catch (e) {"
- + " document.title = 'fail';"
- + "}";
-
- loadUrl(createContentUrl(resource));
-
- // Make sure iframe is really loaded by verifying the title
- CriteriaHelper.pollUiThread(new Criteria() {
+ private String getTitleOnUiThread() {
+ return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<String>() {
@Override
- public boolean isSatisfied() {
- return getActivity().getActivityTab().getTitle().equals("iframe loaded");
+ public String call() throws Exception {
+ return getActivity().getActivityTab().getTitle();
}
});
- // Make sure that content provider was asked to provide the content.
- ensureResourceRequestCountInContentProviderNotLessThan(iframe, 1);
- runJavaScriptCodeInCurrentTab(script);
-
- // Make sure content access failed by verifying that title is set to fail.
- CriteriaHelper.pollUiThread(new Criteria() {
- @Override
- public boolean isSatisfied() {
- return getActivity().getActivityTab().getTitle().equals("fail");
- }
- });
- }
-
- /**
- * Test that a content URL is *ALLOWED* to access an image provided by a content URL.
- */
- @MediumTest
- @Feature({"Navigation"})
- public void testContentUrlImageFromContentUrl() throws Throwable {
- verifyImageLoadRules(createContentUrl(SIMPLE_SRC), "success", 1);
- }
-
- /**
- * Test that a HTTP URL is *NOT ALLOWED* to access an image provided by a content URL.
- */
- @MediumTest
- @Feature({"Navigation"})
- public void testContentUrlImageFromHttpUrl() throws Throwable {
- final String main = mTestServer.getURL("/chrome/test/data/android/" + SIMPLE_SRC);
- verifyImageLoadRules(main, "error", 0);
- }
-
- private void verifyImageLoadRules(String url, final String expectedTitle, int expectedLoadCount)
- throws Throwable {
- final String resource = SIMPLE_IMAGE;
- final String script = "var img = new Image();"
- + " img.onerror = function() { document.title = 'error' };"
- + " img.onabort = function() { document.title = 'error' };"
- + " img.onload = function() { document.title = 'success' };"
- + " img.src = '" + createContentUrl(resource) + "';"
- + " document.body.appendChild(img);";
- loadUrl(url);
- runJavaScriptCodeInCurrentTab(script);
-
- CriteriaHelper.pollUiThread(new Criteria() {
- @Override
- public boolean isSatisfied() {
- return getActivity().getActivityTab().getTitle().equals(expectedTitle);
- }
- });
- ensureResourceRequestCountInContentProviderNotLessThan(resource, expectedLoadCount);
}
/**
@@ -170,7 +84,8 @@
@MediumTest
@Feature({"Navigation"})
public void testContentUrlFromData() throws InterruptedException {
- final String target = SIMPLE_IMAGE;
+ final String target = "content_from_data";
+ resetResourceRequestCountInContentProvider(target);
loadUrl(UrlUtils.encodeHtmlDataUri(
"<img src=\"" + createContentUrl(target) + "\">"));
ensureResourceRequestCountInContentProvider(target, 0);
@@ -182,25 +97,17 @@
@MediumTest
@Feature({"Navigation"})
public void testContentUrlFromFile() throws InterruptedException, IOException {
- final String target = SIMPLE_IMAGE;
+ final String target = "content_from_file";
final File file = new File(Environment.getExternalStorageDirectory(), target + ".html");
try {
TestFileUtil.createNewHtmlFile(
file, target, "<img src=\"" + createContentUrl(target) + "\">");
+ resetResourceRequestCountInContentProvider(target);
loadUrl("file:///" + file.getAbsolutePath());
ensureResourceRequestCountInContentProvider(target, 0);
} finally {
TestFileUtil.deleteFile(file);
}
- }
-
- private String getTitleOnUiThread() {
- return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<String>() {
- @Override
- public String call() throws Exception {
- return getActivity().getActivityTab().getTitle();
- }
- });
}
/**
@@ -245,6 +152,11 @@
actualCount >= expectedMinimalCount);
}
+ private void resetResourceRequestCountInContentProvider(String resource) {
+ Context context = getInstrumentation().getTargetContext();
+ TestContentProvider.resetResourceRequestCount(context, resource);
+ }
+
private String createContentUrl(final String target) {
return TestContentProvider.createContentUrl(target);
}
« no previous file with comments | « no previous file | chrome/test/android/javatests/src/org/chromium/chrome/test/TestContentProvider.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698