Commit 1114fa98 authored by Min Qin's avatar Min Qin Committed by Commit Bot

Fix a disabled download test

There are several issues with this download test:
1. The new download progress info bar will mess up with the duplicate
infobar when trying to find the latter.
2. Download update may never go through DownloadManagerService in
download's new code paths
3. Only 1 duplicate infobar will show at a time, so the
AllowMultipleInfoBars test is no longer valid

This CL fixes the above 3 issues.

BUG=597230

Change-Id: I9cfbfcd51c040dc77bd4f6e0cb0f6bfaf967a912
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2411732Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807120}
parent 769d8a10
...@@ -43,6 +43,7 @@ import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate; ...@@ -43,6 +43,7 @@ import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate;
import org.chromium.chrome.test.util.ChromeTabUtils; import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.InfoBarUtil; import org.chromium.chrome.test.util.InfoBarUtil;
import org.chromium.chrome.test.util.browser.Features; import org.chromium.chrome.test.util.browser.Features;
import org.chromium.components.download.DownloadState;
import org.chromium.content_public.browser.test.util.Criteria; 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.CriteriaHelper;
import org.chromium.content_public.browser.test.util.DOMUtils; import org.chromium.content_public.browser.test.util.DOMUtils;
...@@ -54,7 +55,9 @@ import org.chromium.net.test.util.TestWebServer; ...@@ -54,7 +55,9 @@ import org.chromium.net.test.util.TestWebServer;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* Tests Chrome download feature by attempting to download some files. * Tests Chrome download feature by attempting to download some files.
...@@ -105,6 +108,18 @@ import java.util.List; ...@@ -105,6 +108,18 @@ import java.util.List;
} }
} }
static class TestDownloadInfoBarController extends DownloadInfoBarController {
public TestDownloadInfoBarController() {
super(false);
}
@Override
protected void showInfoBar(
@DownloadInfoBarState int state, DownloadProgressInfoBarData info) {
// Do nothing, so we don't impact other info bars.
}
}
public DownloadTest(boolean useDownloadOfflineContentProvider) { public DownloadTest(boolean useDownloadOfflineContentProvider) {
mUseDownloadOfflineContentProvider = useDownloadOfflineContentProvider; mUseDownloadOfflineContentProvider = useDownloadOfflineContentProvider;
} }
...@@ -131,6 +146,15 @@ import java.util.List; ...@@ -131,6 +146,15 @@ import java.util.List;
mDownloadTestRule.startMainActivityOnBlankPage(); mDownloadTestRule.startMainActivityOnBlankPage();
} }
void waitForLastDownloadToFinish() {
CriteriaHelper.pollUiThread(() -> {
List<DownloadItem> downloads = mDownloadTestRule.getAllDownloads();
Criteria.checkThat(downloads.size(), Matchers.greaterThanOrEqualTo(1));
Criteria.checkThat(downloads.get(downloads.size() - 1).getDownloadInfo().state(),
Matchers.is(DownloadState.COMPLETE));
});
}
@Test @Test
@MediumTest @MediumTest
@Feature({"Downloads"}) @Feature({"Downloads"})
...@@ -235,28 +259,39 @@ import java.util.List; ...@@ -235,28 +259,39 @@ import java.util.List;
@Test @Test
@MediumTest @MediumTest
@Feature({"Downloads"}) @Feature({"Downloads"})
@DisabledTest(message = "crbug.com/597230")
public void testDuplicateHttpPostDownload_Cancel() { public void testDuplicateHttpPostDownload_Cancel() {
// Remove download progress info bar.
TestThreadUtils.runOnUiThreadBlocking(
()
-> DownloadManagerService.getDownloadManagerService()
.setInfoBarControllerForTesting(
new TestDownloadInfoBarController()));
// Download a file. // Download a file.
mDownloadTestRule.loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "post.html")); mDownloadTestRule.loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "post.html"));
waitForFocus(); waitForFocus();
View currentView = mDownloadTestRule.getActivity().getActivityTab().getView(); View currentView = mDownloadTestRule.getActivity().getActivityTab().getView();
int callCount = mDownloadTestRule.getChromeDownloadCallCount();
TouchCommon.singleClickView(currentView); TouchCommon.singleClickView(currentView);
Assert.assertTrue("Failed to finish downloading file for the first time.", waitForLastDownloadToFinish();
mDownloadTestRule.waitForChromeDownloadToFinish(callCount)); int downloadCount = mDownloadTestRule.getAllDownloads().size();
// Download a file with the same name. // Download a file with the same name.
mDownloadTestRule.loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "post.html")); mDownloadTestRule.loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "post.html"));
waitForFocus(); waitForFocus();
currentView = mDownloadTestRule.getActivity().getActivityTab().getView(); currentView = mDownloadTestRule.getActivity().getActivityTab().getView();
callCount = mDownloadTestRule.getChromeDownloadCallCount();
TouchCommon.singleClickView(currentView); TouchCommon.singleClickView(currentView);
assertPollForInfoBarSize(1); assertPollForInfoBarSize(1);
Assert.assertTrue("CREATE NEW button wasn't found", Assert.assertTrue("CANCEL button wasn't found",
InfoBarUtil.clickSecondaryButton(mDownloadTestRule.getInfoBars().get(0))); InfoBarUtil.clickSecondaryButton(mDownloadTestRule.getInfoBars().get(0)));
Assert.assertFalse("Download should not happen when clicking cancel button", InfoBarUtil.waitUntilNoInfoBarsExist(mDownloadTestRule.getInfoBars());
mDownloadTestRule.waitForChromeDownloadToFinish(callCount)); // The download should be canceled.
List<DownloadItem> downloads = mDownloadTestRule.getAllDownloads();
Assert.assertEquals(downloads.size(), downloadCount + 1);
Set<Integer> states =
new HashSet<>(Arrays.asList(downloads.get(downloadCount).getDownloadInfo().state(),
downloads.get(downloadCount - 1).getDownloadInfo().state()));
Assert.assertEquals(states,
new HashSet<>(Arrays.asList(DownloadState.COMPLETE, DownloadState.CANCELLED)));
} }
@Test @Test
...@@ -291,56 +326,6 @@ import java.util.List; ...@@ -291,56 +326,6 @@ import java.util.List;
mDownloadTestRule.hasDownload(FILENAME_TEXT_1, SUPERBO_CONTENTS)); mDownloadTestRule.hasDownload(FILENAME_TEXT_1, SUPERBO_CONTENTS));
} }
@Test
@MediumTest
@Feature({"Downloads"})
@DisabledTest(message = "crbug.com/597230")
public void testDuplicateHttpPostDownload_AllowMultipleInfoBars() throws Exception {
Assert.assertFalse(mDownloadTestRule.hasDownload(FILENAME_TEXT, SUPERBO_CONTENTS));
// Download a file.
mDownloadTestRule.loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "post.html"));
waitForFocus();
View currentView = mDownloadTestRule.getActivity().getActivityTab().getView();
int callCount = mDownloadTestRule.getChromeDownloadCallCount();
TouchCommon.singleClickView(currentView);
Assert.assertTrue("Failed to finish downloading file for the first time.",
mDownloadTestRule.waitForChromeDownloadToFinish(callCount));
// Download the file for the second time.
mDownloadTestRule.loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "post.html"));
waitForFocus();
currentView = mDownloadTestRule.getActivity().getActivityTab().getView();
TouchCommon.singleClickView(currentView);
assertPollForInfoBarSize(1);
// Download the file for the third time.
mDownloadTestRule.loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "post.html"));
waitForFocus();
currentView = mDownloadTestRule.getActivity().getActivityTab().getView();
TouchCommon.singleClickView(currentView);
assertPollForInfoBarSize(2);
// Now create two new files by clicking on the infobars.
callCount = mDownloadTestRule.getChromeDownloadCallCount();
Assert.assertTrue("CREATE NEW button wasn't found",
InfoBarUtil.clickSecondaryButton(mDownloadTestRule.getInfoBars().get(0)));
Assert.assertTrue("Failed to finish downloading the second file.",
mDownloadTestRule.waitForChromeDownloadToFinish(callCount));
assertPollForInfoBarSize(1);
callCount = mDownloadTestRule.getChromeDownloadCallCount();
Assert.assertTrue("CREATE NEW button wasn't found",
InfoBarUtil.clickSecondaryButton(mDownloadTestRule.getInfoBars().get(0)));
Assert.assertTrue("Failed to finish downloading the third file.",
mDownloadTestRule.waitForChromeDownloadToFinish(callCount));
Assert.assertTrue("Missing first download",
mDownloadTestRule.hasDownload(FILENAME_TEXT, SUPERBO_CONTENTS));
Assert.assertTrue("Missing second download",
mDownloadTestRule.hasDownload(FILENAME_TEXT_1, SUPERBO_CONTENTS));
Assert.assertTrue("Missing third download",
mDownloadTestRule.hasDownload(FILENAME_TEXT_2, SUPERBO_CONTENTS));
}
private void goToLastTab() { private void goToLastTab() {
final TabModel model = mDownloadTestRule.getActivity().getCurrentTabModel(); final TabModel model = mDownloadTestRule.getActivity().getCurrentTabModel();
final int count = model.getCount(); final int count = model.getCount();
......
...@@ -51,6 +51,7 @@ public class DownloadTestRule extends ChromeActivityTestRule<ChromeActivity> { ...@@ -51,6 +51,7 @@ public class DownloadTestRule extends ChromeActivityTestRule<ChromeActivity> {
public static final long UPDATE_DELAY_MILLIS = 1000; public static final long UPDATE_DELAY_MILLIS = 1000;
private final CustomMainActivityStart mActivityStart; private final CustomMainActivityStart mActivityStart;
private List<DownloadItem> mAllDownloads;
public DownloadTestRule(CustomMainActivityStart action) { public DownloadTestRule(CustomMainActivityStart action) {
super(ChromeActivity.class); super(ChromeActivity.class);
...@@ -186,10 +187,18 @@ public class DownloadTestRule extends ChromeActivityTestRule<ChromeActivity> { ...@@ -186,10 +187,18 @@ public class DownloadTestRule extends ChromeActivityTestRule<ChromeActivity> {
return eventReceived; return eventReceived;
} }
public List<DownloadItem> getAllDownloads() {
TestThreadUtils.runOnUiThreadBlocking(() -> {
DownloadManagerService.getDownloadManagerService().getAllDownloads(false);
});
return mAllDownloads;
}
private class TestDownloadManagerServiceObserver private class TestDownloadManagerServiceObserver
implements DownloadManagerService.DownloadObserver { implements DownloadManagerService.DownloadObserver {
@Override @Override
public void onAllDownloadsRetrieved(final List<DownloadItem> list, boolean isOffTheRecord) { public void onAllDownloadsRetrieved(final List<DownloadItem> list, boolean isOffTheRecord) {
mAllDownloads = list;
} }
@Override @Override
......
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