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

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: Add comments 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 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<>();
41
42 private String mTitle;
39 43
40 private void addFocusChangedListener(View view) { 44 private void addFocusChangedListener(View view) {
41 view.setOnFocusChangeListener(new OnFocusChangeListener() { 45 view.setOnFocusChangeListener(new OnFocusChangeListener() {
42 @Override 46 @Override
43 public void onFocusChange(View v, boolean hasFocus) { 47 public void onFocusChange(View v, boolean hasFocus) {
44 synchronized (mFocusChanges) { 48 synchronized (mFocusChanges) {
45 mFocusChanges.add(Boolean.valueOf(hasFocus)); 49 mFocusChanges.add(Boolean.valueOf(hasFocus));
46 mFocusChanges.notify(); 50 mFocusChanges.notify();
47 } 51 }
48 } 52 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // Hide the tab switcher 173 // Hide the tab switcher
170 tabSwitcherButton = getActivity().findViewById(R.id.tab_switcher_button) ; 174 tabSwitcherButton = getActivity().findViewById(R.id.tab_switcher_button) ;
171 assertNotNull("'tab_switcher_button' view is not found.", tabSwitcherBut ton); 175 assertNotNull("'tab_switcher_button' view is not found.", tabSwitcherBut ton);
172 singleClickView(getActivity().findViewById(R.id.tab_switcher_button)); 176 singleClickView(getActivity().findViewById(R.id.tab_switcher_button));
173 hideWatcher.waitForBehavior(); 177 hideWatcher.waitForBehavior();
174 178
175 assertTrue("Content view didn't regain focus", blockForFocusChanged()); 179 assertTrue("Content view didn't regain focus", blockForFocusChanged());
176 assertFalse("Unexpected focus change", haveFocusChanges()); 180 assertFalse("Unexpected focus change", haveFocusChanges());
177 } 181 }
178 182
183 /**
184 * Verify ContentView window focus changes propagate to contents.
185 *
186 * @throws Exception
187 */
188 @MediumTest
189 public void testWindowFocusChangeTriggersBlur() throws Exception {
190 final CallbackHelper onTitleUpdatedHelper = new CallbackHelper();
191 final WebContentsObserver observer =
192 new WebContentsObserver(getActivity().getActivityTab().getWebCon tents()) {
193 @Override
194 public void titleWasSet(String title) {
195 mTitle = title;
196 onTitleUpdatedHelper.notifyCalled();
197 }
198 };
199 int callCount = onTitleUpdatedHelper.getCallCount();
200 String url = UrlUtils.getIsolatedTestFileUrl(
201 "chrome/test/data/android/content_view_focus/content_view_blur_f ocus.html");
202 loadUrl(url);
203 final View view = getActivity().getActivityTab().getContentViewCore().ge tContainerView();
204 onTitleUpdatedHelper.waitForCallback(callCount);
205 assertEquals("initial", mTitle);
206 callCount = onTitleUpdatedHelper.getCallCount();
207 ThreadUtils.runOnUiThread(new Runnable() {
208 @Override
209 public void run() {
210 view.onWindowFocusChanged(false);
211 }
212 });
213 onTitleUpdatedHelper.waitForCallback(callCount);
214 assertEquals("blurred", mTitle);
215 callCount = onTitleUpdatedHelper.getCallCount();
216 ThreadUtils.runOnUiThread(new Runnable() {
217 @Override
218 public void run() {
219 view.onWindowFocusChanged(true);
220 }
221 });
222 onTitleUpdatedHelper.waitForCallback(callCount);
223 assertEquals("focused", mTitle);
224 getActivity().getActivityTab().getWebContents().removeObserver(observer) ;
225 }
226
179 @Override 227 @Override
180 public void startMainActivity() throws InterruptedException { 228 public void startMainActivity() throws InterruptedException {
181 startMainActivityOnBlankPage(); 229 startMainActivityOnBlankPage();
182 } 230 }
183 } 231 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698