Commit d6af8726 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Revert "WebLayer: add tests for DownloadDelegate"

This reverts commit f72a8099.

Reason for revert: in-flight conflict with
734ea5e7

Original change's description:
> WebLayer: add tests for DownloadDelegate
> 
> Credit to sky@ for EventUtils.java (salvaged from
> 47bd294d, which got reverted)
> 
> Bug: none
> Change-Id: Iadb75c6b9c77185536c753504b6cefa1ba4796de
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1866987
> Reviewed-by: Scott Violet <sky@chromium.org>
> Commit-Queue: Evan Stade <estade@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#707864}

TBR=sky@chromium.org,estade@chromium.org

Change-Id: I5d2d6604fb0e2e633ac65109d23da7eb2826e6a1
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: none
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872746Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707882}
parent 256e9fd8
......@@ -252,13 +252,10 @@ instrumentation_test_apk("weblayer_instrumentation_test_apk") {
deps = [
"//base:base_java_test_support",
"//content/public/test/android:content_java_test_support",
"//net/android:net_java_test_support",
"//third_party/android_support_test_runner:runner_java",
]
java_files = [
"javatests/src/org/chromium/weblayer/test/BrowserObserverTest.java",
"javatests/src/org/chromium/weblayer/test/EventUtils.java",
"javatests/src/org/chromium/weblayer/test/DownloadDelegateTest.java",
"javatests/src/org/chromium/weblayer/test/NavigationTest.java",
"javatests/src/org/chromium/weblayer/test/SmokeTest.java",
"javatests/src/org/chromium/weblayer/test/RenderingTest.java",
......@@ -266,11 +263,5 @@ instrumentation_test_apk("weblayer_instrumentation_test_apk") {
"javatests/src/org/chromium/weblayer/test/FragmentRestoreTest.java",
"shell_apk/src/org/chromium/weblayer/shell/WebLayerShellActivity.java",
]
additional_apks = [
"//weblayer/shell/android:weblayer_support_apk",
"//net/android:net_test_support_apk",
]
data = [
"//weblayer/test/data/",
]
additional_apks = [ "//weblayer/shell/android:weblayer_support_apk" ]
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.weblayer.test;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.util.Pair;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.net.test.util.TestWebServer;
import org.chromium.weblayer.DownloadDelegate;
import org.chromium.weblayer.shell.WebLayerShellActivity;
import java.util.ArrayList;
import java.util.List;
/**
* Tests that the DownloadDelegate method is invoked for downloads.
*/
@RunWith(BaseJUnit4ClassRunner.class)
public class DownloadDelegateTest {
@Rule
public WebLayerShellActivityTestRule mActivityTestRule = new WebLayerShellActivityTestRule();
private WebLayerShellActivity mActivity;
private Delegate mDelegate;
private static class Delegate extends DownloadDelegate {
public String mUrl;
public String mUserAgent;
public String mContentDisposition;
public String mMimetype;
public long mContentLength;
@Override
public void downloadRequested(String url, String userAgent, String contentDisposition,
String mimetype, long contentLength) {
mUrl = url;
mUserAgent = userAgent;
mContentDisposition = contentDisposition;
mMimetype = mimetype;
mContentLength = contentLength;
}
public void waitForDownload() {
CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override
public boolean isSatisfied() {
return mUrl != null;
}
}, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
}
}
@Before
public void setUp() {
mActivity = mActivityTestRule.launchShellWithUrl(null);
Assert.assertNotNull(mActivity);
mDelegate = new Delegate();
TestThreadUtils.runOnUiThreadBlocking(
() -> { mActivity.getBrowserController().setDownloadDelegate(mDelegate); });
}
/**
* Verifies the DownloadDelegate is informed of downloads resulting from navigations to pages
* with Content-Disposition attachment.
*/
@Test
@SmallTest
public void testDownloadByContentDisposition() throws Throwable {
final String data = "download data";
final String contentDisposition = "attachment;filename=\"download.txt\"";
final String mimetype = "text/plain";
List<Pair<String, String>> downloadHeaders = new ArrayList<Pair<String, String>>();
downloadHeaders.add(Pair.create("Content-Disposition", contentDisposition));
downloadHeaders.add(Pair.create("Content-Type", mimetype));
downloadHeaders.add(Pair.create("Content-Length", Integer.toString(data.length())));
TestWebServer webServer = TestWebServer.start();
try {
final String pageUrl = webServer.setResponse("/download.txt", data, downloadHeaders);
mActivityTestRule.loadUrl(pageUrl);
mDelegate.waitForDownload();
Assert.assertEquals(pageUrl, mDelegate.mUrl);
Assert.assertEquals(contentDisposition, mDelegate.mContentDisposition);
Assert.assertEquals(mimetype, mDelegate.mMimetype);
Assert.assertEquals(data.length(), mDelegate.mContentLength);
// TODO(estade): verify mUserAgent.
} finally {
webServer.shutdown();
}
}
/**
* Verifies the DownloadDelegate is informed of downloads resulting from the user clicking on a
* download link.
*/
@Test
@SmallTest
public void testDownloadByLinkAttribute() {
EmbeddedTestServer testServer = new EmbeddedTestServer();
testServer.initializeNative(InstrumentationRegistry.getInstrumentation().getContext(),
EmbeddedTestServer.ServerHTTPSSetting.USE_HTTP);
testServer.addDefaultHandlers("weblayer/test/data");
Assert.assertTrue(testServer.start(0));
String pageUrl = testServer.getURL("/download.html");
mActivityTestRule.loadUrl(pageUrl);
mActivityTestRule.waitForNavigation(pageUrl);
EventUtils.simulateTouchCenterOfView(mActivity.getWindow().getDecorView());
mDelegate.waitForDownload();
Assert.assertEquals(testServer.getURL("/lorem_ipsum.txt"), mDelegate.mUrl);
testServer.stopAndDestroyServer();
}
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.weblayer.test;
import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
/**
* Utilities related to event generation.
*/
public final class EventUtils {
private EventUtils() {}
/**
* Asynchronously posts a touch-down and touch-up event at the center of the supplied View.
*/
public static void simulateTouchCenterOfView(final View view) {
view.post(() -> {
long eventTime = SystemClock.uptimeMillis();
float x = (float) (view.getRight() - view.getLeft()) / 2;
float y = (float) (view.getBottom() - view.getTop()) / 2;
view.dispatchTouchEvent(
MotionEvent.obtain(eventTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0));
view.dispatchTouchEvent(
MotionEvent.obtain(eventTime, eventTime, MotionEvent.ACTION_UP, x, y, 0));
});
}
}
<html>
<head>
<style>
body, html {
height: 100%;
}
a {
display: block;
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<a href="lorem_ipsum.txt" download>anchor text</a>
</body>
</html>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
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