Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtilsTest.java

Issue 2081153005: [Offline Page] Offline page sharing implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adjustments according to Filip's comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtilsTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtilsTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtilsTest.java
index 239cb671d4533550a43dfa5713ef0e490e59ddcf..0fef4a8d44e9ed1ad75edfe5017ff5c39400deb4 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtilsTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtilsTest.java
@@ -26,6 +26,7 @@ import org.chromium.net.ConnectionType;
import org.chromium.net.NetworkChangeNotifier;
import org.chromium.net.test.EmbeddedTestServer;
+import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Semaphore;
@@ -36,6 +37,8 @@ import java.util.concurrent.TimeUnit;
public class OfflinePageUtilsTest extends ChromeActivityTestCaseBase<ChromeActivity> {
private static final String TAG = "OfflinePageUtilsTest";
private static final String TEST_PAGE = "/chrome/test/data/android/about.html";
+ private static final String CACHE_DIRECTORY =
+ "/storage/emulated/0/Android/data/org.chromium.chrome/cache/offline-pages";
private static final int TIMEOUT_MS = 5000;
private static final ClientId BOOKMARK_ID =
new ClientId(OfflinePageBridge.BOOKMARK_NAMESPACE, "1234");
@@ -242,4 +245,70 @@ public class OfflinePageUtilsTest extends ChromeActivityTestCaseBase<ChromeActiv
assertTrue(semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS));
return result;
}
+
+ @SmallTest
+ public void testCopyToShareableLocation() throws Exception {
+ // Save an offline page.
+ String testUrl = mTestServer.getURL(TEST_PAGE);
+ loadUrl(testUrl);
+ savePage(SavePageResult.SUCCESS, testUrl);
+
+ // Get an offline page from the list and obtain the file path.
+ List<OfflinePageItem> allPages = getAllPages();
+ OfflinePageItem offlinePage = allPages.get(0);
+ String offlinePageFilePath = offlinePage.getFilePath();
+
+ File offlinePageOriginal = new File(offlinePageFilePath);
+
+ File offlineCacheDir = new File(CACHE_DIRECTORY);
+ boolean success = true;
fgorski 2016/08/11 16:57:53 boolean success = offlineCacheDir.exists() || offl
Vivian 2016/08/11 23:18:29 Done.
+ if (!offlineCacheDir.exists() && !offlineCacheDir.mkdir()) {
+ success = false;
+ }
+ assertTrue("Should be able to create subdirectory in shareable directory.", success);
+
+ File offlinePageShareable = new File(CACHE_DIRECTORY, offlinePageOriginal.getName());
+ if (!offlinePageShareable.exists()) {
+ assertTrue("Should be able to copy file to shareable location.",
+ OfflinePageUtils.copyToShareableLocation(
+ offlinePageOriginal, offlinePageShareable));
+ assertEquals("File copy result incorrect", offlinePageOriginal.length(),
fgorski 2016/08/11 16:57:53 Let's see if that works on try bots.
+ offlinePageShareable.length());
+ }
+ }
+
+ @SmallTest
+ public void testDeleteSharedOfflineFiles() throws Exception {
+ // Save an offline page.
+ String testUrl = mTestServer.getURL(TEST_PAGE);
+ loadUrl(testUrl);
+ savePage(SavePageResult.SUCCESS, testUrl);
+
+ // Copies file to external cache directory.
+ List<OfflinePageItem> allPages = getAllPages();
+ OfflinePageItem offlinePage = allPages.get(0);
+ String offlinePageFilePath = offlinePage.getFilePath();
+
+ File offlinePageOriginal = new File(offlinePageFilePath);
+
+ File offlineCacheDir = new File(CACHE_DIRECTORY);
+ boolean success = true;
+ if (!offlineCacheDir.exists() && !offlineCacheDir.mkdir()) {
+ success = false;
+ }
+ assertTrue("Unable to create subdirectory in shareable directory.", success);
+
+ File offlinePageShareable = new File(CACHE_DIRECTORY, offlinePageOriginal.getName());
+ if (!offlinePageShareable.exists()) {
+ assertTrue("Should be able to copy file to shareable location.",
+ OfflinePageUtils.copyToShareableLocation(
+ offlinePageOriginal, offlinePageShareable));
+ }
+
+ // Clear files.
+ Context context = getActivity().getBaseContext();
+ OfflinePageUtils.deleteSharedOfflineFiles(offlineCacheDir);
+
+ assertFalse("Chache directory should be deleted.", offlineCacheDir.exists());
+ }
}

Powered by Google App Engine
This is Rietveld 408576698