Commit ac05859d authored by Min Qin's avatar Min Qin Committed by Commit Bot

Wait for canceled download to fix flakiness

The test is failing on some bot as the download is still in progress
This CL ask the test to wait for the download to enter a canceled state.

BUG=1130550

Change-Id: Icfeb01ebbab20cd901cefe16870b6cbe98be3d59
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2422163
Commit-Queue: Min Qin <qinmin@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809948}
parent 7dd7f7a4
...@@ -57,9 +57,7 @@ import org.chromium.net.test.util.TestWebServer; ...@@ -57,9 +57,7 @@ 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.
...@@ -157,6 +155,21 @@ import java.util.Set; ...@@ -157,6 +155,21 @@ import java.util.Set;
}); });
} }
void waitForAnyDownloadToCancel() {
CriteriaHelper.pollUiThread(() -> {
List<DownloadItem> downloads = mDownloadTestRule.getAllDownloads();
Criteria.checkThat(downloads.size(), Matchers.greaterThanOrEqualTo(1));
boolean hasCanceled = false;
for (DownloadItem download : downloads) {
if (download.getDownloadInfo().state() == DownloadState.CANCELLED) {
hasCanceled = true;
break;
}
}
Criteria.checkThat(hasCanceled, Matchers.is(true));
});
}
@Test @Test
@MediumTest @MediumTest
@Feature({"Downloads"}) @Feature({"Downloads"})
...@@ -260,7 +273,6 @@ import java.util.Set; ...@@ -260,7 +273,6 @@ import java.util.Set;
@Test @Test
@MediumTest @MediumTest
@DisabledTest(message = "crbug.com/1130550")
@Feature({"Downloads"}) @Feature({"Downloads"})
public void testDuplicateHttpPostDownload_Cancel() { public void testDuplicateHttpPostDownload_Cancel() {
// Remove download progress info bar. // Remove download progress info bar.
...@@ -294,13 +306,7 @@ import java.util.Set; ...@@ -294,13 +306,7 @@ import java.util.Set;
InfoBarUtil.clickSecondaryButton(findDuplicateDownloadInfoBar())); InfoBarUtil.clickSecondaryButton(findDuplicateDownloadInfoBar()));
// The download should be canceled. // The download should be canceled.
List<DownloadItem> downloads = mDownloadTestRule.getAllDownloads(); waitForAnyDownloadToCancel();
Assert.assertEquals(downloads.size(), downloadCount + 1);
Set<Integer> states = new HashSet<>(
Arrays.asList(downloads.get(downloads.size() - 1).getDownloadInfo().state(),
downloads.get(downloads.size() - 2).getDownloadInfo().state()));
Assert.assertEquals(states,
new HashSet<>(Arrays.asList(DownloadState.COMPLETE, DownloadState.CANCELLED)));
} }
@Test @Test
......
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