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

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

Issue 497753003: Hide PopupZoomer when the container view or window loses focus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/ContentViewCore.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
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.test.InstrumentationTestCase;
13 import android.test.suitebuilder.annotation.SmallTest; 12 import android.test.suitebuilder.annotation.SmallTest;
14 import android.view.MotionEvent; 13 import android.view.MotionEvent;
15 import android.view.View; 14 import android.view.View;
16 15
17 import org.chromium.base.test.util.Feature; 16 import org.chromium.base.test.util.Feature;
17 import org.chromium.content_shell_apk.ContentShellTestBase;
18 18
19 /** 19 /**
20 * Tests for PopupZoomer. 20 * Tests for PopupZoomer.
21 */ 21 */
22 public class PopupZoomerTest extends InstrumentationTestCase { 22 public class PopupZoomerTest extends ContentShellTestBase {
23 private CustomCanvasPopupZoomer mPopupZoomer; 23 private CustomCanvasPopupZoomer mPopupZoomer;
24 private ContentViewCore mContentViewCore;
24 25
25 private static class CustomCanvasPopupZoomer extends PopupZoomer { 26 private static class CustomCanvasPopupZoomer extends PopupZoomer {
26 Canvas mCanvas; 27 Canvas mCanvas;
27 long mPendingDraws = 0; 28 long mPendingDraws = 0;
28 29
29 CustomCanvasPopupZoomer(Context context, Canvas c) { 30 CustomCanvasPopupZoomer(Context context, Canvas c) {
30 super(context); 31 super(context);
31 mCanvas = c; 32 mCanvas = c;
32 } 33 }
33 34
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 66
66 private void sendSingleTapTouchEventOnView(View view, float x, float y) { 67 private void sendSingleTapTouchEventOnView(View view, float x, float y) {
67 final long downEvent = SystemClock.uptimeMillis(); 68 final long downEvent = SystemClock.uptimeMillis();
68 view.onTouchEvent( 69 view.onTouchEvent(
69 MotionEvent.obtain(downEvent, downEvent, MotionEvent.ACTION_DOWN , x, y, 0)); 70 MotionEvent.obtain(downEvent, downEvent, MotionEvent.ACTION_DOWN , x, y, 0));
70 view.onTouchEvent( 71 view.onTouchEvent(
71 MotionEvent.obtain(downEvent, downEvent + 10, MotionEvent.ACTION _UP, x, y, 0)); 72 MotionEvent.obtain(downEvent, downEvent + 10, MotionEvent.ACTION _UP, x, y, 0));
72 } 73 }
73 74
74 @Override 75 @Override
75 public void setUp() { 76 public void setUp() throws Exception {
77 super.setUp();
76 mPopupZoomer = createPopupZoomerForTest(getInstrumentation().getTargetCo ntext()); 78 mPopupZoomer = createPopupZoomerForTest(getInstrumentation().getTargetCo ntext());
79 mContentViewCore = new ContentViewCore(getActivity());
80 mContentViewCore.setPopupZoomerForTest(mPopupZoomer);
77 } 81 }
78 82
79 @SmallTest 83 @SmallTest
80 @Feature({"Navigation"}) 84 @Feature({"Navigation"})
81 public void testDefaultCreateState() throws Exception { 85 public void testDefaultCreateState() throws Exception {
82 assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility()); 86 assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
83 assertFalse(mPopupZoomer.isShowing()); 87 assertFalse(mPopupZoomer.isShowing());
84 } 88 }
85 89
86 @SmallTest 90 @SmallTest
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // PopupZoomer.ZOOM_BOUNDS_MARGIN + 10 169 // PopupZoomer.ZOOM_BOUNDS_MARGIN + 10
166 sendSingleTapTouchEventOnView(mPopupZoomer, 30, 30); 170 sendSingleTapTouchEventOnView(mPopupZoomer, 30, 30);
167 171
168 // Wait for the animation to finish (if there is any). 172 // Wait for the animation to finish (if there is any).
169 mPopupZoomer.finishPendingDraws(); 173 mPopupZoomer.finishPendingDraws();
170 174
171 // The view should still be visible as no OnTapListener is set. 175 // The view should still be visible as no OnTapListener is set.
172 assertEquals(View.VISIBLE, mPopupZoomer.getVisibility()); 176 assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
173 assertTrue(mPopupZoomer.isShowing()); 177 assertTrue(mPopupZoomer.isShowing());
174 } 178 }
179
180 @SmallTest
181 @Feature({"Navigation"})
182 public void testHidePopupOnLosingFocus() throws Exception {
183 mPopupZoomer.setBitmap(
184 Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8));
185 mPopupZoomer.show(new Rect(0, 0, 5, 5));
186
187 // Wait for the animation to finish.
188 mPopupZoomer.finishPendingDraws();
189
190 // The view should be visible.
191 assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
192 assertTrue(mPopupZoomer.isShowing());
193
194 // Simulate losing the focus.
195 mContentViewCore.onFocusChanged(false);
196
197 // Wait for the hide animation to finish.
198 mPopupZoomer.finishPendingDraws();
199
200 // Now that another view has been focused, the view should be invisible.
201 assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
202 assertFalse(mPopupZoomer.isShowing());
203 }
175 } 204 }
OLDNEW
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698