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

Unified 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, 9 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..e561fdcbff1b6bd5d7d990773c6802833c7d6660 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;
@@ -37,6 +39,10 @@ public class ContentViewFocusTest extends ChromeTabbedActivityTestBase {
private final ArrayDeque<Boolean> mFocusChanges = new ArrayDeque<Boolean>();
+ private CallbackHelper mOnTitleUpdatedHelper;
+ private WebContentsObserver mObserver;
+ private String mTitle;
+
private void addFocusChangedListener(View view) {
view.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
@@ -176,6 +182,49 @@ 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 {
+ mOnTitleUpdatedHelper = new CallbackHelper();
+ mObserver = new WebContentsObserver(getActivity().getActivityTab().getWebContents()) {
Sami 2017/04/03 10:23:45 nit: Looks like mObserver could be a local variabl
mthiesse 2017/04/03 15:50:03 Done.
+ @Override
+ public void titleWasSet(String title) {
+ mTitle = title;
+ mOnTitleUpdatedHelper.notifyCalled();
+ }
+ };
+ int callCount = mOnTitleUpdatedHelper.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();
+ mOnTitleUpdatedHelper.waitForCallback(callCount);
+ assertEquals("initial", mTitle);
+ callCount = mOnTitleUpdatedHelper.getCallCount();
+ ThreadUtils.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ view.onWindowFocusChanged(false);
+ }
+ });
+ mOnTitleUpdatedHelper.waitForCallback(callCount);
+ assertEquals("blurred", mTitle);
+ callCount = mOnTitleUpdatedHelper.getCallCount();
+ ThreadUtils.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ view.onWindowFocusChanged(true);
+ }
+ });
+ mOnTitleUpdatedHelper.waitForCallback(callCount);
+ assertEquals("focused", mTitle);
+ getActivity().getActivityTab().getWebContents().removeObserver(mObserver);
+ }
+
@Override
public void startMainActivity() throws InterruptedException {
startMainActivityOnBlankPage();
« 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