Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1525)

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/PopupZoomerTest.java

Issue 2766393004: Convert most of the rest of instrumentation tests in content (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 ae53c847293e0d35ae3d7bb650375720b1a156a2..c8dc3ce83544f3d27f7fa2861703b1704d8af978 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.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.input.ImeAdapter;
import org.chromium.content.browser.input.TestImeAdapterDelegate;
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(BaseJUnit4ClassRunner.class)
+public class PopupZoomerTest {
+ @Rule
+ public ContentShellActivityTestRule mActivityTestRule = new ContentShellActivityTestRule();
+
private CustomCanvasPopupZoomer mPopupZoomer;
private ContentViewCore mContentViewCore;
@@ -75,37 +87,48 @@ public class PopupZoomerTest extends ContentShellTestBase {
MotionEvent.obtain(downEvent, downEvent + 10, MotionEvent.ACTION_UP, x, y, 0));
}
- @Override
- public void setUp() throws Exception {
- super.setUp();
- mPopupZoomer = createPopupZoomerForTest(getInstrumentation().getTargetContext());
- mContentViewCore = new ContentViewCore(getActivity(), "");
- ImeAdapter imeAdapter = new ImeAdapter(new TestInputMethodManagerWrapper(mContentViewCore),
- new TestImeAdapterDelegate(getContentViewCore().getContainerView()));
- mContentViewCore.setSelectionPopupControllerForTesting(
- new SelectionPopupController(getActivity(), null, null, null,
- mContentViewCore.getRenderCoordinates(), imeAdapter));
- mContentViewCore.setPopupZoomerForTest(mPopupZoomer);
- mContentViewCore.setImeAdapterForTest(imeAdapter);
+ @Before
+ public void setUp() throws Throwable {
+ mActivityTestRule.launchActivity(null);
+ mActivityTestRule.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mPopupZoomer = createPopupZoomerForTest(
+ InstrumentationRegistry.getInstrumentation().getTargetContext());
+ mContentViewCore = new ContentViewCore(mActivityTestRule.getActivity(), "");
+ ImeAdapter imeAdapter =
+ new ImeAdapter(new TestInputMethodManagerWrapper(mContentViewCore),
+ new TestImeAdapterDelegate(
+ mActivityTestRule.getContentViewCore().getContainerView()));
+ mContentViewCore.setSelectionPopupControllerForTesting(
+ new SelectionPopupController(mActivityTestRule.getActivity(), null, null,
+ null, mContentViewCore.getRenderCoordinates(), imeAdapter));
+ mContentViewCore.setPopupZoomerForTest(mPopupZoomer);
+ mContentViewCore.setImeAdapterForTest(imeAdapter);
+ }
+ });
}
+ @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 {
@@ -113,10 +136,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 {
@@ -124,17 +148,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 {
@@ -145,8 +170,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
@@ -156,10 +181,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 {
@@ -170,8 +196,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
@@ -182,10 +208,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 {
@@ -197,8 +224,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);
@@ -207,7 +234,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());
}
}

Powered by Google App Engine
This is Rietveld 408576698