This source file includes following definitions.
- invalidate
- onDraw
- acceptZeroSizeView
- finishPendingDraws
- createPopupZoomerForTest
- sendSingleTapTouchEventOnView
- setUp
- Feature
- testDefaultCreateState
- Feature
- testShowWithoutBitmap
- Feature
- testShowWithBitmap
- Feature
- testHide
- Feature
- testOnTouchEventOutsidePopup
- Feature
- testOnTouchEventInsidePopupNoOnTapListener
package org.chromium.content.browser;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.SystemClock;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.view.MotionEvent;
import android.view.View;
import org.chromium.base.test.util.Feature;
public class PopupZoomerTest extends InstrumentationTestCase {
private CustomCanvasPopupZoomer mPopupZoomer;
private static class CustomCanvasPopupZoomer extends PopupZoomer {
Canvas mCanvas;
long mPendingDraws = 0;
CustomCanvasPopupZoomer(Context context, Canvas c) {
super(context);
mCanvas = c;
}
@Override
public void invalidate() {
mPendingDraws++;
}
@Override
public void onDraw(Canvas c) {
mPendingDraws--;
super.onDraw(c);
}
@Override
protected boolean acceptZeroSizeView() {
return true;
}
public void finishPendingDraws() {
while (mPendingDraws > 0) {
onDraw(mCanvas);
}
}
}
private CustomCanvasPopupZoomer createPopupZoomerForTest(Context context) {
return new CustomCanvasPopupZoomer(
context, new Canvas(Bitmap.createBitmap(100, 100, Bitmap.Config.ALPHA_8)));
}
private void sendSingleTapTouchEventOnView(View view, float x, float y) {
final long downEvent = SystemClock.uptimeMillis();
view.onTouchEvent(
MotionEvent.obtain(downEvent, downEvent, MotionEvent.ACTION_DOWN, x, y, 0));
view.onTouchEvent(
MotionEvent.obtain(downEvent, downEvent + 10, MotionEvent.ACTION_UP, x, y, 0));
}
@Override
public void setUp() {
mPopupZoomer = createPopupZoomerForTest(getInstrumentation().getTargetContext());
}
@SmallTest
@Feature({"Navigation"})
public void testDefaultCreateState() throws Exception {
assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
assertFalse(mPopupZoomer.isShowing());
}
@SmallTest
@Feature({"Navigation"})
public void testShowWithoutBitmap() throws Exception {
mPopupZoomer.show(new Rect(0, 0, 5, 5));
assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
assertFalse(mPopupZoomer.isShowing());
}
@SmallTest
@Feature({"Navigation"})
public void testShowWithBitmap() throws Exception {
mPopupZoomer.setBitmap(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8));
mPopupZoomer.show(new Rect(0, 0, 5, 5));
assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
assertTrue(mPopupZoomer.isShowing());
}
@SmallTest
@Feature({"Navigation"})
public void testHide() throws Exception {
mPopupZoomer.setBitmap(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8));
mPopupZoomer.show(new Rect(0, 0, 5, 5));
assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
assertTrue(mPopupZoomer.isShowing());
mPopupZoomer.hide(false);
assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
assertFalse(mPopupZoomer.isShowing());
}
@SmallTest
@Feature({"Navigation"})
public void testOnTouchEventOutsidePopup() throws Exception {
mPopupZoomer.setBitmap(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8));
mPopupZoomer.show(new Rect(0, 0, 5, 5));
mPopupZoomer.finishPendingDraws();
assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
assertTrue(mPopupZoomer.isShowing());
sendSingleTapTouchEventOnView(mPopupZoomer, 50, 50);
mPopupZoomer.finishPendingDraws();
assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
assertFalse(mPopupZoomer.isShowing());
}
@SmallTest
@Feature({"Navigation"})
public void testOnTouchEventInsidePopupNoOnTapListener() throws Exception {
mPopupZoomer.setBitmap(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8));
mPopupZoomer.show(new Rect(0, 0, 5, 5));
mPopupZoomer.finishPendingDraws();
assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
assertTrue(mPopupZoomer.isShowing());
sendSingleTapTouchEventOnView(mPopupZoomer, 30, 30);
mPopupZoomer.finishPendingDraws();
assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
assertTrue(mPopupZoomer.isShowing());
}
}