| 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 f6eb88d2d4dd311ad9685104d18012b0ec706365..ee4cbde819d7d1eae76ff31ae63a04e5722f1189 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,27 +4,16 @@
|
|
|
| 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.ChromeActivityTestRule;
|
| -import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
| +import org.chromium.chrome.test.ChromeActivityTestCaseBase;
|
| import org.chromium.content_public.browser.LoadUrlParams;
|
| import org.chromium.net.test.EmbeddedTestServer;
|
|
|
| @@ -34,47 +23,48 @@
|
| /**
|
| * Tests for Tab-related histogram collection.
|
| */
|
| -@RunWith(ChromeJUnit4ClassRunner.class)
|
| @RetryOnFailure
|
| -@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
|
| - ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
|
| -public class TabUmaTest {
|
| - @Rule
|
| - public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
|
| - new ChromeActivityTestRule<>(ChromeActivity.class);
|
| +public class TabUmaTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
|
|
| private static final String TEST_PATH = "/chrome/test/data/android/about.html";
|
|
|
| private EmbeddedTestServer mTestServer;
|
| private String mTestUrl;
|
|
|
| - @Before
|
| - public void setUp() throws Exception {
|
| - mActivityTestRule.startMainActivityOnBlankPage();
|
| - mTestServer = EmbeddedTestServer.createAndStartServer(
|
| - InstrumentationRegistry.getInstrumentation().getContext());
|
| + 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());
|
| mTestUrl = mTestServer.getURL(TEST_PATH);
|
| }
|
|
|
| - @After
|
| - public void tearDown() throws Exception {
|
| + @Override
|
| + protected 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(mActivityTestRule.getActivity(), false,
|
| - mActivityTestRule.getActivity().getWindowAndroid(),
|
| - TabLaunchType.FROM_LONGPRESS_BACKGROUND, Tab.INVALID_TAB_ID,
|
| - new LoadUrlParams(mTestUrl));
|
| + Tab bgTab = Tab.createTabForLazyLoad(getActivity(), false,
|
| + getActivity().getWindowAndroid(), TabLaunchType.FROM_LONGPRESS_BACKGROUND,
|
| + Tab.INVALID_TAB_ID, new LoadUrlParams(mTestUrl));
|
| bgTab.initialize(null, null, new TabDelegateFactory(), true, false);
|
| return bgTab;
|
| }
|
| @@ -83,7 +73,7 @@
|
| String histogram = "Tab.StatusWhenSwitchedBackToForeground";
|
| HistogramDelta lazyLoadCount =
|
| new HistogramDelta(histogram, TabUma.TAB_STATUS_LAZY_LOAD_FOR_BG_TAB);
|
| - Assert.assertEquals(0, lazyLoadCount.getDelta()); // Sanity check.
|
| + 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() {
|
| @@ -92,7 +82,7 @@
|
| tab.show(TabSelectionType.FROM_USER);
|
| }
|
| });
|
| - Assert.assertEquals(1, lazyLoadCount.getDelta());
|
| + assertEquals(1, lazyLoadCount.getDelta());
|
|
|
| // Show the tab again and verify that we didn't record another sample.
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @@ -101,13 +91,12 @@
|
| tab.show(TabSelectionType.FROM_USER);
|
| }
|
| });
|
| - Assert.assertEquals(1, lazyLoadCount.getDelta());
|
| + assertEquals(1, lazyLoadCount.getDelta());
|
| }
|
|
|
| /**
|
| * Verify that Tab.BackgroundLoadStatus is correctly recorded.
|
| */
|
| - @Test
|
| @MediumTest
|
| @Feature({"Uma"})
|
| public void testTabBackgroundLoadStatus() throws ExecutionException {
|
| @@ -118,34 +107,34 @@
|
| new HistogramDelta(histogram, TabUma.TAB_BACKGROUND_LOAD_LOST);
|
| HistogramDelta skippedLoadCount =
|
| new HistogramDelta(histogram, TabUma.TAB_BACKGROUND_LOAD_SKIPPED);
|
| - Assert.assertEquals(0, shownLoadCount.getDelta());
|
| - Assert.assertEquals(0, lostLoadCount.getDelta());
|
| - Assert.assertEquals(0, skippedLoadCount.getDelta());
|
| + assertEquals(0, shownLoadCount.getDelta());
|
| + assertEquals(0, lostLoadCount.getDelta());
|
| + 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, mActivityTestRule.getActivity(),
|
| - false, mActivityTestRule.getActivity().getWindowAndroid(),
|
| - TabLaunchType.FROM_LONGPRESS_BACKGROUND, Tab.INVALID_TAB_ID, true);
|
| + Tab bgTab = Tab.createLiveTab(Tab.INVALID_TAB_ID, getActivity(), false,
|
| + 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;
|
| }
|
| });
|
| - Assert.assertEquals(1, shownLoadCount.getDelta());
|
| - Assert.assertEquals(0, lostLoadCount.getDelta());
|
| - Assert.assertEquals(0, skippedLoadCount.getDelta());
|
| + assertEquals(1, shownLoadCount.getDelta());
|
| + assertEquals(0, lostLoadCount.getDelta());
|
| + 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, mActivityTestRule.getActivity(),
|
| - false, mActivityTestRule.getActivity().getWindowAndroid(),
|
| - TabLaunchType.FROM_LONGPRESS_BACKGROUND, Tab.INVALID_TAB_ID, true);
|
| + Tab bgTab = Tab.createLiveTab(Tab.INVALID_TAB_ID, getActivity(), false,
|
| + 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.
|
| @@ -154,26 +143,25 @@
|
| return bgTab;
|
| }
|
| });
|
| - Assert.assertEquals(1, shownLoadCount.getDelta());
|
| - Assert.assertEquals(1, lostLoadCount.getDelta());
|
| - Assert.assertEquals(0, skippedLoadCount.getDelta());
|
| + assertEquals(1, shownLoadCount.getDelta());
|
| + assertEquals(1, lostLoadCount.getDelta());
|
| + 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(mActivityTestRule.getActivity(), false,
|
| - mActivityTestRule.getActivity().getWindowAndroid(),
|
| - TabLaunchType.FROM_LONGPRESS_BACKGROUND, Tab.INVALID_TAB_ID,
|
| - new LoadUrlParams(mTestUrl));
|
| + Tab bgTab = Tab.createTabForLazyLoad(getActivity(), false,
|
| + 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;
|
| }
|
| });
|
| - Assert.assertEquals(1, shownLoadCount.getDelta());
|
| - Assert.assertEquals(1, lostLoadCount.getDelta());
|
| - Assert.assertEquals(1, skippedLoadCount.getDelta());
|
| + assertEquals(1, shownLoadCount.getDelta());
|
| + assertEquals(1, lostLoadCount.getDelta());
|
| + 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.
|
| @@ -185,8 +173,8 @@
|
| frozenBgTab.show(TabSelectionType.FROM_USER);
|
| }
|
| });
|
| - Assert.assertEquals(1, shownLoadCount.getDelta());
|
| - Assert.assertEquals(1, lostLoadCount.getDelta());
|
| - Assert.assertEquals(1, skippedLoadCount.getDelta());
|
| + assertEquals(1, shownLoadCount.getDelta());
|
| + assertEquals(1, lostLoadCount.getDelta());
|
| + assertEquals(1, skippedLoadCount.getDelta());
|
| }
|
| }
|
|
|