| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.browser.test; | 5 package org.chromium.chrome.browser.test; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.support.test.InstrumentationRegistry; |
| 8 | 8 |
| 9 import org.junit.rules.TestRule; | 9 import org.junit.rules.TestRule; |
| 10 import org.junit.runner.Description; | 10 import org.junit.runner.Description; |
| 11 import org.junit.runners.model.Statement; | 11 import org.junit.runners.model.Statement; |
| 12 | 12 |
| 13 import org.chromium.chrome.test.util.ApplicationData; | 13 import org.chromium.chrome.test.util.ApplicationData; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * JUnit test rule that just clears app data before each test. Having this as a
rule allows us | 16 * JUnit test rule that just clears app data before each test. Having this as a
rule allows us |
| 17 * to ensure the order it's executed in with something like RuleChain, allowing
us to execute it | 17 * to ensure the order it's executed in with something like RuleChain, allowing
us to execute it |
| 18 * prior to launching the browser process. | 18 * prior to launching the browser process. |
| 19 */ | 19 */ |
| 20 public class ClearAppDataTestRule implements TestRule { | 20 public class ClearAppDataTestRule implements TestRule { |
| 21 Context mContext; | |
| 22 | |
| 23 public ClearAppDataTestRule(Context context) { | |
| 24 mContext = context; | |
| 25 } | |
| 26 | |
| 27 @Override | 21 @Override |
| 28 public Statement apply(final Statement base, Description description) { | 22 public Statement apply(final Statement base, Description description) { |
| 29 return new Statement() { | 23 return new Statement() { |
| 30 @Override | 24 @Override |
| 31 public void evaluate() throws Throwable { | 25 public void evaluate() throws Throwable { |
| 32 ApplicationData.clearAppData(mContext); | 26 ApplicationData.clearAppData(InstrumentationRegistry.getContext(
)); |
| 33 } | 27 } |
| 34 }; | 28 }; |
| 35 } | 29 } |
| 36 } | 30 } |
| OLD | NEW |