Chromium Code Reviews| 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; |
| 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<>(); |
|
aelias_OOO_until_Jul13
2017/03/30 18:10:35
You still have one of these.
mthiesse
2017/03/30 18:42:31
Done.
| |
| 41 | |
| 42 private CallbackHelper mOnTitleUpdatedHelper; | |
| 43 private WebContentsObserver mObserver; | |
| 44 private String mTitle; | |
| 39 | 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 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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()) { | |
| 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 } |
| OLD | NEW |