| Index: chrome/android/javatests/src/org/chromium/chrome/browser/ContentViewFocusTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/ContentViewFocusTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/ContentViewFocusTest.java
|
| index 294dbb31e731b848ea9b518bff0a96d144a7d3b1..a19d00567f322a1880fa6a5960b93021146aeef5 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/ContentViewFocusTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/ContentViewFocusTest.java
|
| @@ -9,6 +9,7 @@ import android.view.View;
|
| import android.view.View.OnFocusChangeListener;
|
|
|
| import org.chromium.base.ThreadUtils;
|
| +import org.chromium.base.test.util.CallbackHelper;
|
| import org.chromium.base.test.util.Feature;
|
| import org.chromium.base.test.util.FlakyTest;
|
| import org.chromium.base.test.util.Restriction;
|
| @@ -24,6 +25,7 @@ import org.chromium.chrome.test.util.OverviewModeBehaviorWatcher;
|
| import org.chromium.content.browser.test.util.Criteria;
|
| import org.chromium.content.browser.test.util.CriteriaHelper;
|
| import org.chromium.content.browser.test.util.TestTouchUtils;
|
| +import org.chromium.content_public.browser.WebContentsObserver;
|
|
|
| import java.util.ArrayDeque;
|
|
|
| @@ -35,7 +37,9 @@ public class ContentViewFocusTest extends ChromeTabbedActivityTestBase {
|
|
|
| private static final int WAIT_RESPONSE_MS = 2000;
|
|
|
| - private final ArrayDeque<Boolean> mFocusChanges = new ArrayDeque<Boolean>();
|
| + private final ArrayDeque<Boolean> mFocusChanges = new ArrayDeque<>();
|
| +
|
| + private String mTitle;
|
|
|
| private void addFocusChangedListener(View view) {
|
| view.setOnFocusChangeListener(new OnFocusChangeListener() {
|
| @@ -176,6 +180,50 @@ public class ContentViewFocusTest extends ChromeTabbedActivityTestBase {
|
| assertFalse("Unexpected focus change", haveFocusChanges());
|
| }
|
|
|
| + /**
|
| + * Verify ContentView window focus changes propagate to contents.
|
| + *
|
| + * @throws Exception
|
| + */
|
| + @MediumTest
|
| + public void testWindowFocusChangeTriggersBlur() throws Exception {
|
| + final CallbackHelper onTitleUpdatedHelper = new CallbackHelper();
|
| + final WebContentsObserver observer =
|
| + new WebContentsObserver(getActivity().getActivityTab().getWebContents()) {
|
| + @Override
|
| + public void titleWasSet(String title) {
|
| + mTitle = title;
|
| + onTitleUpdatedHelper.notifyCalled();
|
| + }
|
| + };
|
| + int callCount = onTitleUpdatedHelper.getCallCount();
|
| + String url = UrlUtils.getIsolatedTestFileUrl(
|
| + "chrome/test/data/android/content_view_focus/content_view_blur_focus.html");
|
| + loadUrl(url);
|
| + final View view = getActivity().getActivityTab().getContentViewCore().getContainerView();
|
| + onTitleUpdatedHelper.waitForCallback(callCount);
|
| + assertEquals("initial", mTitle);
|
| + callCount = onTitleUpdatedHelper.getCallCount();
|
| + ThreadUtils.runOnUiThread(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + view.onWindowFocusChanged(false);
|
| + }
|
| + });
|
| + onTitleUpdatedHelper.waitForCallback(callCount);
|
| + assertEquals("blurred", mTitle);
|
| + callCount = onTitleUpdatedHelper.getCallCount();
|
| + ThreadUtils.runOnUiThread(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + view.onWindowFocusChanged(true);
|
| + }
|
| + });
|
| + onTitleUpdatedHelper.waitForCallback(callCount);
|
| + assertEquals("focused", mTitle);
|
| + getActivity().getActivityTab().getWebContents().removeObserver(observer);
|
| + }
|
| +
|
| @Override
|
| public void startMainActivity() throws InterruptedException {
|
| startMainActivityOnBlankPage();
|
|
|