Commit 0547b535 authored by Yun Liu's avatar Yun Liu Committed by Commit Bot

Reset RecordUserAction and RecordHistogram after each DummyUiActivity test

https://cs.chromium.org/chromium/src/base/android/java/src/org/chromium/base/metrics/RecordUserAction.java?q=RecordUserAction&g=0&l=26-27
It seems we need to reset the value to avoid carrying over state to
unrelated tests after test is done. Moved them to DummyUiActivityTestCase
to set and reset them by default.

Bug: 728297, 908174
Change-Id: If9462012a967933e927b5e0987944d03110bab5f
Reviewed-on: https://chromium-review.googlesource.com/c/1492368
Commit-Queue: Yun Liu <yliuyliu@google.com>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636233}
parent 9a73ad4f
...@@ -18,8 +18,6 @@ import org.mockito.Mock; ...@@ -18,8 +18,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.base.test.util.Restriction; import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList; import org.chromium.chrome.browser.ChromeFeatureList;
...@@ -60,8 +58,6 @@ public class DownloadActivityV2Test extends DummyUiActivityTestCase { ...@@ -60,8 +58,6 @@ public class DownloadActivityV2Test extends DummyUiActivityTestCase {
@BeforeClass @BeforeClass
public static void setUpBeforeActivityLaunched() { public static void setUpBeforeActivityLaunched() {
RecordUserAction.setDisabledForTests(true);
RecordHistogram.setDisabledForTests(true);
UiUtils.setDisableUrlFormattingForTests(true); UiUtils.setDisableUrlFormattingForTests(true);
DummyUiActivity.setTestTheme(R.style.Theme_Chromium_Activity_Fullscreen); DummyUiActivity.setTestTheme(R.style.Theme_Chromium_Activity_Fullscreen);
} }
......
...@@ -13,6 +13,9 @@ import org.junit.rules.TestRule; ...@@ -13,6 +13,9 @@ import org.junit.rules.TestRule;
import org.junit.runner.Description; import org.junit.runner.Description;
import org.junit.runners.model.Statement; import org.junit.runners.model.Statement;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction;
/** /**
* Test case to instrument DummyUiActivity for UI testing scenarios. * Test case to instrument DummyUiActivity for UI testing scenarios.
* Recommend to use setUpTest() and tearDownTest() to setup and tear down instead of @Before and * Recommend to use setUpTest() and tearDownTest() to setup and tear down instead of @Before and
...@@ -40,6 +43,7 @@ public class DummyUiActivityTestCase { ...@@ -40,6 +43,7 @@ public class DummyUiActivityTestCase {
return new Statement() { return new Statement() {
@Override @Override
public void evaluate() throws Throwable { public void evaluate() throws Throwable {
mActivity = mActivityTestRule.getActivity();
setUpTest(); setUpTest();
try { try {
base.evaluate(); base.evaluate();
...@@ -53,11 +57,15 @@ public class DummyUiActivityTestCase { ...@@ -53,11 +57,15 @@ public class DummyUiActivityTestCase {
// Override this to setup before test. // Override this to setup before test.
public void setUpTest() throws Exception { public void setUpTest() throws Exception {
mActivity = mActivityTestRule.getActivity(); RecordHistogram.setDisabledForTests(true);
RecordUserAction.setDisabledForTests(true);
} }
// Override this to tear down after test. // Override this to tear down after test.
public void tearDownTest() throws Exception {} public void tearDownTest() throws Exception {
RecordHistogram.setDisabledForTests(false);
RecordUserAction.setDisabledForTests(false);
}
public DummyUiActivity getActivity() { public DummyUiActivity getActivity() {
return mActivity; return mActivity;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment