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

Unified Diff: chrome/test/android/javatests/src/org/chromium/chrome/test/util/ApplicationData.java

Issue 2849323002: Revert of [Android] Keep extracted secondary dex files when clearing data in tests. (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « chrome/test/android/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/android/javatests/src/org/chromium/chrome/test/util/ApplicationData.java
diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/ApplicationData.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/ApplicationData.java
index cb776fe348467d4fa78eecf17dc299028b49075b..e861035e527e7b06a4d0de017572cc09eab8b64a 100644
--- a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/ApplicationData.java
+++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/ApplicationData.java
@@ -4,10 +4,7 @@
package org.chromium.chrome.test.util;
-import android.annotation.SuppressLint;
import android.content.Context;
-import android.content.SharedPreferences;
-import android.support.v4.content.ContextCompat;
import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
@@ -40,33 +37,40 @@
*
* @param targetContext the target Context.
*/
- public static void clearAppData(final Context targetContext) {
+ public static void clearAppData(Context targetContext) {
+ final String appDir = getAppDirFromTargetContext(targetContext);
CriteriaHelper.pollInstrumentationThread(
new Criteria() {
private boolean mDataRemoved;
- @SuppressLint("CommitPrefEdits")
@Override
public boolean isSatisfied() {
- SharedPreferences multidexPrefs =
- targetContext.getSharedPreferences("multidex.version", 0);
- if (!mDataRemoved && !removeAppData(targetContext)) {
+ if (!mDataRemoved && !removeAppData(appDir)) {
return false;
}
mDataRemoved = true;
// We have to make sure the cache directory still exists, as the framework
// will try to create it otherwise and will fail for sandbox processes with
// a NullPointerException.
- File cacheDir = new File(ContextCompat.getDataDir(targetContext), "cache");
- // Removing app data cleared out all shared prefs. Multidex uses shared
- // prefs to cache hashes of the secondary dexes it has extracted; without
- // them, it'll attempt to reextract the dexes the next time the tests
- // start up.
- multidexPrefs.edit().commit();
+ File cacheDir = new File(appDir, "cache");
return cacheDir.exists() || cacheDir.mkdir();
}
},
MAX_CLEAR_APP_DATA_TIMEOUT_MS, CLEAR_APP_DATA_POLL_INTERVAL_MS);
+ }
+
+ /**
+ * Find the absolute path of the application data directory for the given target context.
+ *
+ * When this is invoked from tests, the target context from the instrumentation must be used.
+ *
+ * @param targetContext the target Context.
+ *
+ * @return the absolute path of the application data directory.
+ */
+ public static String getAppDirFromTargetContext(Context targetContext) {
+ String cacheDir = targetContext.getCacheDir().getAbsolutePath();
+ return cacheDir.substring(0, cacheDir.lastIndexOf('/'));
}
/**
@@ -76,14 +80,12 @@
*
* @return whether removal succeeded.
*/
- private static boolean removeAppData(final Context targetContext) {
- File dataDir = ContextCompat.getDataDir(targetContext);
- File codeCacheDir = ContextCompat.getCodeCacheDir(targetContext);
- File[] files = dataDir.listFiles();
+ private static boolean removeAppData(String appDir) {
+ File[] files = new File(appDir).listFiles();
if (files == null) return true;
for (File file : files) {
- if (!(file.getName().equals("lib") || file.getName().equals("incremental-install-files")
- || file.getName().equals(codeCacheDir.getName()))
+ if (!(file.getName().equals("lib")
+ || file.getName().equals("incremental-install-files"))
&& !removeFile(file)) {
return false;
}
« no previous file with comments | « chrome/test/android/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698