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

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: Use pause/resume instead of WindowFocusChanged 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 side-by-side diff with in-line comments
Download patch
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..03b606444e50cb188c1f4b6105de6186d644347d 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;
@@ -21,9 +22,11 @@ import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
import org.chromium.chrome.test.util.ChromeRestriction;
import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.OverviewModeBehaviorWatcher;
+import org.chromium.content.browser.ContentViewCore;
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 +40,8 @@ public class ContentViewFocusTest extends ChromeTabbedActivityTestBase {
private final ArrayDeque<Boolean> mFocusChanges = new ArrayDeque<Boolean>();
+ private String mTitle;
+
private void addFocusChangedListener(View view) {
view.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
@@ -176,6 +181,50 @@ public class ContentViewFocusTest extends ChromeTabbedActivityTestBase {
assertFalse("Unexpected focus change", haveFocusChanges());
}
+ /**
+ * Verify ContentView window focus changes propagate to contents.
+ *
+ * @throws Exception
+ */
+ @MediumTest
+ public void testPauseTriggersBlur() 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 ContentViewCore cvc = getActivity().getActivityTab().getContentViewCore();
+ onTitleUpdatedHelper.waitForCallback(callCount);
+ assertEquals("initial", mTitle);
+ callCount = onTitleUpdatedHelper.getCallCount();
+ ThreadUtils.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ cvc.onPause();
+ }
+ });
+ onTitleUpdatedHelper.waitForCallback(callCount);
+ assertEquals("blurred", mTitle);
+ callCount = onTitleUpdatedHelper.getCallCount();
+ ThreadUtils.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ cvc.onResume();
+ }
+ });
+ onTitleUpdatedHelper.waitForCallback(callCount);
+ assertEquals("focused", mTitle);
+ getActivity().getActivityTab().getWebContents().removeObserver(observer);
+ }
+
@Override
public void startMainActivity() throws InterruptedException {
startMainActivityOnBlankPage();

Powered by Google App Engine
This is Rietveld 408576698