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

Side by Side 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: rebase Created 3 years, 8 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.content.browser; 5 package org.chromium.content.browser;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.graphics.Bitmap; 8 import android.graphics.Bitmap;
9 import android.graphics.Canvas; 9 import android.graphics.Canvas;
10 import android.graphics.Rect; 10 import android.graphics.Rect;
11 import android.os.SystemClock; 11 import android.os.SystemClock;
12 import android.support.test.InstrumentationRegistry;
12 import android.support.test.filters.SmallTest; 13 import android.support.test.filters.SmallTest;
13 import android.view.MotionEvent; 14 import android.view.MotionEvent;
14 import android.view.View; 15 import android.view.View;
15 16
17 import org.junit.Assert;
18 import org.junit.Before;
19 import org.junit.Rule;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22
16 import org.chromium.base.ThreadUtils; 23 import org.chromium.base.ThreadUtils;
17 import org.chromium.base.test.util.Feature; 24 import org.chromium.base.test.util.Feature;
18 import org.chromium.content.browser.input.ImeAdapter; 25 import org.chromium.content.browser.input.ImeAdapter;
26 import org.chromium.content.browser.test.ContentJUnit4ClassRunner;
19 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper; 27 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper;
20 import org.chromium.content_shell_apk.ContentShellTestBase; 28 import org.chromium.content_shell_apk.ContentShellActivityTestRule;
21 29
22 /** 30 /**
23 * Tests for PopupZoomer. 31 * Tests for PopupZoomer.
24 */ 32 */
25 public class PopupZoomerTest extends ContentShellTestBase { 33 @RunWith(ContentJUnit4ClassRunner.class)
34 public class PopupZoomerTest {
35 @Rule
36 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi vityTestRule();
37
26 private CustomCanvasPopupZoomer mPopupZoomer; 38 private CustomCanvasPopupZoomer mPopupZoomer;
27 private ContentViewCore mContentViewCore; 39 private ContentViewCore mContentViewCore;
28 40
29 private static class CustomCanvasPopupZoomer extends PopupZoomer { 41 private static class CustomCanvasPopupZoomer extends PopupZoomer {
30 Canvas mCanvas; 42 Canvas mCanvas;
31 long mPendingDraws = 0; 43 long mPendingDraws = 0;
32 44
33 CustomCanvasPopupZoomer(Context context, Canvas c) { 45 CustomCanvasPopupZoomer(Context context, Canvas c) {
34 super(context); 46 super(context);
35 mCanvas = c; 47 mCanvas = c;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 80 }
69 81
70 private void sendSingleTapTouchEventOnView(View view, float x, float y) { 82 private void sendSingleTapTouchEventOnView(View view, float x, float y) {
71 final long downEvent = SystemClock.uptimeMillis(); 83 final long downEvent = SystemClock.uptimeMillis();
72 view.onTouchEvent( 84 view.onTouchEvent(
73 MotionEvent.obtain(downEvent, downEvent, MotionEvent.ACTION_DOWN , x, y, 0)); 85 MotionEvent.obtain(downEvent, downEvent, MotionEvent.ACTION_DOWN , x, y, 0));
74 view.onTouchEvent( 86 view.onTouchEvent(
75 MotionEvent.obtain(downEvent, downEvent + 10, MotionEvent.ACTION _UP, x, y, 0)); 87 MotionEvent.obtain(downEvent, downEvent + 10, MotionEvent.ACTION _UP, x, y, 0));
76 } 88 }
77 89
78 @Override 90 @Before
79 public void setUp() throws Exception { 91 public void setUp() throws Throwable {
80 super.setUp(); 92 mActivityTestRule.launchActivity(null);
81
82 final Context context = getActivity();
83
84 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 93 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
85 @Override 94 @Override
86 public void run() { 95 public void run() {
96 Context context = mActivityTestRule.getActivity();
87 mContentViewCore = new ContentViewCore(context, ""); 97 mContentViewCore = new ContentViewCore(context, "");
88 mContentViewCore.setSelectionPopupControllerForTesting(new Selec tionPopupController( 98 mContentViewCore.setSelectionPopupControllerForTesting(new Selec tionPopupController(
89 context, null, null, null, mContentViewCore.getRenderCoo rdinates())); 99 context, null, null, null, mContentViewCore.getRenderCoo rdinates()));
90 mContentViewCore.setImeAdapterForTest( 100 mContentViewCore.setImeAdapterForTest(
91 new ImeAdapter(getContentViewCore().getWebContents(), 101 new ImeAdapter(mActivityTestRule.getContentViewCore().ge tWebContents(),
92 getContentViewCore().getContainerView(), 102 mActivityTestRule.getContentViewCore().getContai nerView(),
93 new TestInputMethodManagerWrapper(mContentViewCo re))); 103 new TestInputMethodManagerWrapper(mContentViewCo re)));
94 mPopupZoomer = createPopupZoomerForTest(getInstrumentation().get TargetContext()); 104 mPopupZoomer = createPopupZoomerForTest(InstrumentationRegistry. getTargetContext());
95 mContentViewCore.setPopupZoomerForTest(mPopupZoomer); 105 mContentViewCore.setPopupZoomerForTest(mPopupZoomer);
96 } 106 }
97 }); 107 });
98 } 108 }
99 109
110 @Test
100 @SmallTest 111 @SmallTest
101 @Feature({"Navigation"}) 112 @Feature({"Navigation"})
102 public void testDefaultCreateState() throws Exception { 113 public void testDefaultCreateState() throws Exception {
103 assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility()); 114 Assert.assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
104 assertFalse(mPopupZoomer.isShowing()); 115 Assert.assertFalse(mPopupZoomer.isShowing());
105 } 116 }
106 117
118 @Test
107 @SmallTest 119 @SmallTest
108 @Feature({"Navigation"}) 120 @Feature({"Navigation"})
109 public void testShowWithoutBitmap() throws Exception { 121 public void testShowWithoutBitmap() throws Exception {
110 mPopupZoomer.show(new Rect(0, 0, 5, 5)); 122 mPopupZoomer.show(new Rect(0, 0, 5, 5));
111 123
112 // The view should be invisible. 124 // The view should be invisible.
113 assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility()); 125 Assert.assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
114 assertFalse(mPopupZoomer.isShowing()); 126 Assert.assertFalse(mPopupZoomer.isShowing());
115 } 127 }
116 128
129 @Test
117 @SmallTest 130 @SmallTest
118 @Feature({"Navigation"}) 131 @Feature({"Navigation"})
119 public void testShowWithBitmap() throws Exception { 132 public void testShowWithBitmap() throws Exception {
120 mPopupZoomer.setBitmap(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8 )); 133 mPopupZoomer.setBitmap(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8 ));
121 mPopupZoomer.show(new Rect(0, 0, 5, 5)); 134 mPopupZoomer.show(new Rect(0, 0, 5, 5));
122 135
123 // The view should become visible. 136 // The view should become visible.
124 assertEquals(View.VISIBLE, mPopupZoomer.getVisibility()); 137 Assert.assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
125 assertTrue(mPopupZoomer.isShowing()); 138 Assert.assertTrue(mPopupZoomer.isShowing());
126 } 139 }
127 140
141 @Test
128 @SmallTest 142 @SmallTest
129 @Feature({"Navigation"}) 143 @Feature({"Navigation"})
130 public void testHide() throws Exception { 144 public void testHide() throws Exception {
131 mPopupZoomer.setBitmap(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8 )); 145 mPopupZoomer.setBitmap(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8 ));
132 mPopupZoomer.show(new Rect(0, 0, 5, 5)); 146 mPopupZoomer.show(new Rect(0, 0, 5, 5));
133 147
134 // The view should become visible. 148 // The view should become visible.
135 assertEquals(View.VISIBLE, mPopupZoomer.getVisibility()); 149 Assert.assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
136 assertTrue(mPopupZoomer.isShowing()); 150 Assert.assertTrue(mPopupZoomer.isShowing());
137 151
138 // Call hide without animation. 152 // Call hide without animation.
139 mPopupZoomer.hide(false); 153 mPopupZoomer.hide(false);
140 154
141 // The view should be invisible. 155 // The view should be invisible.
142 assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility()); 156 Assert.assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
143 assertFalse(mPopupZoomer.isShowing()); 157 Assert.assertFalse(mPopupZoomer.isShowing());
144 } 158 }
145 159
160 @Test
146 @SmallTest 161 @SmallTest
147 @Feature({"Navigation"}) 162 @Feature({"Navigation"})
148 public void testOnTouchEventOutsidePopup() throws Exception { 163 public void testOnTouchEventOutsidePopup() throws Exception {
149 mPopupZoomer.setBitmap(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8 )); 164 mPopupZoomer.setBitmap(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8 ));
150 mPopupZoomer.show(new Rect(0, 0, 5, 5)); 165 mPopupZoomer.show(new Rect(0, 0, 5, 5));
151 166
152 // Wait for the show animation to finish. 167 // Wait for the show animation to finish.
153 mPopupZoomer.finishPendingDraws(); 168 mPopupZoomer.finishPendingDraws();
154 169
155 // The view should be visible. 170 // The view should be visible.
156 assertEquals(View.VISIBLE, mPopupZoomer.getVisibility()); 171 Assert.assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
157 assertTrue(mPopupZoomer.isShowing()); 172 Assert.assertTrue(mPopupZoomer.isShowing());
158 173
159 // Send tap event at a point outside the popup. 174 // Send tap event at a point outside the popup.
160 // i.e. coordinates greater than 10 + PopupZoomer.ZOOM_BOUNDS_MARGIN 175 // i.e. coordinates greater than 10 + PopupZoomer.ZOOM_BOUNDS_MARGIN
161 sendSingleTapTouchEventOnView(mPopupZoomer, 50, 50); 176 sendSingleTapTouchEventOnView(mPopupZoomer, 50, 50);
162 177
163 // Wait for the hide animation to finish. 178 // Wait for the hide animation to finish.
164 mPopupZoomer.finishPendingDraws(); 179 mPopupZoomer.finishPendingDraws();
165 180
166 // The view should be invisible. 181 // The view should be invisible.
167 assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility()); 182 Assert.assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
168 assertFalse(mPopupZoomer.isShowing()); 183 Assert.assertFalse(mPopupZoomer.isShowing());
169 } 184 }
170 185
186 @Test
171 @SmallTest 187 @SmallTest
172 @Feature({"Navigation"}) 188 @Feature({"Navigation"})
173 public void testOnTouchEventInsidePopupNoOnTapListener() throws Exception { 189 public void testOnTouchEventInsidePopupNoOnTapListener() throws Exception {
174 mPopupZoomer.setBitmap(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8 )); 190 mPopupZoomer.setBitmap(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8 ));
175 mPopupZoomer.show(new Rect(0, 0, 5, 5)); 191 mPopupZoomer.show(new Rect(0, 0, 5, 5));
176 192
177 // Wait for the animation to finish. 193 // Wait for the animation to finish.
178 mPopupZoomer.finishPendingDraws(); 194 mPopupZoomer.finishPendingDraws();
179 195
180 // The view should be visible. 196 // The view should be visible.
181 assertEquals(View.VISIBLE, mPopupZoomer.getVisibility()); 197 Assert.assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
182 assertTrue(mPopupZoomer.isShowing()); 198 Assert.assertTrue(mPopupZoomer.isShowing());
183 199
184 // Send tap event at a point inside the popup. 200 // Send tap event at a point inside the popup.
185 // i.e. coordinates between PopupZoomer.ZOOM_BOUNDS_MARGIN and 201 // i.e. coordinates between PopupZoomer.ZOOM_BOUNDS_MARGIN and
186 // PopupZoomer.ZOOM_BOUNDS_MARGIN + 10 202 // PopupZoomer.ZOOM_BOUNDS_MARGIN + 10
187 sendSingleTapTouchEventOnView(mPopupZoomer, 30, 30); 203 sendSingleTapTouchEventOnView(mPopupZoomer, 30, 30);
188 204
189 // Wait for the animation to finish (if there is any). 205 // Wait for the animation to finish (if there is any).
190 mPopupZoomer.finishPendingDraws(); 206 mPopupZoomer.finishPendingDraws();
191 207
192 // The view should still be visible as no OnTapListener is set. 208 // The view should still be visible as no OnTapListener is set.
193 assertEquals(View.VISIBLE, mPopupZoomer.getVisibility()); 209 Assert.assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
194 assertTrue(mPopupZoomer.isShowing()); 210 Assert.assertTrue(mPopupZoomer.isShowing());
195 } 211 }
196 212
213 @Test
197 @SmallTest 214 @SmallTest
198 @Feature({"Navigation"}) 215 @Feature({"Navigation"})
199 public void testHidePopupOnLosingFocus() throws Exception { 216 public void testHidePopupOnLosingFocus() throws Exception {
200 mPopupZoomer.setBitmap( 217 mPopupZoomer.setBitmap(
201 Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8)); 218 Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8));
202 mPopupZoomer.show(new Rect(0, 0, 5, 5)); 219 mPopupZoomer.show(new Rect(0, 0, 5, 5));
203 220
204 // Wait for the animation to finish. 221 // Wait for the animation to finish.
205 mPopupZoomer.finishPendingDraws(); 222 mPopupZoomer.finishPendingDraws();
206 223
207 // The view should be visible. 224 // The view should be visible.
208 assertEquals(View.VISIBLE, mPopupZoomer.getVisibility()); 225 Assert.assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
209 assertTrue(mPopupZoomer.isShowing()); 226 Assert.assertTrue(mPopupZoomer.isShowing());
210 227
211 // Simulate losing the focus. 228 // Simulate losing the focus.
212 mContentViewCore.onFocusChanged(false, true); 229 mContentViewCore.onFocusChanged(false, true);
213 230
214 // Wait for the hide animation to finish. 231 // Wait for the hide animation to finish.
215 mPopupZoomer.finishPendingDraws(); 232 mPopupZoomer.finishPendingDraws();
216 233
217 // Now that another view has been focused, the view should be invisible. 234 // Now that another view has been focused, the view should be invisible.
218 assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility()); 235 Assert.assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
219 assertFalse(mPopupZoomer.isShowing()); 236 Assert.assertFalse(mPopupZoomer.isShowing());
220 } 237 }
221 } 238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698