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

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

Issue 10828427: Add a view to show magnified link preview on Andrdoid. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added code to init PopupZoomer Created 8 years, 4 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
new file mode 100644
index 0000000000000000000000000000000000000000..2fb2957fa035a18fc6ddbf003b40498a7329ade3
--- /dev/null
+++ b/content/public/android/javatests/src/org/chromium/content/browser/PopupZoomerTest.java
@@ -0,0 +1,176 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.content.browser;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Rect;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
+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.Feature;
+
+/**
+ * Tests for PopupZoomer.
+ */
+public class PopupZoomerTest extends InstrumentationTestCase {
+ private PopupZoomer mPopupZoomer;
+
+ private 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);
+ }
+
+ public void finishPendingDraws() {
+ // Finish all pending draw calls. A draw call may change mPendingDraws.
+ while (mPendingDraws > 0) {
+ onDraw(mCanvas);
+ }
+ }
+
+ @Override
+ protected Drawable loadOverlayDrawable() {
+ return new ColorDrawable();
+ }
+
+ }
+
+ private PopupZoomer createPopupZoomerForTest(Context context) {
+ PopupZoomer popup = new CustomCanvasPopupZoomer(
Ted C 2012/08/23 00:19:08 you can just return here without keeping a referen
nilesh 2012/08/23 17:04:30 Done.
+ context, new Canvas(Bitmap.createBitmap(100, 100, Bitmap.Config.ALPHA_8)));
+ return popup;
+ }
+
+ 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));
+
+ // The view should be invisible.
+ 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));
+
+ // The view should become visible.
+ 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));
+
+ // The view should become visible.
+ assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
+ assertTrue(mPopupZoomer.isShowing());
+
+ // Call hide without animation.
+ mPopupZoomer.hide(false);
+
+ // The view should be invisible.
+ 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));
+
+ // Wait for the show animation to finish.
+ ((CustomCanvasPopupZoomer)mPopupZoomer).finishPendingDraws();
Ted C 2012/08/23 00:19:08 space after cast (a couple places below as well)
nilesh 2012/08/23 17:04:30 Done.
+
+ // The view should be visible.
+ assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
+ assertTrue(mPopupZoomer.isShowing());
+
+ // Send tap event at a point outside the popup.
+ // i.e. coordinates greater than 10 + PopupZoomer.ZOOM_BOUNDS_MARGIN
+ sendSingleTapTouchEventOnView(mPopupZoomer, 50, 50);
+
+ // Wait for the hide animation to finish.
+ ((CustomCanvasPopupZoomer)mPopupZoomer).finishPendingDraws();
+
+ // The view should be invisible.
+ 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));
+
+ // Wait for the animation to finish.
+ ((CustomCanvasPopupZoomer)mPopupZoomer).finishPendingDraws();
+
+ // The view should be visible.
+ assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
+ assertTrue(mPopupZoomer.isShowing());
+
+ // Send tap event at a point inside the popup.
+ // i.e. coordinates between PopupZoomer.ZOOM_BOUNDS_MARGIN and
+ // PopupZoomer.ZOOM_BOUNDS_MARGIN + 10
+ sendSingleTapTouchEventOnView(mPopupZoomer, 30, 30);
+
+ // Wait for the animation to finish (if there is any).
+ ((CustomCanvasPopupZoomer)mPopupZoomer).finishPendingDraws();
+
+ // The view should still be visible as no OnTapListener is set.
+ assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
+ assertTrue(mPopupZoomer.isShowing());
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698