| Index: content/public/android/javatests/src/org/chromium/content/browser/PopupZoomerTest.java
|
| diff --git a/content/public/android/javatests/src/org/chromium/content/browser/PopupZoomerTest.java b/content/public/android/javatests/src/org/chromium/content/browser/PopupZoomerTest.java
|
| index 43f443b0d0f3a77a839cda125ef777cdf90021bb..885a56009b8bf48e6fe6db5bee5c84fe106469f9 100644
|
| --- a/content/public/android/javatests/src/org/chromium/content/browser/PopupZoomerTest.java
|
| +++ b/content/public/android/javatests/src/org/chromium/content/browser/PopupZoomerTest.java
|
| @@ -9,20 +9,32 @@ import android.graphics.Bitmap;
|
| import android.graphics.Canvas;
|
| import android.graphics.Rect;
|
| import android.os.SystemClock;
|
| +import android.support.test.InstrumentationRegistry;
|
| import android.support.test.filters.SmallTest;
|
| import android.view.MotionEvent;
|
| import android.view.View;
|
|
|
| +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.Feature;
|
| import org.chromium.content.browser.input.ImeAdapter;
|
| +import org.chromium.content.browser.test.ContentJUnit4ClassRunner;
|
| import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper;
|
| -import org.chromium.content_shell_apk.ContentShellTestBase;
|
| +import org.chromium.content_shell_apk.ContentShellActivityTestRule;
|
|
|
| /**
|
| * Tests for PopupZoomer.
|
| */
|
| -public class PopupZoomerTest extends ContentShellTestBase {
|
| +@RunWith(ContentJUnit4ClassRunner.class)
|
| +public class PopupZoomerTest {
|
| + @Rule
|
| + public ContentShellActivityTestRule mActivityTestRule = new ContentShellActivityTestRule();
|
| +
|
| private CustomCanvasPopupZoomer mPopupZoomer;
|
| private ContentViewCore mContentViewCore;
|
|
|
| @@ -75,45 +87,46 @@ public class PopupZoomerTest extends ContentShellTestBase {
|
| MotionEvent.obtain(downEvent, downEvent + 10, MotionEvent.ACTION_UP, x, y, 0));
|
| }
|
|
|
| - @Override
|
| - public void setUp() throws Exception {
|
| - super.setUp();
|
| -
|
| - final Context context = getActivity();
|
| -
|
| + @Before
|
| + public void setUp() throws Throwable {
|
| + mActivityTestRule.launchActivity(null);
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| + Context context = mActivityTestRule.getActivity();
|
| mContentViewCore = new ContentViewCore(context, "");
|
| mContentViewCore.setSelectionPopupControllerForTesting(new SelectionPopupController(
|
| context, null, null, null, mContentViewCore.getRenderCoordinates()));
|
| mContentViewCore.setImeAdapterForTest(
|
| - new ImeAdapter(getContentViewCore().getWebContents(),
|
| - getContentViewCore().getContainerView(),
|
| + new ImeAdapter(mActivityTestRule.getContentViewCore().getWebContents(),
|
| + mActivityTestRule.getContentViewCore().getContainerView(),
|
| new TestInputMethodManagerWrapper(mContentViewCore)));
|
| - mPopupZoomer = createPopupZoomerForTest(getInstrumentation().getTargetContext());
|
| + mPopupZoomer = createPopupZoomerForTest(InstrumentationRegistry.getTargetContext());
|
| mContentViewCore.setPopupZoomerForTest(mPopupZoomer);
|
| }
|
| });
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Navigation"})
|
| public void testDefaultCreateState() throws Exception {
|
| - assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
|
| - assertFalse(mPopupZoomer.isShowing());
|
| + Assert.assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
|
| + Assert.assertFalse(mPopupZoomer.isShowing());
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Navigation"})
|
| public void testShowWithoutBitmap() throws Exception {
|
| mPopupZoomer.show(new Rect(0, 0, 5, 5));
|
|
|
| // The view should be invisible.
|
| - assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
|
| - assertFalse(mPopupZoomer.isShowing());
|
| + Assert.assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
|
| + Assert.assertFalse(mPopupZoomer.isShowing());
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Navigation"})
|
| public void testShowWithBitmap() throws Exception {
|
| @@ -121,10 +134,11 @@ public class PopupZoomerTest extends ContentShellTestBase {
|
| mPopupZoomer.show(new Rect(0, 0, 5, 5));
|
|
|
| // The view should become visible.
|
| - assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
|
| - assertTrue(mPopupZoomer.isShowing());
|
| + Assert.assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
|
| + Assert.assertTrue(mPopupZoomer.isShowing());
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Navigation"})
|
| public void testHide() throws Exception {
|
| @@ -132,17 +146,18 @@ public class PopupZoomerTest extends ContentShellTestBase {
|
| mPopupZoomer.show(new Rect(0, 0, 5, 5));
|
|
|
| // The view should become visible.
|
| - assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
|
| - assertTrue(mPopupZoomer.isShowing());
|
| + Assert.assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
|
| + Assert.assertTrue(mPopupZoomer.isShowing());
|
|
|
| // Call hide without animation.
|
| mPopupZoomer.hide(false);
|
|
|
| // The view should be invisible.
|
| - assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
|
| - assertFalse(mPopupZoomer.isShowing());
|
| + Assert.assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
|
| + Assert.assertFalse(mPopupZoomer.isShowing());
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Navigation"})
|
| public void testOnTouchEventOutsidePopup() throws Exception {
|
| @@ -153,8 +168,8 @@ public class PopupZoomerTest extends ContentShellTestBase {
|
| mPopupZoomer.finishPendingDraws();
|
|
|
| // The view should be visible.
|
| - assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
|
| - assertTrue(mPopupZoomer.isShowing());
|
| + Assert.assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
|
| + Assert.assertTrue(mPopupZoomer.isShowing());
|
|
|
| // Send tap event at a point outside the popup.
|
| // i.e. coordinates greater than 10 + PopupZoomer.ZOOM_BOUNDS_MARGIN
|
| @@ -164,10 +179,11 @@ public class PopupZoomerTest extends ContentShellTestBase {
|
| mPopupZoomer.finishPendingDraws();
|
|
|
| // The view should be invisible.
|
| - assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
|
| - assertFalse(mPopupZoomer.isShowing());
|
| + Assert.assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
|
| + Assert.assertFalse(mPopupZoomer.isShowing());
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Navigation"})
|
| public void testOnTouchEventInsidePopupNoOnTapListener() throws Exception {
|
| @@ -178,8 +194,8 @@ public class PopupZoomerTest extends ContentShellTestBase {
|
| mPopupZoomer.finishPendingDraws();
|
|
|
| // The view should be visible.
|
| - assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
|
| - assertTrue(mPopupZoomer.isShowing());
|
| + Assert.assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
|
| + Assert.assertTrue(mPopupZoomer.isShowing());
|
|
|
| // Send tap event at a point inside the popup.
|
| // i.e. coordinates between PopupZoomer.ZOOM_BOUNDS_MARGIN and
|
| @@ -190,10 +206,11 @@ public class PopupZoomerTest extends ContentShellTestBase {
|
| mPopupZoomer.finishPendingDraws();
|
|
|
| // The view should still be visible as no OnTapListener is set.
|
| - assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
|
| - assertTrue(mPopupZoomer.isShowing());
|
| + Assert.assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
|
| + Assert.assertTrue(mPopupZoomer.isShowing());
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"Navigation"})
|
| public void testHidePopupOnLosingFocus() throws Exception {
|
| @@ -205,8 +222,8 @@ public class PopupZoomerTest extends ContentShellTestBase {
|
| mPopupZoomer.finishPendingDraws();
|
|
|
| // The view should be visible.
|
| - assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
|
| - assertTrue(mPopupZoomer.isShowing());
|
| + Assert.assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
|
| + Assert.assertTrue(mPopupZoomer.isShowing());
|
|
|
| // Simulate losing the focus.
|
| mContentViewCore.onFocusChanged(false, true);
|
| @@ -215,7 +232,7 @@ public class PopupZoomerTest extends ContentShellTestBase {
|
| mPopupZoomer.finishPendingDraws();
|
|
|
| // Now that another view has been focused, the view should be invisible.
|
| - assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
|
| - assertFalse(mPopupZoomer.isShowing());
|
| + Assert.assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
|
| + Assert.assertFalse(mPopupZoomer.isShowing());
|
| }
|
| }
|
|
|