OLD | NEW |
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; |
| 25 import org.chromium.content.browser.ContentViewCore; |
24 import org.chromium.content.browser.test.util.Criteria; | 26 import org.chromium.content.browser.test.util.Criteria; |
25 import org.chromium.content.browser.test.util.CriteriaHelper; | 27 import org.chromium.content.browser.test.util.CriteriaHelper; |
26 import org.chromium.content.browser.test.util.TestTouchUtils; | 28 import org.chromium.content.browser.test.util.TestTouchUtils; |
| 29 import org.chromium.content_public.browser.WebContentsObserver; |
27 | 30 |
28 import java.util.ArrayDeque; | 31 import java.util.ArrayDeque; |
29 | 32 |
30 /** | 33 /** |
31 * Test suite for ContentView focus and its interaction with Tab switcher, | 34 * Test suite for ContentView focus and its interaction with Tab switcher, |
32 * Tab swiping, etc. | 35 * Tab swiping, etc. |
33 */ | 36 */ |
34 public class ContentViewFocusTest extends ChromeTabbedActivityTestBase { | 37 public class ContentViewFocusTest extends ChromeTabbedActivityTestBase { |
35 | 38 |
36 private static final int WAIT_RESPONSE_MS = 2000; | 39 private static final int WAIT_RESPONSE_MS = 2000; |
37 | 40 |
38 private final ArrayDeque<Boolean> mFocusChanges = new ArrayDeque<Boolean>(); | 41 private final ArrayDeque<Boolean> mFocusChanges = new ArrayDeque<Boolean>(); |
39 | 42 |
| 43 private String mTitle; |
| 44 |
40 private void addFocusChangedListener(View view) { | 45 private void addFocusChangedListener(View view) { |
41 view.setOnFocusChangeListener(new OnFocusChangeListener() { | 46 view.setOnFocusChangeListener(new OnFocusChangeListener() { |
42 @Override | 47 @Override |
43 public void onFocusChange(View v, boolean hasFocus) { | 48 public void onFocusChange(View v, boolean hasFocus) { |
44 synchronized (mFocusChanges) { | 49 synchronized (mFocusChanges) { |
45 mFocusChanges.add(Boolean.valueOf(hasFocus)); | 50 mFocusChanges.add(Boolean.valueOf(hasFocus)); |
46 mFocusChanges.notify(); | 51 mFocusChanges.notify(); |
47 } | 52 } |
48 } | 53 } |
49 }); | 54 }); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // Hide the tab switcher | 174 // Hide the tab switcher |
170 tabSwitcherButton = getActivity().findViewById(R.id.tab_switcher_button)
; | 175 tabSwitcherButton = getActivity().findViewById(R.id.tab_switcher_button)
; |
171 assertNotNull("'tab_switcher_button' view is not found.", tabSwitcherBut
ton); | 176 assertNotNull("'tab_switcher_button' view is not found.", tabSwitcherBut
ton); |
172 singleClickView(getActivity().findViewById(R.id.tab_switcher_button)); | 177 singleClickView(getActivity().findViewById(R.id.tab_switcher_button)); |
173 hideWatcher.waitForBehavior(); | 178 hideWatcher.waitForBehavior(); |
174 | 179 |
175 assertTrue("Content view didn't regain focus", blockForFocusChanged()); | 180 assertTrue("Content view didn't regain focus", blockForFocusChanged()); |
176 assertFalse("Unexpected focus change", haveFocusChanges()); | 181 assertFalse("Unexpected focus change", haveFocusChanges()); |
177 } | 182 } |
178 | 183 |
| 184 /** |
| 185 * Verify ContentView window focus changes propagate to contents. |
| 186 * |
| 187 * @throws Exception |
| 188 */ |
| 189 @MediumTest |
| 190 public void testPauseTriggersBlur() throws Exception { |
| 191 final CallbackHelper onTitleUpdatedHelper = new CallbackHelper(); |
| 192 final WebContentsObserver observer = |
| 193 new WebContentsObserver(getActivity().getActivityTab().getWebCon
tents()) { |
| 194 @Override |
| 195 public void titleWasSet(String title) { |
| 196 mTitle = title; |
| 197 onTitleUpdatedHelper.notifyCalled(); |
| 198 } |
| 199 }; |
| 200 int callCount = onTitleUpdatedHelper.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 ContentViewCore cvc = getActivity().getActivityTab().getContentVie
wCore(); |
| 205 onTitleUpdatedHelper.waitForCallback(callCount); |
| 206 assertEquals("initial", mTitle); |
| 207 callCount = onTitleUpdatedHelper.getCallCount(); |
| 208 ThreadUtils.runOnUiThread(new Runnable() { |
| 209 @Override |
| 210 public void run() { |
| 211 cvc.onPause(); |
| 212 } |
| 213 }); |
| 214 onTitleUpdatedHelper.waitForCallback(callCount); |
| 215 assertEquals("blurred", mTitle); |
| 216 callCount = onTitleUpdatedHelper.getCallCount(); |
| 217 ThreadUtils.runOnUiThread(new Runnable() { |
| 218 @Override |
| 219 public void run() { |
| 220 cvc.onResume(); |
| 221 } |
| 222 }); |
| 223 onTitleUpdatedHelper.waitForCallback(callCount); |
| 224 assertEquals("focused", mTitle); |
| 225 getActivity().getActivityTab().getWebContents().removeObserver(observer)
; |
| 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 } |
OLD | NEW |