| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.test.util; | 5 package org.chromium.chrome.test.util; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 | 8 |
| 9 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; | 9 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 * framework does not try to create it for sandbox processes and fail. | 34 * framework does not try to create it for sandbox processes and fail. |
| 35 * | 35 * |
| 36 * When this is invoked from tests, the target context from the instrumentat
ion must be used. | 36 * When this is invoked from tests, the target context from the instrumentat
ion must be used. |
| 37 * | 37 * |
| 38 * @param targetContext the target Context. | 38 * @param targetContext the target Context. |
| 39 */ | 39 */ |
| 40 public static void clearAppData(Context targetContext) throws InterruptedExc
eption { | 40 public static void clearAppData(Context targetContext) throws InterruptedExc
eption { |
| 41 final String appDir = getAppDirFromTargetContext(targetContext); | 41 final String appDir = getAppDirFromTargetContext(targetContext); |
| 42 CriteriaHelper.pollInstrumentationThread( | 42 CriteriaHelper.pollInstrumentationThread( |
| 43 new Criteria() { | 43 new Criteria() { |
| 44 private boolean mDataRemoved = false; | 44 private boolean mDataRemoved; |
| 45 | 45 |
| 46 @Override | 46 @Override |
| 47 public boolean isSatisfied() { | 47 public boolean isSatisfied() { |
| 48 if (!mDataRemoved && !removeAppData(appDir)) { | 48 if (!mDataRemoved && !removeAppData(appDir)) { |
| 49 return false; | 49 return false; |
| 50 } | 50 } |
| 51 mDataRemoved = true; | 51 mDataRemoved = true; |
| 52 // We have to make sure the cache directory still exists
, as the framework | 52 // We have to make sure the cache directory still exists
, as the framework |
| 53 // will try to create it otherwise and will fail for san
dbox processes with | 53 // will try to create it otherwise and will fail for san
dbox processes with |
| 54 // a NullPointerException. | 54 // a NullPointerException. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 if (file.isDirectory()) { | 104 if (file.isDirectory()) { |
| 105 File[] files = file.listFiles(); | 105 File[] files = file.listFiles(); |
| 106 if (files == null) return true; | 106 if (files == null) return true; |
| 107 for (File sub_file : files) { | 107 for (File sub_file : files) { |
| 108 if (!removeFile(sub_file)) return false; | 108 if (!removeFile(sub_file)) return false; |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 return file.delete(); | 111 return file.delete(); |
| 112 } | 112 } |
| 113 } | 113 } |
| OLD | NEW |