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; ...@@ -28,6 +28,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch;
/** /**
* Instrumentation tests for {@link MostVisitedSitesMetadataUtils}. * Instrumentation tests for {@link MostVisitedSitesMetadataUtils}.
...@@ -47,7 +48,7 @@ public class MostVisitedSitesMetadataUtilsTest { ...@@ -47,7 +48,7 @@ public class MostVisitedSitesMetadataUtilsTest {
@Test @Test
@SmallTest @SmallTest
public void testSaveRestoreConsistency() { public void testSaveRestoreConsistency() throws InterruptedException, IOException {
mExpectedSiteSuggestions = createFakeSiteSuggestions(); mExpectedSiteSuggestions = createFakeSiteSuggestions();
// Get old file and ensure to delete it. // Get old file and ensure to delete it.
...@@ -55,20 +56,19 @@ public class MostVisitedSitesMetadataUtilsTest { ...@@ -55,20 +56,19 @@ public class MostVisitedSitesMetadataUtilsTest {
assertTrue(oldFile.delete() && !oldFile.exists()); assertTrue(oldFile.delete() && !oldFile.exists());
// Save suggestion lists to file. // Save suggestion lists to file.
MostVisitedSitesMetadataUtils.saveSuggestionListsToFile(mExpectedSiteSuggestions, () -> { final CountDownLatch latch = new CountDownLatch(1);
// Restore list from file after saving finished. MostVisitedSitesMetadataUtils.saveSuggestionListsToFile(
List<SiteSuggestion> sitesAfterRestore = null; mExpectedSiteSuggestions, latch::countDown);
try { // Wait util the file has been saved.
sitesAfterRestore = latch.await();
MostVisitedSitesMetadataUtils.restoreFileToSuggestionListsOnUiThread();
} catch (IOException e) { // Restore list from file after saving finished.
e.printStackTrace(); List<SiteSuggestion> sitesAfterRestore =
} MostVisitedSitesMetadataUtils.restoreFileToSuggestionLists();
// Ensure that the new list equals to old list. // Ensure that the new list equals to old list.
assertEquals(mExpectedSiteSuggestions, sitesAfterRestore); assertEquals(mExpectedSiteSuggestions, sitesAfterRestore);
});
} }
@Test(expected = IOException.class) @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