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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/ContentViewFocusTest.java

Issue 2779033004: [Android] Focus/Blur contents when window focus changes (Closed)
Patch Set: rebase + fix nit 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
« no previous file with comments | « no previous file | chrome/test/data/android/content_view_focus/content_view_blur_focus.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.chrome.browser; 5 package org.chromium.chrome.browser;
6 6
7 import android.support.test.filters.MediumTest; 7 import android.support.test.filters.MediumTest;
8 import android.view.View; 8 import android.view.View;
9 import android.view.View.OnFocusChangeListener; 9 import android.view.View.OnFocusChangeListener;
10 10
11 import org.chromium.base.ThreadUtils; 11 import org.chromium.base.ThreadUtils;
12 import org.chromium.base.test.util.CallbackHelper;
12 import org.chromium.base.test.util.Feature; 13 import org.chromium.base.test.util.Feature;
13 import org.chromium.base.test.util.FlakyTest; 14 import org.chromium.base.test.util.FlakyTest;
14 import org.chromium.base.test.util.Restriction; 15 import org.chromium.base.test.util.Restriction;
15 import org.chromium.base.test.util.UrlUtils; 16 import org.chromium.base.test.util.UrlUtils;
16 import org.chromium.chrome.R; 17 import org.chromium.chrome.R;
17 import org.chromium.chrome.browser.compositor.layouts.LayoutManager; 18 import org.chromium.chrome.browser.compositor.layouts.LayoutManager;
18 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EdgeSwipeHandl er; 19 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EdgeSwipeHandl er;
19 import org.chromium.chrome.browser.compositor.layouts.eventfilter.ScrollDirectio n; 20 import org.chromium.chrome.browser.compositor.layouts.eventfilter.ScrollDirectio n;
20 import org.chromium.chrome.test.ChromeTabbedActivityTestBase; 21 import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
21 import org.chromium.chrome.test.util.ChromeRestriction; 22 import org.chromium.chrome.test.util.ChromeRestriction;
22 import org.chromium.chrome.test.util.ChromeTabUtils; 23 import org.chromium.chrome.test.util.ChromeTabUtils;
23 import org.chromium.chrome.test.util.OverviewModeBehaviorWatcher; 24 import org.chromium.chrome.test.util.OverviewModeBehaviorWatcher;
24 import org.chromium.content.browser.test.util.Criteria; 25 import org.chromium.content.browser.test.util.Criteria;
25 import org.chromium.content.browser.test.util.CriteriaHelper; 26 import org.chromium.content.browser.test.util.CriteriaHelper;
26 import org.chromium.content.browser.test.util.TestTouchUtils; 27 import org.chromium.content.browser.test.util.TestTouchUtils;
28 import org.chromium.content_public.browser.WebContentsObserver;
27 29
28 import java.util.ArrayDeque; 30 import java.util.ArrayDeque;
29 31
30 /** 32 /**
31 * Test suite for ContentView focus and its interaction with Tab switcher, 33 * Test suite for ContentView focus and its interaction with Tab switcher,
32 * Tab swiping, etc. 34 * Tab swiping, etc.
33 */ 35 */
34 public class ContentViewFocusTest extends ChromeTabbedActivityTestBase { 36 public class ContentViewFocusTest extends ChromeTabbedActivityTestBase {
35 37
36 private static final int WAIT_RESPONSE_MS = 2000; 38 private static final int WAIT_RESPONSE_MS = 2000;
37 39
38 private final ArrayDeque<Boolean> mFocusChanges = new ArrayDeque<Boolean>(); 40 private final ArrayDeque<Boolean> mFocusChanges = new ArrayDeque<Boolean>();
39 41
42 private CallbackHelper mOnTitleUpdatedHelper;
43 private WebContentsObserver mObserver;
44 private String mTitle;
45
40 private void addFocusChangedListener(View view) { 46 private void addFocusChangedListener(View view) {
41 view.setOnFocusChangeListener(new OnFocusChangeListener() { 47 view.setOnFocusChangeListener(new OnFocusChangeListener() {
42 @Override 48 @Override
43 public void onFocusChange(View v, boolean hasFocus) { 49 public void onFocusChange(View v, boolean hasFocus) {
44 synchronized (mFocusChanges) { 50 synchronized (mFocusChanges) {
45 mFocusChanges.add(Boolean.valueOf(hasFocus)); 51 mFocusChanges.add(Boolean.valueOf(hasFocus));
46 mFocusChanges.notify(); 52 mFocusChanges.notify();
47 } 53 }
48 } 54 }
49 }); 55 });
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // Hide the tab switcher 175 // Hide the tab switcher
170 tabSwitcherButton = getActivity().findViewById(R.id.tab_switcher_button) ; 176 tabSwitcherButton = getActivity().findViewById(R.id.tab_switcher_button) ;
171 assertNotNull("'tab_switcher_button' view is not found.", tabSwitcherBut ton); 177 assertNotNull("'tab_switcher_button' view is not found.", tabSwitcherBut ton);
172 singleClickView(getActivity().findViewById(R.id.tab_switcher_button)); 178 singleClickView(getActivity().findViewById(R.id.tab_switcher_button));
173 hideWatcher.waitForBehavior(); 179 hideWatcher.waitForBehavior();
174 180
175 assertTrue("Content view didn't regain focus", blockForFocusChanged()); 181 assertTrue("Content view didn't regain focus", blockForFocusChanged());
176 assertFalse("Unexpected focus change", haveFocusChanges()); 182 assertFalse("Unexpected focus change", haveFocusChanges());
177 } 183 }
178 184
185 /**
186 * Verify ContentView window focus changes propagate to contents.
187 *
188 * @throws Exception
189 */
190 @MediumTest
191 public void testWindowFocusChangeTriggersBlur() throws Exception {
192 mOnTitleUpdatedHelper = new CallbackHelper();
193 mObserver = new WebContentsObserver(getActivity().getActivityTab().getWe bContents()) {
Sami 2017/04/03 10:23:45 nit: Looks like mObserver could be a local variabl
mthiesse 2017/04/03 15:50:03 Done.
194 @Override
195 public void titleWasSet(String title) {
196 mTitle = title;
197 mOnTitleUpdatedHelper.notifyCalled();
198 }
199 };
200 int callCount = mOnTitleUpdatedHelper.getCallCount();
201 String url = UrlUtils.getIsolatedTestFileUrl(
202 "chrome/test/data/android/content_view_focus/content_view_blur_f ocus.html");
203 loadUrl(url);
204 final View view = getActivity().getActivityTab().getContentViewCore().ge tContainerView();
205 mOnTitleUpdatedHelper.waitForCallback(callCount);
206 assertEquals("initial", mTitle);
207 callCount = mOnTitleUpdatedHelper.getCallCount();
208 ThreadUtils.runOnUiThread(new Runnable() {
209 @Override
210 public void run() {
211 view.onWindowFocusChanged(false);
212 }
213 });
214 mOnTitleUpdatedHelper.waitForCallback(callCount);
215 assertEquals("blurred", mTitle);
216 callCount = mOnTitleUpdatedHelper.getCallCount();
217 ThreadUtils.runOnUiThread(new Runnable() {
218 @Override
219 public void run() {
220 view.onWindowFocusChanged(true);
221 }
222 });
223 mOnTitleUpdatedHelper.waitForCallback(callCount);
224 assertEquals("focused", mTitle);
225 getActivity().getActivityTab().getWebContents().removeObserver(mObserver );
226 }
227
179 @Override 228 @Override
180 public void startMainActivity() throws InterruptedException { 229 public void startMainActivity() throws InterruptedException {
181 startMainActivityOnBlankPage(); 230 startMainActivityOnBlankPage();
182 } 231 }
183 } 232 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/android/content_view_focus/content_view_blur_focus.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698