Index: chrome/android/javatests/src/org/chromium/chrome/browser/tab/TabUmaTest.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/tab/TabUmaTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/tab/TabUmaTest.java |
index ee4cbde819d7d1eae76ff31ae63a04e5722f1189..f6eb88d2d4dd311ad9685104d18012b0ec706365 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/tab/TabUmaTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/tab/TabUmaTest.java |
@@ -4,16 +4,27 @@ |
package org.chromium.chrome.browser.tab; |
+import android.support.test.InstrumentationRegistry; |
import android.support.test.filters.MediumTest; |
+import org.junit.After; |
+import org.junit.Assert; |
+import org.junit.Before; |
+import org.junit.Rule; |
+import org.junit.Test; |
+import org.junit.runner.RunWith; |
+ |
import org.chromium.base.ThreadUtils; |
+import org.chromium.base.test.util.CommandLineFlags; |
import org.chromium.base.test.util.Feature; |
import org.chromium.base.test.util.MetricsUtils.HistogramDelta; |
import org.chromium.base.test.util.RetryOnFailure; |
import org.chromium.chrome.browser.ChromeActivity; |
+import org.chromium.chrome.browser.ChromeSwitches; |
import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; |
-import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
+import org.chromium.chrome.test.ChromeActivityTestRule; |
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
import org.chromium.content_public.browser.LoadUrlParams; |
import org.chromium.net.test.EmbeddedTestServer; |
@@ -23,48 +34,47 @@ import java.util.concurrent.ExecutionException; |
/** |
* Tests for Tab-related histogram collection. |
*/ |
+@RunWith(ChromeJUnit4ClassRunner.class) |
@RetryOnFailure |
-public class TabUmaTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
+@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
+ ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
+public class TabUmaTest { |
+ @Rule |
+ public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = |
+ new ChromeActivityTestRule<>(ChromeActivity.class); |
private static final String TEST_PATH = "/chrome/test/data/android/about.html"; |
private EmbeddedTestServer mTestServer; |
private String mTestUrl; |
- public TabUmaTest() { |
- super(ChromeActivity.class); |
- } |
- |
- @Override |
- public void startMainActivity() throws InterruptedException { |
- startMainActivityOnBlankPage(); |
- } |
- |
- @Override |
- protected void setUp() throws Exception { |
- super.setUp(); |
- mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext()); |
+ @Before |
+ public void setUp() throws Exception { |
+ mActivityTestRule.startMainActivityOnBlankPage(); |
+ mTestServer = EmbeddedTestServer.createAndStartServer( |
+ InstrumentationRegistry.getInstrumentation().getContext()); |
mTestUrl = mTestServer.getURL(TEST_PATH); |
} |
- @Override |
- protected void tearDown() throws Exception { |
+ @After |
+ public void tearDown() throws Exception { |
mTestServer.stopAndDestroyServer(); |
- super.tearDown(); |
} |
/** |
* Verify that Tab.StatusWhenSwitchedBackToForeground is correctly recording lazy loads. |
*/ |
+ @Test |
@MediumTest |
@Feature({"Uma"}) |
public void testTabStatusWhenSwitchedToLazyLoads() throws ExecutionException { |
final Tab tab = ThreadUtils.runOnUiThreadBlocking(new Callable<Tab>() { |
@Override |
public Tab call() { |
- Tab bgTab = Tab.createTabForLazyLoad(getActivity(), false, |
- getActivity().getWindowAndroid(), TabLaunchType.FROM_LONGPRESS_BACKGROUND, |
- Tab.INVALID_TAB_ID, new LoadUrlParams(mTestUrl)); |
+ Tab bgTab = Tab.createTabForLazyLoad(mActivityTestRule.getActivity(), false, |
+ mActivityTestRule.getActivity().getWindowAndroid(), |
+ TabLaunchType.FROM_LONGPRESS_BACKGROUND, Tab.INVALID_TAB_ID, |
+ new LoadUrlParams(mTestUrl)); |
bgTab.initialize(null, null, new TabDelegateFactory(), true, false); |
return bgTab; |
} |
@@ -73,7 +83,7 @@ public class TabUmaTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
String histogram = "Tab.StatusWhenSwitchedBackToForeground"; |
HistogramDelta lazyLoadCount = |
new HistogramDelta(histogram, TabUma.TAB_STATUS_LAZY_LOAD_FOR_BG_TAB); |
- assertEquals(0, lazyLoadCount.getDelta()); // Sanity check. |
+ Assert.assertEquals(0, lazyLoadCount.getDelta()); // Sanity check. |
// Show the tab and verify that one sample was recorded in the lazy load bucket. |
ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
@@ -82,7 +92,7 @@ public class TabUmaTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
tab.show(TabSelectionType.FROM_USER); |
} |
}); |
- assertEquals(1, lazyLoadCount.getDelta()); |
+ Assert.assertEquals(1, lazyLoadCount.getDelta()); |
// Show the tab again and verify that we didn't record another sample. |
ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
@@ -91,12 +101,13 @@ public class TabUmaTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
tab.show(TabSelectionType.FROM_USER); |
} |
}); |
- assertEquals(1, lazyLoadCount.getDelta()); |
+ Assert.assertEquals(1, lazyLoadCount.getDelta()); |
} |
/** |
* Verify that Tab.BackgroundLoadStatus is correctly recorded. |
*/ |
+ @Test |
@MediumTest |
@Feature({"Uma"}) |
public void testTabBackgroundLoadStatus() throws ExecutionException { |
@@ -107,34 +118,34 @@ public class TabUmaTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
new HistogramDelta(histogram, TabUma.TAB_BACKGROUND_LOAD_LOST); |
HistogramDelta skippedLoadCount = |
new HistogramDelta(histogram, TabUma.TAB_BACKGROUND_LOAD_SKIPPED); |
- assertEquals(0, shownLoadCount.getDelta()); |
- assertEquals(0, lostLoadCount.getDelta()); |
- assertEquals(0, skippedLoadCount.getDelta()); |
+ Assert.assertEquals(0, shownLoadCount.getDelta()); |
+ Assert.assertEquals(0, lostLoadCount.getDelta()); |
+ Assert.assertEquals(0, skippedLoadCount.getDelta()); |
// Test a live tab created in background and shown. |
final Tab liveBgTab = ThreadUtils.runOnUiThreadBlocking(new Callable<Tab>() { |
@Override |
public Tab call() { |
- Tab bgTab = Tab.createLiveTab(Tab.INVALID_TAB_ID, getActivity(), false, |
- getActivity().getWindowAndroid(), TabLaunchType.FROM_LONGPRESS_BACKGROUND, |
- Tab.INVALID_TAB_ID, true); |
+ Tab bgTab = Tab.createLiveTab(Tab.INVALID_TAB_ID, mActivityTestRule.getActivity(), |
+ false, mActivityTestRule.getActivity().getWindowAndroid(), |
+ TabLaunchType.FROM_LONGPRESS_BACKGROUND, Tab.INVALID_TAB_ID, true); |
bgTab.initialize(null, null, new TabDelegateFactory(), true, false); |
bgTab.loadUrl(new LoadUrlParams(mTestUrl)); |
bgTab.show(TabSelectionType.FROM_USER); |
return bgTab; |
} |
}); |
- assertEquals(1, shownLoadCount.getDelta()); |
- assertEquals(0, lostLoadCount.getDelta()); |
- assertEquals(0, skippedLoadCount.getDelta()); |
+ Assert.assertEquals(1, shownLoadCount.getDelta()); |
+ Assert.assertEquals(0, lostLoadCount.getDelta()); |
+ Assert.assertEquals(0, skippedLoadCount.getDelta()); |
// Test a live tab killed in background before shown. |
final Tab killedBgTab = ThreadUtils.runOnUiThreadBlocking(new Callable<Tab>() { |
@Override |
public Tab call() { |
- Tab bgTab = Tab.createLiveTab(Tab.INVALID_TAB_ID, getActivity(), false, |
- getActivity().getWindowAndroid(), TabLaunchType.FROM_LONGPRESS_BACKGROUND, |
- Tab.INVALID_TAB_ID, true); |
+ Tab bgTab = Tab.createLiveTab(Tab.INVALID_TAB_ID, mActivityTestRule.getActivity(), |
+ false, mActivityTestRule.getActivity().getWindowAndroid(), |
+ TabLaunchType.FROM_LONGPRESS_BACKGROUND, Tab.INVALID_TAB_ID, true); |
bgTab.initialize(null, null, new TabDelegateFactory(), true, false); |
bgTab.loadUrl(new LoadUrlParams(mTestUrl)); |
// Simulate the renderer being killed by the OS. |
@@ -143,25 +154,26 @@ public class TabUmaTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
return bgTab; |
} |
}); |
- assertEquals(1, shownLoadCount.getDelta()); |
- assertEquals(1, lostLoadCount.getDelta()); |
- assertEquals(0, skippedLoadCount.getDelta()); |
+ Assert.assertEquals(1, shownLoadCount.getDelta()); |
+ Assert.assertEquals(1, lostLoadCount.getDelta()); |
+ Assert.assertEquals(0, skippedLoadCount.getDelta()); |
// Test a tab created in background but not loaded eagerly. |
final Tab frozenBgTab = ThreadUtils.runOnUiThreadBlocking(new Callable<Tab>() { |
@Override |
public Tab call() { |
- Tab bgTab = Tab.createTabForLazyLoad(getActivity(), false, |
- getActivity().getWindowAndroid(), TabLaunchType.FROM_LONGPRESS_BACKGROUND, |
- Tab.INVALID_TAB_ID, new LoadUrlParams(mTestUrl)); |
+ Tab bgTab = Tab.createTabForLazyLoad(mActivityTestRule.getActivity(), false, |
+ mActivityTestRule.getActivity().getWindowAndroid(), |
+ TabLaunchType.FROM_LONGPRESS_BACKGROUND, Tab.INVALID_TAB_ID, |
+ new LoadUrlParams(mTestUrl)); |
bgTab.initialize(null, null, new TabDelegateFactory(), true, false); |
bgTab.show(TabSelectionType.FROM_USER); |
return bgTab; |
} |
}); |
- assertEquals(1, shownLoadCount.getDelta()); |
- assertEquals(1, lostLoadCount.getDelta()); |
- assertEquals(1, skippedLoadCount.getDelta()); |
+ Assert.assertEquals(1, shownLoadCount.getDelta()); |
+ Assert.assertEquals(1, lostLoadCount.getDelta()); |
+ Assert.assertEquals(1, skippedLoadCount.getDelta()); |
// Show every tab again and make sure we didn't record more samples - this metric should be |
// recorded only on first display. |
@@ -173,8 +185,8 @@ public class TabUmaTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
frozenBgTab.show(TabSelectionType.FROM_USER); |
} |
}); |
- assertEquals(1, shownLoadCount.getDelta()); |
- assertEquals(1, lostLoadCount.getDelta()); |
- assertEquals(1, skippedLoadCount.getDelta()); |
+ Assert.assertEquals(1, shownLoadCount.getDelta()); |
+ Assert.assertEquals(1, lostLoadCount.getDelta()); |
+ Assert.assertEquals(1, skippedLoadCount.getDelta()); |
} |
} |