| Index: chrome/android/javatests/src/org/chromium/chrome/browser/tabmodel/TabWindowManagerTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/tabmodel/TabWindowManagerTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/tabmodel/TabWindowManagerTest.java
|
| index 44aded45d72a5102c6b37d89245ebfb40dcbec04..65e78d3a9fa568926dc033ebb33d05611525e57f 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/tabmodel/TabWindowManagerTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/tabmodel/TabWindowManagerTest.java
|
| @@ -5,9 +5,14 @@
|
| package org.chromium.chrome.browser.tabmodel;
|
|
|
| import android.app.Activity;
|
| +import android.support.test.annotation.UiThreadTest;
|
| import android.support.test.filters.SmallTest;
|
| -import android.test.InstrumentationTestCase;
|
| -import android.test.UiThreadTest;
|
| +import android.support.test.rule.UiThreadTestRule;
|
| +
|
| +import org.junit.Assert;
|
| +import org.junit.Rule;
|
| +import org.junit.Test;
|
| +import org.junit.runner.RunWith;
|
|
|
| import org.chromium.base.ActivityState;
|
| import org.chromium.base.ApplicationStatus;
|
| @@ -16,13 +21,15 @@ import org.chromium.chrome.browser.ChromeActivity;
|
| import org.chromium.chrome.browser.customtabs.CustomTabActivity;
|
| import org.chromium.chrome.browser.tab.Tab;
|
| import org.chromium.chrome.browser.tabmodel.TabWindowManager.TabModelSelectorFactory;
|
| +import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
| import org.chromium.chrome.test.util.browser.tabmodel.MockTabModelSelector;
|
|
|
| /**
|
| * Test for {@link TabWindowManager} APIs. Makes sure the class handles multiple {@link Activity}s
|
| * requesting {@link TabModelSelector}s, {@link Activity}s getting destroyed, etc..
|
| */
|
| -public class TabWindowManagerTest extends InstrumentationTestCase {
|
| +@RunWith(ChromeJUnit4ClassRunner.class)
|
| +public class TabWindowManagerTest {
|
| private final TabModelSelectorFactory mMockTabModelSelectorFactory =
|
| new TabModelSelectorFactory() {
|
| @Override
|
| @@ -44,9 +51,13 @@ public class TabWindowManagerTest extends InstrumentationTestCase {
|
| return (MockTabModelSelector) manager.requestSelector(activity, activity, requestedIndex);
|
| }
|
|
|
| + @Rule
|
| + public UiThreadTestRule mRule = new UiThreadTestRule();
|
| +
|
| /**
|
| * Test that a single {@link Activity} can request a {@link TabModelSelector}.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Feature({"Multiwindow"})
|
| @UiThreadTest
|
| @@ -56,18 +67,19 @@ public class TabWindowManagerTest extends InstrumentationTestCase {
|
| ChromeActivity activity0 = buildActivity();
|
| TabModelSelector selector0 = requestSelector(activity0, 0);
|
|
|
| - assertNotNull("Was not able to build the TabModelSelector", selector0);
|
| - assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity0));
|
| + Assert.assertNotNull("Was not able to build the TabModelSelector", selector0);
|
| + Assert.assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity0));
|
| }
|
|
|
| /**
|
| * Test that two {@link Activity}s can request different {@link TabModelSelector}s.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Feature({"Multiwindow"})
|
| @UiThreadTest
|
| public void testMultipleActivities() {
|
| - assertTrue("Not enough selectors", TabWindowManager.MAX_SIMULTANEOUS_SELECTORS >= 2);
|
| + Assert.assertTrue("Not enough selectors", TabWindowManager.MAX_SIMULTANEOUS_SELECTORS >= 2);
|
| final TabWindowManager manager = TabWindowManager.getInstance();
|
|
|
| ChromeActivity activity0 = buildActivity();
|
| @@ -75,25 +87,26 @@ public class TabWindowManagerTest extends InstrumentationTestCase {
|
| TabModelSelector selector0 = requestSelector(activity0, 0);
|
| TabModelSelector selector1 = requestSelector(activity1, 1);
|
|
|
| - assertNotNull("Was not able to build the TabModelSelector", selector0);
|
| - assertNotNull("Was not able to build the TabModelSelector", selector1);
|
| - assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity0));
|
| - assertEquals("Unexpected model index", 1, manager.getIndexForWindow(activity1));
|
| + Assert.assertNotNull("Was not able to build the TabModelSelector", selector0);
|
| + Assert.assertNotNull("Was not able to build the TabModelSelector", selector1);
|
| + Assert.assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity0));
|
| + Assert.assertEquals("Unexpected model index", 1, manager.getIndexForWindow(activity1));
|
| }
|
|
|
| /**
|
| * Test that trying to have too many {@link Activity}s requesting {@link TabModelSelector}s is
|
| * properly capped and returns {@code null}.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Feature({"Multiwindow"})
|
| @UiThreadTest
|
| public void testTooManyActivities() {
|
| for (int i = 0; i < TabWindowManager.MAX_SIMULTANEOUS_SELECTORS; i++) {
|
| - assertNotNull("Could not build selector", requestSelector(buildActivity(), 0));
|
| + Assert.assertNotNull("Could not build selector", requestSelector(buildActivity(), 0));
|
| }
|
|
|
| - assertNull("Built selectors past the max number supported",
|
| + Assert.assertNull("Built selectors past the max number supported",
|
| requestSelector(buildActivity(), 0));
|
| }
|
|
|
| @@ -101,11 +114,12 @@ public class TabWindowManagerTest extends InstrumentationTestCase {
|
| * Test that requesting the same {@link TabModelSelector} index will fall back and return a
|
| * model for a different available index instead. In this case, a higher index (0 -> 1).
|
| */
|
| + @Test
|
| @SmallTest
|
| @Feature({"Multiwindow"})
|
| @UiThreadTest
|
| public void testIndexFallback() {
|
| - assertTrue("Not enough selectors", TabWindowManager.MAX_SIMULTANEOUS_SELECTORS >= 2);
|
| + Assert.assertTrue("Not enough selectors", TabWindowManager.MAX_SIMULTANEOUS_SELECTORS >= 2);
|
|
|
| final TabWindowManager manager = TabWindowManager.getInstance();
|
|
|
| @@ -115,21 +129,22 @@ public class TabWindowManagerTest extends InstrumentationTestCase {
|
| // Request 0 again, but should get 1 instead.
|
| TabModelSelector selector1 = requestSelector(activity1, 0);
|
|
|
| - assertNotNull("Was not able to build the TabModelSelector", selector0);
|
| - assertNotNull("Was not able to build the TabModelSelector", selector1);
|
| - assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity0));
|
| - assertEquals("Unexpected model index", 1, manager.getIndexForWindow(activity1));
|
| + Assert.assertNotNull("Was not able to build the TabModelSelector", selector0);
|
| + Assert.assertNotNull("Was not able to build the TabModelSelector", selector1);
|
| + Assert.assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity0));
|
| + Assert.assertEquals("Unexpected model index", 1, manager.getIndexForWindow(activity1));
|
| }
|
|
|
| /**
|
| * Test that requesting the same {@link TabModelSelector} index will fall back and return a
|
| * model for a different available index instead. In this case, a lower index (2 -> 0).
|
| */
|
| + @Test
|
| @SmallTest
|
| @Feature({"Multiwindow"})
|
| @UiThreadTest
|
| public void testIndexFallback2() {
|
| - assertTrue("Not enough selectors", TabWindowManager.MAX_SIMULTANEOUS_SELECTORS >= 3);
|
| + Assert.assertTrue("Not enough selectors", TabWindowManager.MAX_SIMULTANEOUS_SELECTORS >= 3);
|
|
|
| final TabWindowManager manager = TabWindowManager.getInstance();
|
|
|
| @@ -139,15 +154,16 @@ public class TabWindowManagerTest extends InstrumentationTestCase {
|
| // Request 2 again, but should get 0 instead.
|
| TabModelSelector selector1 = requestSelector(activity1, 2);
|
|
|
| - assertNotNull("Was not able to build the TabModelSelector", selector0);
|
| - assertNotNull("Was not able to build the TabModelSelector", selector1);
|
| - assertEquals("Unexpected model index", 2, manager.getIndexForWindow(activity0));
|
| - assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity1));
|
| + Assert.assertNotNull("Was not able to build the TabModelSelector", selector0);
|
| + Assert.assertNotNull("Was not able to build the TabModelSelector", selector1);
|
| + Assert.assertEquals("Unexpected model index", 2, manager.getIndexForWindow(activity0));
|
| + Assert.assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity1));
|
| }
|
|
|
| /**
|
| * Test that a destroyed {@link Activity} properly gets removed from {@link TabWindowManager}.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Feature({"Multiwindow"})
|
| @UiThreadTest
|
| @@ -157,12 +173,12 @@ public class TabWindowManagerTest extends InstrumentationTestCase {
|
| ChromeActivity activity0 = buildActivity();
|
| TabModelSelector selector0 = requestSelector(activity0, 0);
|
|
|
| - assertNotNull("Was not able to build the TabModelSelector", selector0);
|
| - assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity0));
|
| + Assert.assertNotNull("Was not able to build the TabModelSelector", selector0);
|
| + Assert.assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity0));
|
|
|
| ApplicationStatus.onStateChangeForTesting(activity0, ActivityState.DESTROYED);
|
|
|
| - assertEquals("Still found model", TabWindowManager.INVALID_WINDOW_INDEX,
|
| + Assert.assertEquals("Still found model", TabWindowManager.INVALID_WINDOW_INDEX,
|
| manager.getIndexForWindow(activity0));
|
| }
|
|
|
| @@ -170,6 +186,7 @@ public class TabWindowManagerTest extends InstrumentationTestCase {
|
| * Test that an {@link Activity} requesting an index that was previously assigned to a destroyed
|
| * {@link Activity} can take that {@link TabModelSelector}.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Feature({"Multiwindow"})
|
| @UiThreadTest
|
| @@ -179,19 +196,19 @@ public class TabWindowManagerTest extends InstrumentationTestCase {
|
| ChromeActivity activity0 = buildActivity();
|
| TabModelSelector selector0 = requestSelector(activity0, 0);
|
|
|
| - assertNotNull("Was not able to build the TabModelSelector", selector0);
|
| - assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity0));
|
| + Assert.assertNotNull("Was not able to build the TabModelSelector", selector0);
|
| + Assert.assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity0));
|
|
|
| ApplicationStatus.onStateChangeForTesting(activity0, ActivityState.DESTROYED);
|
|
|
| - assertEquals("Still found model", TabWindowManager.INVALID_WINDOW_INDEX,
|
| + Assert.assertEquals("Still found model", TabWindowManager.INVALID_WINDOW_INDEX,
|
| manager.getIndexForWindow(activity0));
|
|
|
| ChromeActivity activity1 = buildActivity();
|
| TabModelSelector selector1 = requestSelector(activity1, 0);
|
|
|
| - assertNotNull("Was not able to build the TabModelSelector", selector1);
|
| - assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity1));
|
| + Assert.assertNotNull("Was not able to build the TabModelSelector", selector1);
|
| + Assert.assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity1));
|
| }
|
|
|
| /**
|
| @@ -199,11 +216,12 @@ public class TabWindowManagerTest extends InstrumentationTestCase {
|
| * {@link Activity} can take that {@link TabModelSelector} when there are other
|
| * {@link Activity}s assigned {@link TabModelSelector}s.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Feature({"Multiwindow"})
|
| @UiThreadTest
|
| public void testActivityDeathWithMultipleActivities() {
|
| - assertTrue("Not enough selectors", TabWindowManager.MAX_SIMULTANEOUS_SELECTORS >= 2);
|
| + Assert.assertTrue("Not enough selectors", TabWindowManager.MAX_SIMULTANEOUS_SELECTORS >= 2);
|
|
|
| final TabWindowManager manager = TabWindowManager.getInstance();
|
|
|
| @@ -212,27 +230,28 @@ public class TabWindowManagerTest extends InstrumentationTestCase {
|
| TabModelSelector selector0 = requestSelector(activity0, 0);
|
| TabModelSelector selector1 = requestSelector(activity1, 1);
|
|
|
| - assertNotNull("Was not able to build the TabModelSelector", selector0);
|
| - assertNotNull("Was not able to build the TabModelSelector", selector1);
|
| - assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity0));
|
| - assertEquals("Unexpected model index", 1, manager.getIndexForWindow(activity1));
|
| + Assert.assertNotNull("Was not able to build the TabModelSelector", selector0);
|
| + Assert.assertNotNull("Was not able to build the TabModelSelector", selector1);
|
| + Assert.assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity0));
|
| + Assert.assertEquals("Unexpected model index", 1, manager.getIndexForWindow(activity1));
|
|
|
| ApplicationStatus.onStateChangeForTesting(activity1, ActivityState.DESTROYED);
|
|
|
| - assertEquals("Still found model", TabWindowManager.INVALID_WINDOW_INDEX,
|
| + Assert.assertEquals("Still found model", TabWindowManager.INVALID_WINDOW_INDEX,
|
| manager.getIndexForWindow(activity1));
|
|
|
| ChromeActivity activity2 = buildActivity();
|
| TabModelSelector selector2 = requestSelector(activity2, 1);
|
|
|
| - assertNotNull("Was not able to build the TabModelSelector", selector2);
|
| - assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity0));
|
| - assertEquals("Unexpected model index", 1, manager.getIndexForWindow(activity2));
|
| + Assert.assertNotNull("Was not able to build the TabModelSelector", selector2);
|
| + Assert.assertEquals("Unexpected model index", 0, manager.getIndexForWindow(activity0));
|
| + Assert.assertEquals("Unexpected model index", 1, manager.getIndexForWindow(activity2));
|
| }
|
|
|
| /**
|
| * Tests that tabExistsInAnySelector() functions properly.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Feature({"Multiwindow"})
|
| @UiThreadTest
|
| @@ -246,19 +265,19 @@ public class TabWindowManagerTest extends InstrumentationTestCase {
|
| Tab tab1 = selector0.addMockTab();
|
| Tab tab2 = selector1.addMockIncognitoTab();
|
|
|
| - assertFalse(manager.tabExistsInAnySelector(tab1.getId() - 1));
|
| - assertTrue(manager.tabExistsInAnySelector(tab1.getId()));
|
| - assertTrue(manager.tabExistsInAnySelector(tab2.getId()));
|
| - assertFalse(manager.tabExistsInAnySelector(tab2.getId() + 1));
|
| + Assert.assertFalse(manager.tabExistsInAnySelector(tab1.getId() - 1));
|
| + Assert.assertTrue(manager.tabExistsInAnySelector(tab1.getId()));
|
| + Assert.assertTrue(manager.tabExistsInAnySelector(tab2.getId()));
|
| + Assert.assertFalse(manager.tabExistsInAnySelector(tab2.getId() + 1));
|
|
|
| AsyncTabParamsManager.getAsyncTabParams().clear();
|
| final int asyncTabId = 123;
|
| final TabReparentingParams dummyParams =
|
| new TabReparentingParams(new Tab(0, false, null), null, null);
|
| - assertFalse(manager.tabExistsInAnySelector(asyncTabId));
|
| + Assert.assertFalse(manager.tabExistsInAnySelector(asyncTabId));
|
| AsyncTabParamsManager.add(asyncTabId, dummyParams);
|
| try {
|
| - assertTrue(manager.tabExistsInAnySelector(asyncTabId));
|
| + Assert.assertTrue(manager.tabExistsInAnySelector(asyncTabId));
|
| } finally {
|
| AsyncTabParamsManager.getAsyncTabParams().clear();
|
| }
|
| @@ -267,6 +286,7 @@ public class TabWindowManagerTest extends InstrumentationTestCase {
|
| /**
|
| * Tests that getTabById() functions properly.
|
| */
|
| + @Test
|
| @SmallTest
|
| @Feature({"Multiwindow"})
|
| @UiThreadTest
|
| @@ -280,19 +300,19 @@ public class TabWindowManagerTest extends InstrumentationTestCase {
|
| Tab tab1 = selector0.addMockTab();
|
| Tab tab2 = selector1.addMockIncognitoTab();
|
|
|
| - assertNull(manager.getTabById(tab1.getId() - 1));
|
| - assertNotNull(manager.getTabById(tab1.getId()));
|
| - assertNotNull(manager.getTabById(tab2.getId()));
|
| - assertNull(manager.getTabById(tab2.getId() + 1));
|
| + Assert.assertNull(manager.getTabById(tab1.getId() - 1));
|
| + Assert.assertNotNull(manager.getTabById(tab1.getId()));
|
| + Assert.assertNotNull(manager.getTabById(tab2.getId()));
|
| + Assert.assertNull(manager.getTabById(tab2.getId() + 1));
|
|
|
| AsyncTabParamsManager.getAsyncTabParams().clear();
|
| final int asyncTabId = 123;
|
| final TabReparentingParams dummyParams =
|
| new TabReparentingParams(new Tab(0, false, null), null, null);
|
| - assertNull(manager.getTabById(asyncTabId));
|
| + Assert.assertNull(manager.getTabById(asyncTabId));
|
| AsyncTabParamsManager.add(asyncTabId, dummyParams);
|
| try {
|
| - assertNotNull(manager.getTabById(asyncTabId));
|
| + Assert.assertNotNull(manager.getTabById(asyncTabId));
|
| } finally {
|
| AsyncTabParamsManager.getAsyncTabParams().clear();
|
| }
|
|
|