Commit bbb6353c authored by spdonghao's avatar spdonghao Committed by Commit Bot

Move restore out to instrumentation thread.

Bug: 1061906
Change-Id: I6ced07e139c6be9a96ce32d8d1c5e3e2f1e9f74d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2153585Reviewed-by: default avatarCathy Li <chili@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Commit-Queue: Hao Dong <spdonghao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#761067}
parent 0f74b382
......@@ -28,6 +28,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CountDownLatch;
/**
* Instrumentation tests for {@link MostVisitedSitesMetadataUtils}.
......@@ -47,7 +48,7 @@ public class MostVisitedSitesMetadataUtilsTest {
@Test
@SmallTest
public void testSaveRestoreConsistency() {
public void testSaveRestoreConsistency() throws InterruptedException, IOException {
mExpectedSiteSuggestions = createFakeSiteSuggestions();
// Get old file and ensure to delete it.
......@@ -55,20 +56,19 @@ public class MostVisitedSitesMetadataUtilsTest {
assertTrue(oldFile.delete() && !oldFile.exists());
// Save suggestion lists to file.
MostVisitedSitesMetadataUtils.saveSuggestionListsToFile(mExpectedSiteSuggestions, () -> {
// Restore list from file after saving finished.
List<SiteSuggestion> sitesAfterRestore = null;
try {
sitesAfterRestore =
MostVisitedSitesMetadataUtils.restoreFileToSuggestionListsOnUiThread();
} catch (IOException e) {
e.printStackTrace();
}
// Ensure that the new list equals to old list.
assertEquals(mExpectedSiteSuggestions, sitesAfterRestore);
});
final CountDownLatch latch = new CountDownLatch(1);
MostVisitedSitesMetadataUtils.saveSuggestionListsToFile(
mExpectedSiteSuggestions, latch::countDown);
// Wait util the file has been saved.
latch.await();
// Restore list from file after saving finished.
List<SiteSuggestion> sitesAfterRestore =
MostVisitedSitesMetadataUtils.restoreFileToSuggestionLists();
// Ensure that the new list equals to old list.
assertEquals(mExpectedSiteSuggestions, sitesAfterRestore);
}
@Test(expected = IOException.class)
......
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