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

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

Issue 470193005: Hide PopupZoomer when the container view or window loses focus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed reduntant hide call in OnWindowFocusChanged 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
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() {
76 mPopupZoomer = createPopupZoomerForTest(getInstrumentation().getTargetCo ntext()); 77 mPopupZoomer = createPopupZoomerForTest(getInstrumentation().getTargetCo ntext());
78 mContentViewCore = new ContentViewCore(getActivity());
79 mContentViewCore.setPopupZoomerForTest(mPopupZoomer);
77 } 80 }
78 81
79 @SmallTest 82 @SmallTest
80 @Feature({"Navigation"}) 83 @Feature({"Navigation"})
81 public void testDefaultCreateState() throws Exception { 84 public void testDefaultCreateState() throws Exception {
82 assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility()); 85 assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
83 assertFalse(mPopupZoomer.isShowing()); 86 assertFalse(mPopupZoomer.isShowing());
84 } 87 }
85 88
86 @SmallTest 89 @SmallTest
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // PopupZoomer.ZOOM_BOUNDS_MARGIN + 10 168 // PopupZoomer.ZOOM_BOUNDS_MARGIN + 10
166 sendSingleTapTouchEventOnView(mPopupZoomer, 30, 30); 169 sendSingleTapTouchEventOnView(mPopupZoomer, 30, 30);
167 170
168 // Wait for the animation to finish (if there is any). 171 // Wait for the animation to finish (if there is any).
169 mPopupZoomer.finishPendingDraws(); 172 mPopupZoomer.finishPendingDraws();
170 173
171 // The view should still be visible as no OnTapListener is set. 174 // The view should still be visible as no OnTapListener is set.
172 assertEquals(View.VISIBLE, mPopupZoomer.getVisibility()); 175 assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
173 assertTrue(mPopupZoomer.isShowing()); 176 assertTrue(mPopupZoomer.isShowing());
174 } 177 }
178
179 @SmallTest
180 @Feature({"Navigation"})
181 public void testHidePopupOnLosingFocus() throws Exception {
182 mPopupZoomer.setBitmap(
183 Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8));
184 mPopupZoomer.show(new Rect(0, 0, 5, 5));
185
186 // Wait for the animation to finish.
187 mPopupZoomer.finishPendingDraws();
188
189 // The view should be visible.
190 assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
191 assertTrue(mPopupZoomer.isShowing());
192
193 // Simulate losing the focus.
194 mContentViewCore.onFocusChanged(false);
195
196 // Wait for the hide animation to finish.
197 mPopupZoomer.finishPendingDraws();
198
199 // Now that another view has been focused, the view should be invisible.
200 assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
201 assertFalse(mPopupZoomer.isShowing());
202 }
175 } 203 }
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