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

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: Address 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 b1274372a4c6015019895988983421589f4d70d0..2d1dcb9fbdf76c1e81924956330b11ce06942684 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
@@ -25,8 +25,10 @@ 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.UUID;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
@@ -236,4 +238,73 @@ 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);
Theresa 2016/08/15 20:50:00 It looks like the code to save an offline page is
Vivian 2016/08/16 17:40:12 Done.
+ 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);
+
+ // Clear the directory before perform file copying.
+ Context context = getActivity().getBaseContext();
+ OfflinePageUtils.clearSharedOfflineFiles(context);
+
+ File offlineCacheDir =
+ OfflinePageUtils.getDirectoryForOfflineSharing(getActivity().getBaseContext());
+
+ boolean success = (offlineCacheDir != null);
+ assertTrue("Should be able to create subdirectory in shareable directory.", success);
+
+ // Use a random file name for test issue.
Theresa 2016/08/15 20:50:00 What is the test issue that requires using a rando
Vivian 2016/08/16 17:40:12 This is deprecated after adding clearing directory
+ File offlinePageShareable = new File(offlineCacheDir, UUID.randomUUID().toString());
+
+ assertFalse("Should not exist a file with same file name,", offlinePageShareable.exists());
Theresa 2016/08/15 20:50:00 "The shareable offline page file should lot alread
Vivian 2016/08/16 17:40:12 Done.
+ assertTrue("Should be able to copy file to shareable location.",
+ OfflinePageUtils.copyToShareableLocation(
+ offlinePageOriginal, offlinePageShareable));
+ assertEquals("File copy result incorrect", offlinePageOriginal.length(),
+ 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 =
+ OfflinePageUtils.getDirectoryForOfflineSharing(getActivity().getBaseContext());
+
+ boolean success = (offlineCacheDir != null);
+ assertTrue("Should be able to create subdirectory in shareable directory.", success);
+
+ File offlinePageShareable = new File(offlineCacheDir, 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.clearSharedOfflineFiles(context);
+
+ assertFalse("Chache directory should be deleted.", offlineCacheDir.exists());
+ }
}

Powered by Google App Engine
This is Rietveld 408576698