Commit 81804dcb authored by fgorski's avatar fgorski Committed by Commit bot

[Offline pages] Reenabling sharing tests

This makes an update to OfflinePageUtilsTest.testCopyToShareableLocation
to make it more reliable (by ensuring a more proper clean up).

BUG=640319

patch from issue 2259413002 at patchset 1 (http://crrev.com/2259413002#ps1)

Review-Url: https://codereview.chromium.org/2303443002
Cr-Commit-Position: refs/heads/master@{#415784}
parent 265b1369
...@@ -11,7 +11,6 @@ import android.test.suitebuilder.annotation.SmallTest; ...@@ -11,7 +11,6 @@ import android.test.suitebuilder.annotation.SmallTest;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.offlinepages.OfflinePageBridge.OfflinePageModelObserver; import org.chromium.chrome.browser.offlinepages.OfflinePageBridge.OfflinePageModelObserver;
import org.chromium.chrome.browser.offlinepages.OfflinePageBridge.SavePageCallback; import org.chromium.chrome.browser.offlinepages.OfflinePageBridge.SavePageCallback;
...@@ -244,7 +243,6 @@ public class OfflinePageUtilsTest extends ChromeActivityTestCaseBase<ChromeActiv ...@@ -244,7 +243,6 @@ public class OfflinePageUtilsTest extends ChromeActivityTestCaseBase<ChromeActiv
return result; return result;
} }
@DisabledTest(message = "Flaky, crbug.com/640319")
@SmallTest @SmallTest
public void testCopyToShareableLocation() throws Exception { public void testCopyToShareableLocation() throws Exception {
// Save an offline page. // Save an offline page.
...@@ -257,22 +255,20 @@ public class OfflinePageUtilsTest extends ChromeActivityTestCaseBase<ChromeActiv ...@@ -257,22 +255,20 @@ public class OfflinePageUtilsTest extends ChromeActivityTestCaseBase<ChromeActiv
File offlinePageOriginal = new File(offlinePageFilePath); File offlinePageOriginal = new File(offlinePageFilePath);
// Clear the directory before perform file copying. // Clear the directory before copying the file.
Context context = getActivity().getBaseContext(); clearSharedOfflineFilesAndWait();
OfflinePageUtils.clearSharedOfflineFiles(context);
File offlineCacheDir = File offlineSharingDir =
OfflinePageUtils.getDirectoryForOfflineSharing(getActivity().getBaseContext()); OfflinePageUtils.getDirectoryForOfflineSharing(getActivity().getBaseContext());
assertTrue("Offline sharing directory should exist.", offlineSharingDir != null);
assertTrue("The shareable offline page file should not already exist.", File offlinePageShareable = new File(offlineSharingDir, offlinePageOriginal.getName());
(offlineCacheDir != null));
File offlinePageShareable = new File(offlineCacheDir, offlinePageOriginal.getName());
assertFalse("File with the same name should not exist.", offlinePageShareable.exists()); assertFalse("File with the same name should not exist.", offlinePageShareable.exists());
assertTrue("Should be able to copy file to shareable location.", assertTrue("Should be able to copy file to shareable location.",
OfflinePageUtils.copyToShareableLocation( OfflinePageUtils.copyToShareableLocation(
offlinePageOriginal, offlinePageShareable)); offlinePageOriginal, offlinePageShareable));
assertEquals("File copy result incorrect", offlinePageOriginal.length(), assertEquals("File copy result incorrect", offlinePageOriginal.length(),
offlinePageShareable.length()); offlinePageShareable.length());
} }
...@@ -290,12 +286,12 @@ public class OfflinePageUtilsTest extends ChromeActivityTestCaseBase<ChromeActiv ...@@ -290,12 +286,12 @@ public class OfflinePageUtilsTest extends ChromeActivityTestCaseBase<ChromeActiv
File offlinePageOriginal = new File(offlinePageFilePath); File offlinePageOriginal = new File(offlinePageFilePath);
final Context context = getActivity().getBaseContext(); final Context context = getActivity().getBaseContext();
final File offlineCacheDir = OfflinePageUtils.getDirectoryForOfflineSharing(context); final File offlineSharingDir = OfflinePageUtils.getDirectoryForOfflineSharing(context);
assertTrue("Should be able to create subdirectory in shareable directory.", assertTrue("Should be able to create subdirectory in shareable directory.",
(offlineCacheDir != null)); (offlineSharingDir != null));
File offlinePageShareable = new File(offlineCacheDir, offlinePageOriginal.getName()); File offlinePageShareable = new File(offlineSharingDir, offlinePageOriginal.getName());
if (!offlinePageShareable.exists()) { if (!offlinePageShareable.exists()) {
assertTrue("Should be able to copy file to shareable location.", assertTrue("Should be able to copy file to shareable location.",
OfflinePageUtils.copyToShareableLocation( OfflinePageUtils.copyToShareableLocation(
...@@ -303,19 +299,23 @@ public class OfflinePageUtilsTest extends ChromeActivityTestCaseBase<ChromeActiv ...@@ -303,19 +299,23 @@ public class OfflinePageUtilsTest extends ChromeActivityTestCaseBase<ChromeActiv
} }
// Clear files. // Clear files.
clearSharedOfflineFilesAndWait();
}
private void clearSharedOfflineFilesAndWait() {
Context context = getActivity().getBaseContext();
final File offlineSharingDir = OfflinePageUtils.getDirectoryForOfflineSharing(context);
OfflinePageUtils.clearSharedOfflineFiles(context); OfflinePageUtils.clearSharedOfflineFiles(context);
try { try {
CriteriaHelper.pollInstrumentationThread( CriteriaHelper.pollInstrumentationThread(
new Criteria("Failed while waiting for file operation to complete.") { new Criteria("Failed while waiting for file operation to complete.") {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
return !offlineCacheDir.exists(); return !offlineSharingDir.exists();
} }
}); });
} catch (InterruptedException e) { } catch (InterruptedException e) {
fail("Failed while waiting for file operation to complete." + e); fail("Failed while waiting for file operation to complete." + e);
} }
assertFalse("Cache directory should be deleted.", offlineCacheDir.exists());
} }
} }
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