Commit fbc7c1e4 authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

TextSuggestionHost on WebContentsUserData

This CL moves Java TextSuggestionHost to be managed by
WebContentsUserData so ContentViewCore doesn't have to keep
a reference to the object, and the object can be obtained
easily by TextSuggestionHost.fromWebContents(). It helps
decouple the class from CVC.

Bug: 789000
Change-Id: Iefdeb0a727fc975323b7f8f24d4eb187ad38601b
Reviewed-on: https://chromium-review.googlesource.com/892180Reviewed-by: default avatarRyan Landay <rlanday@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533068}
parent b17acb28
...@@ -13,7 +13,6 @@ import android.view.ViewGroup; ...@@ -13,7 +13,6 @@ import android.view.ViewGroup;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.content.browser.input.SelectPopup; import org.chromium.content.browser.input.SelectPopup;
import org.chromium.content.browser.input.TextSuggestionHost;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.ViewAndroidDelegate; import org.chromium.ui.base.ViewAndroidDelegate;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
...@@ -378,15 +377,6 @@ public interface ContentViewCore { ...@@ -378,15 +377,6 @@ public interface ContentViewCore {
// Test-only methods // Test-only methods
/**
* @return The TextSuggestionHost that handles displaying the text suggestion menu.
*/
@VisibleForTesting
TextSuggestionHost getTextSuggestionHostForTesting();
@VisibleForTesting
void setTextSuggestionHostForTesting(TextSuggestionHost textSuggestionHost);
/** /**
* @return The amount of the top controls height if controls are in the state * @return The amount of the top controls height if controls are in the state
* of shrinking Blink's view size, otherwise 0. * of shrinking Blink's view size, otherwise 0.
......
...@@ -158,8 +158,6 @@ public class ContentViewCoreImpl ...@@ -158,8 +158,6 @@ public class ContentViewCoreImpl
private SelectPopup mSelectPopup; private SelectPopup mSelectPopup;
private long mNativeSelectPopupSourceFrame; private long mNativeSelectPopupSourceFrame;
private TextSuggestionHost mTextSuggestionHost;
// Cached copy of all positions and scales as reported by the renderer. // Cached copy of all positions and scales as reported by the renderer.
private RenderCoordinates mRenderCoordinates; private RenderCoordinates mRenderCoordinates;
...@@ -253,23 +251,11 @@ public class ContentViewCoreImpl ...@@ -253,23 +251,11 @@ public class ContentViewCoreImpl
return nativeGetJavaWindowAndroid(mNativeContentViewCore); return nativeGetJavaWindowAndroid(mNativeContentViewCore);
} }
@VisibleForTesting
@Override
public TextSuggestionHost getTextSuggestionHostForTesting() {
return mTextSuggestionHost;
}
@VisibleForTesting @VisibleForTesting
void setWebContentsForTesting(WebContentsImpl webContents) { void setWebContentsForTesting(WebContentsImpl webContents) {
mWebContents = webContents; mWebContents = webContents;
} }
@VisibleForTesting
@Override
public void setTextSuggestionHostForTesting(TextSuggestionHost textSuggestionHost) {
mTextSuggestionHost = textSuggestionHost;
}
/** /**
* Add {@link WindowAndroidChangeObserver} object. * Add {@link WindowAndroidChangeObserver} object.
* @param observer Observer instance to add. * @param observer Observer instance to add.
...@@ -321,9 +307,9 @@ public class ContentViewCoreImpl ...@@ -321,9 +307,9 @@ public class ContentViewCoreImpl
mWebContents, mContainerView, new InputMethodManagerWrapper(mContext)); mWebContents, mContainerView, new InputMethodManagerWrapper(mContext));
imeAdapter.addEventObserver(this); imeAdapter.addEventObserver(this);
imeAdapter.addEventObserver(TapDisambiguator.create(mContext, mWebContents, containerView)); imeAdapter.addEventObserver(TapDisambiguator.create(mContext, mWebContents, containerView));
mTextSuggestionHost = TextSuggestionHost textSuggestionHost =
new TextSuggestionHost(mContext, mWebContents, windowAndroid, mContainerView); TextSuggestionHost.create(mContext, mWebContents, windowAndroid, containerView);
addWindowAndroidChangedObserver(mTextSuggestionHost); addWindowAndroidChangedObserver(textSuggestionHost);
mWebContentsObserver = new ContentViewWebContentsObserver(this); mWebContentsObserver = new ContentViewWebContentsObserver(this);
...@@ -334,7 +320,7 @@ public class ContentViewCoreImpl ...@@ -334,7 +320,7 @@ public class ContentViewCoreImpl
mWindowEventObservers.addObserver(controller); mWindowEventObservers.addObserver(controller);
mWindowEventObservers.addObserver(getGestureListenerManager()); mWindowEventObservers.addObserver(getGestureListenerManager());
mWindowEventObservers.addObserver(mTextSuggestionHost); mWindowEventObservers.addObserver(textSuggestionHost);
mWindowEventObservers.addObserver(imeAdapter); mWindowEventObservers.addObserver(imeAdapter);
mWindowEventObservers.addObserver(wcax); mWindowEventObservers.addObserver(wcax);
} }
...@@ -385,7 +371,7 @@ public class ContentViewCoreImpl ...@@ -385,7 +371,7 @@ public class ContentViewCoreImpl
if (mContainerView != null) { if (mContainerView != null) {
hideSelectPopupWithCancelMessage(); hideSelectPopupWithCancelMessage();
getImeAdapter().setContainerView(containerView); getImeAdapter().setContainerView(containerView);
mTextSuggestionHost.setContainerView(containerView); getTextSuggestionHost().setContainerView(containerView);
} }
mContainerView = containerView; mContainerView = containerView;
...@@ -416,6 +402,10 @@ public class ContentViewCoreImpl ...@@ -416,6 +402,10 @@ public class ContentViewCoreImpl
return WebContentsAccessibilityImpl.fromWebContents(mWebContents); return WebContentsAccessibilityImpl.fromWebContents(mWebContents);
} }
private TextSuggestionHost getTextSuggestionHost() {
return TextSuggestionHost.fromWebContents(mWebContents);
}
@CalledByNative @CalledByNative
private void onNativeContentViewCoreDestroyed(long nativeContentViewCore) { private void onNativeContentViewCoreDestroyed(long nativeContentViewCore) {
assert nativeContentViewCore == mNativeContentViewCore; assert nativeContentViewCore == mNativeContentViewCore;
...@@ -436,7 +426,7 @@ public class ContentViewCoreImpl ...@@ -436,7 +426,7 @@ public class ContentViewCoreImpl
mWebContentsObserver.destroy(); mWebContentsObserver.destroy();
mWebContentsObserver = null; mWebContentsObserver = null;
getImeAdapter().resetAndHideKeyboard(); getImeAdapter().resetAndHideKeyboard();
removeWindowAndroidChangedObserver(mTextSuggestionHost); removeWindowAndroidChangedObserver(getTextSuggestionHost());
mWindowEventObservers.clear(); mWindowEventObservers.clear();
hidePopupsAndPreserveSelection(); hidePopupsAndPreserveSelection();
mWebContents = null; mWebContents = null;
...@@ -558,8 +548,6 @@ public class ContentViewCoreImpl ...@@ -558,8 +548,6 @@ public class ContentViewCoreImpl
private void hidePopupsAndClearSelection() { private void hidePopupsAndClearSelection() {
if (mWebContents != null) { if (mWebContents != null) {
getSelectionPopupController().destroyActionModeAndUnselect(); getSelectionPopupController().destroyActionModeAndUnselect();
destroyPastePopup();
getTapDisambiguator().hidePopup(false);
mWebContents.dismissTextHandles(); mWebContents.dismissTextHandles();
} }
hidePopups(); hidePopups();
...@@ -569,15 +557,17 @@ public class ContentViewCoreImpl ...@@ -569,15 +557,17 @@ public class ContentViewCoreImpl
private void hidePopupsAndPreserveSelection() { private void hidePopupsAndPreserveSelection() {
if (mWebContents != null) { if (mWebContents != null) {
getSelectionPopupController().destroyActionModeAndKeepSelection(); getSelectionPopupController().destroyActionModeAndKeepSelection();
destroyPastePopup();
getTapDisambiguator().hidePopup(false);
} }
hidePopups(); hidePopups();
} }
private void hidePopups() { private void hidePopups() {
if (mWebContents != null) {
destroyPastePopup();
getTapDisambiguator().hidePopup(false);
getTextSuggestionHost().hidePopups();
}
hideSelectPopupWithCancelMessage(); hideSelectPopupWithCancelMessage();
mTextSuggestionHost.hidePopups();
} }
private void restoreSelectionPopupsIfNecessary() { private void restoreSelectionPopupsIfNecessary() {
...@@ -1141,7 +1131,7 @@ public class ContentViewCoreImpl ...@@ -1141,7 +1131,7 @@ public class ContentViewCoreImpl
hidePopupsAndPreserveSelection(); hidePopupsAndPreserveSelection();
getSelectionPopupController().showActionModeOrClearOnFailure(); getSelectionPopupController().showActionModeOrClearOnFailure();
} }
mTextSuggestionHost.hidePopups(); getTextSuggestionHost().hidePopups();
int rotationDegrees = 0; int rotationDegrees = 0;
switch (rotation) { switch (rotation) {
......
...@@ -13,6 +13,8 @@ import org.chromium.base.annotations.JNINamespace; ...@@ -13,6 +13,8 @@ import org.chromium.base.annotations.JNINamespace;
import org.chromium.content.browser.WindowAndroidChangedObserver; import org.chromium.content.browser.WindowAndroidChangedObserver;
import org.chromium.content.browser.WindowEventObserver; import org.chromium.content.browser.WindowEventObserver;
import org.chromium.content.browser.webcontents.WebContentsImpl; import org.chromium.content.browser.webcontents.WebContentsImpl;
import org.chromium.content.browser.webcontents.WebContentsUserData;
import org.chromium.content.browser.webcontents.WebContentsUserData.UserDataFactory;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
...@@ -24,9 +26,9 @@ import org.chromium.ui.base.WindowAndroid; ...@@ -24,9 +26,9 @@ import org.chromium.ui.base.WindowAndroid;
@JNINamespace("content") @JNINamespace("content")
public class TextSuggestionHost implements WindowEventObserver, WindowAndroidChangedObserver { public class TextSuggestionHost implements WindowEventObserver, WindowAndroidChangedObserver {
private long mNativeTextSuggestionHost; private long mNativeTextSuggestionHost;
private final Context mContext;
private final WebContentsImpl mWebContents; private final WebContentsImpl mWebContents;
private Context mContext;
private View mContainerView; private View mContainerView;
private boolean mIsAttachedToWindow; private boolean mIsAttachedToWindow;
private WindowAndroid mWindowAndroid; private WindowAndroid mWindowAndroid;
...@@ -34,13 +36,58 @@ public class TextSuggestionHost implements WindowEventObserver, WindowAndroidCha ...@@ -34,13 +36,58 @@ public class TextSuggestionHost implements WindowEventObserver, WindowAndroidCha
private SpellCheckPopupWindow mSpellCheckPopupWindow; private SpellCheckPopupWindow mSpellCheckPopupWindow;
private TextSuggestionsPopupWindow mTextSuggestionsPopupWindow; private TextSuggestionsPopupWindow mTextSuggestionsPopupWindow;
public TextSuggestionHost( private boolean mInitialized;
Context context, WebContentsImpl webContents, WindowAndroid windowAndroid, View view) {
private static final class UserDataFactoryLazyHolder {
private static final UserDataFactory<TextSuggestionHost> INSTANCE = TextSuggestionHost::new;
}
/**
* Create {@link TextSuggestionHost} instance.
* @param context Context for action mode.
* @param webContents WebContents instance.
* @param windowAndroid The current WindowAndroid instance.
* @param view Container view.
*/
public static TextSuggestionHost create(
Context context, WebContents webContents, WindowAndroid windowAndroid, View view) {
TextSuggestionHost host = WebContentsUserData.fromWebContents(
webContents, TextSuggestionHost.class, UserDataFactoryLazyHolder.INSTANCE);
assert host != null;
assert !host.initialized();
host.init(context, windowAndroid, view);
return host;
}
/**
* Get {@link TextSuggestionHost} object used for the give WebContents.
* {@link #create()} should precede any calls to this.
* @param webContents {@link WebContents} object.
* @return {@link TextSuggestionHost} object. {@code null} if not available because
* {@link #create()} is not called yet.
*/
public static TextSuggestionHost fromWebContents(WebContents webContents) {
return WebContentsUserData.fromWebContents(webContents, TextSuggestionHost.class, null);
}
/**
* Create {@link TextSuggestionHost} instance.
* @param webContents WebContents instance.
*/
public TextSuggestionHost(WebContents webContents) {
mWebContents = (WebContentsImpl) webContents;
}
private void init(Context context, WindowAndroid windowAndroid, View view) {
mContext = context; mContext = context;
mWebContents = webContents;
mWindowAndroid = windowAndroid; mWindowAndroid = windowAndroid;
mContainerView = view; mContainerView = view;
mNativeTextSuggestionHost = nativeInit(webContents); mNativeTextSuggestionHost = nativeInit(mWebContents);
mInitialized = true;
}
private boolean initialized() {
return mInitialized;
} }
private float getContentOffsetYPix() { private float getContentOffsetYPix() {
......
...@@ -23,7 +23,6 @@ import org.junit.runner.RunWith; ...@@ -23,7 +23,6 @@ import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.input.TextSuggestionHost;
import org.chromium.content.browser.test.ContentJUnit4ClassRunner; import org.chromium.content.browser.test.ContentJUnit4ClassRunner;
import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper; import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper;
import org.chromium.content.browser.webcontents.WebContentsImpl; import org.chromium.content.browser.webcontents.WebContentsImpl;
...@@ -108,8 +107,6 @@ public class PopupZoomerTest { ...@@ -108,8 +107,6 @@ public class PopupZoomerTest {
mPopupZoomer = createPopupZoomerForTest( mPopupZoomer = createPopupZoomerForTest(
InstrumentationRegistry.getTargetContext(), containerView); InstrumentationRegistry.getTargetContext(), containerView);
TapDisambiguator.fromWebContents(webContents).setPopupZoomerForTest(mPopupZoomer); TapDisambiguator.fromWebContents(webContents).setPopupZoomerForTest(mPopupZoomer);
mContentViewCore.setTextSuggestionHostForTesting(new TextSuggestionHost(
context, (WebContentsImpl) webContents, null, containerView));
} }
}); });
} }
......
...@@ -55,7 +55,7 @@ public class TextSuggestionMenuTest { ...@@ -55,7 +55,7 @@ public class TextSuggestionMenuTest {
public void testDeleteWordMarkedWithSuggestionMarker() public void testDeleteWordMarkedWithSuggestionMarker()
throws InterruptedException, Throwable, TimeoutException { throws InterruptedException, Throwable, TimeoutException {
final ContentViewCore cvc = mRule.getContentViewCore(); final ContentViewCore cvc = mRule.getContentViewCore();
WebContents webContents = cvc.getWebContents(); WebContents webContents = mRule.getWebContents();
DOMUtils.focusNode(webContents, "div"); DOMUtils.focusNode(webContents, "div");
...@@ -66,22 +66,22 @@ public class TextSuggestionMenuTest { ...@@ -66,22 +66,22 @@ public class TextSuggestionMenuTest {
mRule.commitText(textToCommit, 1); mRule.commitText(textToCommit, 1);
DOMUtils.clickNode(cvc, "div"); DOMUtils.clickNode(cvc, "div");
waitForMenuToShow(cvc); waitForMenuToShow(webContents);
TouchCommon.singleClickView(getDeleteButton(cvc)); TouchCommon.singleClickView(getDeleteButton(webContents));
CriteriaHelper.pollInstrumentationThread(new Criteria() { CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
try { try {
return DOMUtils.getNodeContents(cvc.getWebContents(), "div").equals(""); return DOMUtils.getNodeContents(webContents, "div").equals("");
} catch (InterruptedException | TimeoutException e) { } catch (InterruptedException | TimeoutException e) {
return false; return false;
} }
} }
}); });
waitForMenuToHide(cvc); waitForMenuToHide(webContents);
} }
@Test @Test
...@@ -89,7 +89,7 @@ public class TextSuggestionMenuTest { ...@@ -89,7 +89,7 @@ public class TextSuggestionMenuTest {
public void testDeleteWordMarkedWithSpellingMarker() public void testDeleteWordMarkedWithSpellingMarker()
throws InterruptedException, Throwable, TimeoutException { throws InterruptedException, Throwable, TimeoutException {
final ContentViewCore cvc = mRule.getContentViewCore(); final ContentViewCore cvc = mRule.getContentViewCore();
WebContents webContents = cvc.getWebContents(); WebContents webContents = mRule.getWebContents();
DOMUtils.focusNode(webContents, "div"); DOMUtils.focusNode(webContents, "div");
...@@ -121,29 +121,29 @@ public class TextSuggestionMenuTest { ...@@ -121,29 +121,29 @@ public class TextSuggestionMenuTest {
+ "internals.setMarker(document, range, 'spelling');"); + "internals.setMarker(document, range, 'spelling');");
DOMUtils.clickNode(cvc, "div"); DOMUtils.clickNode(cvc, "div");
waitForMenuToShow(cvc); waitForMenuToShow(webContents);
TouchCommon.singleClickView(getDeleteButton(cvc)); TouchCommon.singleClickView(getDeleteButton(webContents));
CriteriaHelper.pollInstrumentationThread(new Criteria() { CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
try { try {
return DOMUtils.getNodeContents(cvc.getWebContents(), "div").equals(""); return DOMUtils.getNodeContents(mRule.getWebContents(), "div").equals("");
} catch (InterruptedException | TimeoutException e) { } catch (InterruptedException | TimeoutException e) {
return false; return false;
} }
} }
}); });
waitForMenuToHide(cvc); waitForMenuToHide(webContents);
} }
@Test @Test
@LargeTest @LargeTest
public void testApplySuggestion() throws InterruptedException, Throwable, TimeoutException { public void testApplySuggestion() throws InterruptedException, Throwable, TimeoutException {
final ContentViewCore cvc = mRule.getContentViewCore(); final ContentViewCore cvc = mRule.getContentViewCore();
WebContents webContents = cvc.getWebContents(); WebContents webContents = mRule.getWebContents();
DOMUtils.focusNode(webContents, "div"); DOMUtils.focusNode(webContents, "div");
...@@ -187,27 +187,27 @@ public class TextSuggestionMenuTest { ...@@ -187,27 +187,27 @@ public class TextSuggestionMenuTest {
}); });
DOMUtils.clickNode(cvc, "span"); DOMUtils.clickNode(cvc, "span");
waitForMenuToShow(cvc); waitForMenuToShow(webContents);
// There should be 5 child views: 4 suggestions plus the list footer. // There should be 5 child views: 4 suggestions plus the list footer.
Assert.assertEquals(5, getSuggestionList(cvc).getChildCount()); Assert.assertEquals(5, getSuggestionList(webContents).getChildCount());
Assert.assertEquals( Assert.assertEquals("hello suggestion1",
"hello suggestion1", ((TextView) getSuggestionButton(cvc, 0)).getText().toString()); ((TextView) getSuggestionButton(webContents, 0)).getText().toString());
Assert.assertEquals( Assert.assertEquals("hello suggestion2",
"hello suggestion2", ((TextView) getSuggestionButton(cvc, 1)).getText().toString()); ((TextView) getSuggestionButton(webContents, 1)).getText().toString());
Assert.assertEquals( Assert.assertEquals("suggestion3",
"suggestion3", ((TextView) getSuggestionButton(cvc, 2)).getText().toString()); ((TextView) getSuggestionButton(webContents, 2)).getText().toString());
Assert.assertEquals( Assert.assertEquals("suggestion4",
"suggestion4", ((TextView) getSuggestionButton(cvc, 3)).getText().toString()); ((TextView) getSuggestionButton(webContents, 3)).getText().toString());
TouchCommon.singleClickView(getSuggestionButton(cvc, 2)); TouchCommon.singleClickView(getSuggestionButton(webContents, 2));
CriteriaHelper.pollInstrumentationThread(new Criteria() { CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
try { try {
return DOMUtils.getNodeContents(cvc.getWebContents(), "div") return DOMUtils.getNodeContents(mRule.getWebContents(), "div")
.equals("suggestion3"); .equals("suggestion3");
} catch (InterruptedException | TimeoutException e) { } catch (InterruptedException | TimeoutException e) {
return false; return false;
...@@ -215,7 +215,7 @@ public class TextSuggestionMenuTest { ...@@ -215,7 +215,7 @@ public class TextSuggestionMenuTest {
} }
}); });
waitForMenuToHide(cvc); waitForMenuToHide(webContents);
} }
@Test @Test
...@@ -223,7 +223,7 @@ public class TextSuggestionMenuTest { ...@@ -223,7 +223,7 @@ public class TextSuggestionMenuTest {
public void testApplyMisspellingSuggestion() public void testApplyMisspellingSuggestion()
throws InterruptedException, Throwable, TimeoutException { throws InterruptedException, Throwable, TimeoutException {
final ContentViewCore cvc = mRule.getContentViewCore(); final ContentViewCore cvc = mRule.getContentViewCore();
WebContents webContents = cvc.getWebContents(); WebContents webContents = mRule.getWebContents();
DOMUtils.focusNode(webContents, "div"); DOMUtils.focusNode(webContents, "div");
...@@ -237,21 +237,21 @@ public class TextSuggestionMenuTest { ...@@ -237,21 +237,21 @@ public class TextSuggestionMenuTest {
mRule.commitText(textToCommit, 1); mRule.commitText(textToCommit, 1);
DOMUtils.clickNode(cvc, "span"); DOMUtils.clickNode(cvc, "span");
waitForMenuToShow(cvc); waitForMenuToShow(webContents);
// There should be 2 child views: 1 suggestion plus the list footer. // There should be 2 child views: 1 suggestion plus the list footer.
Assert.assertEquals(2, getSuggestionList(cvc).getChildCount()); Assert.assertEquals(2, getSuggestionList(webContents).getChildCount());
Assert.assertEquals( Assert.assertEquals("replacement",
"replacement", ((TextView) getSuggestionButton(cvc, 0)).getText().toString()); ((TextView) getSuggestionButton(webContents, 0)).getText().toString());
TouchCommon.singleClickView(getSuggestionButton(cvc, 0)); TouchCommon.singleClickView(getSuggestionButton(webContents, 0));
CriteriaHelper.pollInstrumentationThread(new Criteria() { CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
try { try {
return DOMUtils.getNodeContents(cvc.getWebContents(), "div") return DOMUtils.getNodeContents(mRule.getWebContents(), "div")
.equals("replacement"); .equals("replacement");
} catch (InterruptedException | TimeoutException e) { } catch (InterruptedException | TimeoutException e) {
return false; return false;
...@@ -259,7 +259,7 @@ public class TextSuggestionMenuTest { ...@@ -259,7 +259,7 @@ public class TextSuggestionMenuTest {
} }
}); });
waitForMenuToHide(cvc); waitForMenuToHide(webContents);
// Verify that the suggestion marker was replaced. // Verify that the suggestion marker was replaced.
Assert.assertEquals("0", Assert.assertEquals("0",
...@@ -272,7 +272,7 @@ public class TextSuggestionMenuTest { ...@@ -272,7 +272,7 @@ public class TextSuggestionMenuTest {
@LargeTest @LargeTest
public void suggestionMenuDismissal() throws InterruptedException, Throwable, TimeoutException { public void suggestionMenuDismissal() throws InterruptedException, Throwable, TimeoutException {
final ContentViewCore cvc = mRule.getContentViewCore(); final ContentViewCore cvc = mRule.getContentViewCore();
WebContents webContents = cvc.getWebContents(); WebContents webContents = mRule.getWebContents();
DOMUtils.focusNode(webContents, "div"); DOMUtils.focusNode(webContents, "div");
...@@ -283,24 +283,24 @@ public class TextSuggestionMenuTest { ...@@ -283,24 +283,24 @@ public class TextSuggestionMenuTest {
mRule.commitText(textToCommit, 1); mRule.commitText(textToCommit, 1);
DOMUtils.clickNode(cvc, "div"); DOMUtils.clickNode(cvc, "div");
waitForMenuToShow(cvc); waitForMenuToShow(webContents);
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
cvc.getTextSuggestionHostForTesting() TextSuggestionHost.fromWebContents(webContents)
.getTextSuggestionsPopupWindowForTesting() .getTextSuggestionsPopupWindowForTesting()
.dismiss(); .dismiss();
} }
}); });
waitForMenuToHide(cvc); waitForMenuToHide(webContents);
} }
private void waitForMenuToShow(ContentViewCore cvc) { private void waitForMenuToShow(WebContents webContents) {
CriteriaHelper.pollUiThread(new Criteria() { CriteriaHelper.pollUiThread(new Criteria() {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
View deleteButton = getDeleteButton(cvc); View deleteButton = getDeleteButton(webContents);
if (deleteButton == null) { if (deleteButton == null) {
return false; return false;
} }
...@@ -314,32 +314,35 @@ public class TextSuggestionMenuTest { ...@@ -314,32 +314,35 @@ public class TextSuggestionMenuTest {
}); });
} }
private void waitForMenuToHide(ContentViewCore cvc) { private void waitForMenuToHide(WebContents webContents) {
CriteriaHelper.pollUiThread(new Criteria() { CriteriaHelper.pollUiThread(new Criteria() {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
SuggestionsPopupWindow suggestionsPopupWindow = SuggestionsPopupWindow suggestionsPopupWindow =
cvc.getTextSuggestionHostForTesting() TextSuggestionHost.fromWebContents(webContents)
.getTextSuggestionsPopupWindowForTesting(); .getTextSuggestionsPopupWindowForTesting();
SuggestionsPopupWindow spellCheckPopupWindow = SuggestionsPopupWindow spellCheckPopupWindow =
cvc.getTextSuggestionHostForTesting().getSpellCheckPopupWindowForTesting(); TextSuggestionHost.fromWebContents(webContents)
.getSpellCheckPopupWindowForTesting();
return suggestionsPopupWindow == null && spellCheckPopupWindow == null; return suggestionsPopupWindow == null && spellCheckPopupWindow == null;
} }
}); });
} }
private View getContentView(ContentViewCore cvc) { private View getContentView(WebContents webContents) {
SuggestionsPopupWindow suggestionsPopupWindow = SuggestionsPopupWindow suggestionsPopupWindow =
cvc.getTextSuggestionHostForTesting().getTextSuggestionsPopupWindowForTesting(); TextSuggestionHost.fromWebContents(webContents)
.getTextSuggestionsPopupWindowForTesting();
if (suggestionsPopupWindow != null) { if (suggestionsPopupWindow != null) {
return suggestionsPopupWindow.getContentViewForTesting(); return suggestionsPopupWindow.getContentViewForTesting();
} }
SuggestionsPopupWindow spellCheckPopupWindow = SuggestionsPopupWindow spellCheckPopupWindow =
cvc.getTextSuggestionHostForTesting().getSpellCheckPopupWindowForTesting(); TextSuggestionHost.fromWebContents(webContents)
.getSpellCheckPopupWindowForTesting();
if (spellCheckPopupWindow != null) { if (spellCheckPopupWindow != null) {
return spellCheckPopupWindow.getContentViewForTesting(); return spellCheckPopupWindow.getContentViewForTesting();
...@@ -348,17 +351,17 @@ public class TextSuggestionMenuTest { ...@@ -348,17 +351,17 @@ public class TextSuggestionMenuTest {
return null; return null;
} }
private ListView getSuggestionList(ContentViewCore cvc) { private ListView getSuggestionList(WebContents webContents) {
View contentView = getContentView(cvc); View contentView = getContentView(webContents);
return (ListView) contentView.findViewById(R.id.suggestionContainer); return (ListView) contentView.findViewById(R.id.suggestionContainer);
} }
private View getSuggestionButton(ContentViewCore cvc, int suggestionIndex) { private View getSuggestionButton(WebContents webContents, int suggestionIndex) {
return getSuggestionList(cvc).getChildAt(suggestionIndex); return getSuggestionList(webContents).getChildAt(suggestionIndex);
} }
private View getDeleteButton(ContentViewCore cvc) { private View getDeleteButton(WebContents webContents) {
View contentView = getContentView(cvc); View contentView = getContentView(webContents);
if (contentView == null) { if (contentView == null) {
return null; return null;
} }
......
...@@ -13,7 +13,6 @@ import android.view.ViewGroup; ...@@ -13,7 +13,6 @@ import android.view.ViewGroup;
import org.chromium.content.browser.ContentViewCore; import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.ContentViewCore.InternalAccessDelegate; import org.chromium.content.browser.ContentViewCore.InternalAccessDelegate;
import org.chromium.content.browser.input.SelectPopup; import org.chromium.content.browser.input.SelectPopup;
import org.chromium.content.browser.input.TextSuggestionHost;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.ViewAndroidDelegate; import org.chromium.ui.base.ViewAndroidDelegate;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
...@@ -45,14 +44,6 @@ public class TestContentViewCore implements ContentViewCore { ...@@ -45,14 +44,6 @@ public class TestContentViewCore implements ContentViewCore {
return null; return null;
} }
@Override
public TextSuggestionHost getTextSuggestionHostForTesting() {
return null;
}
@Override
public void setTextSuggestionHostForTesting(TextSuggestionHost textSuggestionHost) {}
@Override @Override
public void initialize(ViewAndroidDelegate viewDelegate, public void initialize(ViewAndroidDelegate viewDelegate,
InternalAccessDelegate internalDispatcher, WebContents webContents, InternalAccessDelegate internalDispatcher, WebContents webContents,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment