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

Side by Side 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: Nit fixed. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/PopupZoomer.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.content.browser;
6
7 import android.content.Context;
8 import android.graphics.Bitmap;
9 import android.graphics.Canvas;
10 import android.graphics.Rect;
11 import android.graphics.drawable.ColorDrawable;
12 import android.graphics.drawable.Drawable;
13 import android.os.SystemClock;
14 import android.test.InstrumentationTestCase;
15 import android.test.suitebuilder.annotation.SmallTest;
16 import android.view.MotionEvent;
17 import android.view.View;
18
19 import org.chromium.base.test.Feature;
20
21 /**
22 * Tests for PopupZoomer.
23 */
24 public class PopupZoomerTest extends InstrumentationTestCase {
25 private CustomCanvasPopupZoomer mPopupZoomer;
26
27 private class CustomCanvasPopupZoomer extends PopupZoomer {
28 Canvas mCanvas;
29 long mPendingDraws = 0;
30
31 CustomCanvasPopupZoomer(Context context, Canvas c) {
32 super(context, 0);
33 mCanvas = c;
34 }
35
36 @Override
37 public void invalidate() {
38 mPendingDraws++;
39 }
40
41 @Override
42 public void onDraw(Canvas c) {
43 mPendingDraws--;
44 super.onDraw(c);
45 }
46
47 public void finishPendingDraws() {
48 // Finish all pending draw calls. A draw call may change mPendingDra ws.
49 while (mPendingDraws > 0) {
50 onDraw(mCanvas);
51 }
52 }
53
54 @Override
55 protected Drawable loadOverlayDrawable() {
56 return new ColorDrawable();
57 }
58
59 }
60
61 private CustomCanvasPopupZoomer createPopupZoomerForTest(Context context) {
62 return new CustomCanvasPopupZoomer(
63 context, new Canvas(Bitmap.createBitmap(100, 100, Bitmap.Config. ALPHA_8)));
64 }
65
66 private void sendSingleTapTouchEventOnView(View view, float x, float y) {
67 final long downEvent = SystemClock.uptimeMillis();
68 view.onTouchEvent(
69 MotionEvent.obtain(downEvent, downEvent, MotionEvent.ACTION_DOWN , x, y, 0));
70 view.onTouchEvent(
71 MotionEvent.obtain(downEvent, downEvent + 10, MotionEvent.ACTION _UP, x, y, 0));
72 }
73
74 @Override
75 public void setUp() {
76 mPopupZoomer = createPopupZoomerForTest(getInstrumentation().getTargetCo ntext());
77 }
78
79 @SmallTest
80 @Feature({"Navigation"})
81 public void testDefaultCreateState() throws Exception {
82 assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
83 assertFalse(mPopupZoomer.isShowing());
84 }
85
86 @SmallTest
87 @Feature({"Navigation"})
88 public void testShowWithoutBitmap() throws Exception {
89 mPopupZoomer.show(new Rect(0, 0, 5, 5));
90
91 // The view should be invisible.
92 assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
93 assertFalse(mPopupZoomer.isShowing());
94 }
95
96 @SmallTest
97 @Feature({"Navigation"})
98 public void testShowWithBitmap() throws Exception {
99 mPopupZoomer.setBitmap(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8 ));
100 mPopupZoomer.show(new Rect(0, 0, 5, 5));
101
102 // The view should become visible.
103 assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
104 assertTrue(mPopupZoomer.isShowing());
105 }
106
107 @SmallTest
108 @Feature({"Navigation"})
109 public void testHide() throws Exception {
110 mPopupZoomer.setBitmap(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8 ));
111 mPopupZoomer.show(new Rect(0, 0, 5, 5));
112
113 // The view should become visible.
114 assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
115 assertTrue(mPopupZoomer.isShowing());
116
117 // Call hide without animation.
118 mPopupZoomer.hide(false);
119
120 // The view should be invisible.
121 assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
122 assertFalse(mPopupZoomer.isShowing());
123 }
124
125 @SmallTest
126 @Feature({"Navigation"})
127 public void testOnTouchEventOutsidePopup() throws Exception {
128 mPopupZoomer.setBitmap(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8 ));
129 mPopupZoomer.show(new Rect(0, 0, 5, 5));
130
131 // Wait for the show animation to finish.
132 mPopupZoomer.finishPendingDraws();
133
134 // The view should be visible.
135 assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
136 assertTrue(mPopupZoomer.isShowing());
137
138 // Send tap event at a point outside the popup.
139 // i.e. coordinates greater than 10 + PopupZoomer.ZOOM_BOUNDS_MARGIN
140 sendSingleTapTouchEventOnView(mPopupZoomer, 50, 50);
141
142 // Wait for the hide animation to finish.
143 mPopupZoomer.finishPendingDraws();
144
145 // The view should be invisible.
146 assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
147 assertFalse(mPopupZoomer.isShowing());
148 }
149
150 @SmallTest
151 @Feature({"Navigation"})
152 public void testOnTouchEventInsidePopupNoOnTapListener() throws Exception {
153 mPopupZoomer.setBitmap(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8 ));
154 mPopupZoomer.show(new Rect(0, 0, 5, 5));
155
156 // Wait for the animation to finish.
157 mPopupZoomer.finishPendingDraws();
158
159 // The view should be visible.
160 assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
161 assertTrue(mPopupZoomer.isShowing());
162
163 // Send tap event at a point inside the popup.
164 // i.e. coordinates between PopupZoomer.ZOOM_BOUNDS_MARGIN and
165 // PopupZoomer.ZOOM_BOUNDS_MARGIN + 10
166 sendSingleTapTouchEventOnView(mPopupZoomer, 30, 30);
167
168 // Wait for the animation to finish (if there is any).
169 mPopupZoomer.finishPendingDraws();
170
171 // The view should still be visible as no OnTapListener is set.
172 assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
173 assertTrue(mPopupZoomer.isShowing());
174 }
175 }
OLDNEW
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/PopupZoomer.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698