| Index: chrome/android/javatests/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchTapEventTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchTapEventTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchTapEventTest.java
|
| index cecd71ac51fde4ce91c1820dae3a06551b7c3d16..91283287b53f293a2667d6ba5b5059ee809ee5d3 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchTapEventTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchTapEventTest.java
|
| @@ -5,6 +5,9 @@
|
| package org.chromium.chrome.browser.contextualsearch;
|
|
|
| import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE;
|
| +import static org.hamcrest.CoreMatchers.equalTo;
|
| +import static org.hamcrest.CoreMatchers.is;
|
| +import static org.junit.Assert.assertThat;
|
|
|
| import android.content.Context;
|
| import android.net.Uri;
|
| @@ -19,12 +22,14 @@ import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManager;
|
| import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManagerWrapper;
|
| import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.ContextualSearchPanel;
|
| import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost;
|
| +import org.chromium.chrome.browser.contextualsearch.ContextualSearchInternalStateController.InternalState;
|
| import org.chromium.chrome.test.ChromeActivityTestCaseBase;
|
| import org.chromium.content.browser.ContentViewCore;
|
| import org.chromium.content.browser.SelectionClient;
|
| import org.chromium.content.browser.SelectionPopupController;
|
| +import org.chromium.content.browser.test.util.Criteria;
|
| +import org.chromium.content.browser.test.util.CriteriaHelper;
|
| import org.chromium.content_public.browser.WebContents;
|
| -import org.chromium.ui.base.WindowAndroid;
|
| import org.chromium.ui.resources.dynamics.DynamicResourceLoader;
|
| import org.chromium.ui.touch_selection.SelectionEventType;
|
|
|
| @@ -41,7 +46,7 @@ public class ContextualSearchTapEventTest extends ChromeActivityTestCaseBase<Chr
|
| private SelectionClient mContextualSearchClient;
|
|
|
| /**
|
| - * A ContextualSearchRequest that forgoes URI template lookup.
|
| + * A ContextualSearchRequest that foregoes URI template lookup.
|
| */
|
| private static class MockContextualSearchRequest extends ContextualSearchRequest {
|
| public MockContextualSearchRequest(String term, String altTerm, boolean prefetch) {
|
| @@ -82,9 +87,8 @@ public class ContextualSearchTapEventTest extends ChromeActivityTestCaseBase<Chr
|
| * ContextualSearchManager wrapper that prevents network requests and most native calls.
|
| */
|
| private static class ContextualSearchManagerWrapper extends ContextualSearchManager {
|
| - public ContextualSearchManagerWrapper(ChromeActivity activity,
|
| - WindowAndroid windowAndroid) {
|
| - super(activity, windowAndroid, null);
|
| + public ContextualSearchManagerWrapper(ChromeActivity activity) {
|
| + super(activity, null);
|
| setSelectionController(new MockCSSelectionController(activity, this));
|
| ContentViewCore contentView = getSelectionController().getBaseContentView();
|
| contentView.setSelectionPopupControllerForTesting(new SelectionPopupController(
|
| @@ -93,6 +97,7 @@ public class ContextualSearchTapEventTest extends ChromeActivityTestCaseBase<Chr
|
| MockContextualSearchPolicy policy = new MockContextualSearchPolicy();
|
| setContextualSearchPolicy(policy);
|
| mTranslateController = new MockedCSTranslateController(activity, policy, null);
|
| + setContextualSearchInternalStateController(makeNewStateControllerWrapper(this));
|
| }
|
|
|
| @Override
|
| @@ -188,12 +193,38 @@ public class ContextualSearchTapEventTest extends ChromeActivityTestCaseBase<Chr
|
| }
|
| }
|
|
|
| + private static final class InternalStateControllerWrapper
|
| + extends ContextualSearchInternalStateController {
|
| + /**
|
| + * @param selectionController
|
| + * @param policy
|
| + * @param handler
|
| + */
|
| + InternalStateControllerWrapper(
|
| + ContextualSearchPolicy policy, ContextualSearchInternalStateHandler handler) {
|
| + super(policy, handler);
|
| + // TODO(donnd): Auto-generated constructor stub
|
| + }
|
| +
|
| + @Override
|
| + void notifyStartingWorkOn(InternalState state) {
|
| + System.out.println("ctxs started work on state " + state);
|
| + super.notifyStartingWorkOn(state);
|
| + }
|
| + }
|
| +
|
| + private static ContextualSearchInternalStateController makeNewStateControllerWrapper(
|
| + ContextualSearchManager manager) {
|
| + return new InternalStateControllerWrapper(manager.getContextualSearchPolicy(),
|
| + manager.getContextualSearchInternalStateHandler());
|
| + }
|
| +
|
| // --------------------------------------------------------------------------------------------
|
|
|
| /**
|
| * Trigger text selection on the contextual search manager.
|
| */
|
| - private void mockTapText(String text) {
|
| + private void mockLongpressText(String text) {
|
| mContextualSearchManager.getBaseContentView().setSelectedText(text);
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| @@ -205,6 +236,19 @@ public class ContextualSearchTapEventTest extends ChromeActivityTestCaseBase<Chr
|
| }
|
|
|
| /**
|
| + * Trigger text selection on the contextual search manager.
|
| + */
|
| + private void mockTapText(String text) {
|
| + mContextualSearchManager.getBaseContentView().setSelectedText(text);
|
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + mContextualSearchClient.showUnhandledTapUIIfNeeded(0, 0);
|
| + }
|
| + });
|
| + }
|
| +
|
| + /**
|
| * Trigger empty space tap.
|
| */
|
| private void mockTapEmptySpace() {
|
| @@ -237,8 +281,7 @@ public class ContextualSearchTapEventTest extends ChromeActivityTestCaseBase<Chr
|
| mPanelManager.setContainerView(new LinearLayout(activity));
|
| mPanelManager.setDynamicResourceLoader(new DynamicResourceLoader(0, null));
|
|
|
| - mContextualSearchManager =
|
| - new ContextualSearchManagerWrapper(activity, activity.getWindowAndroid());
|
| + mContextualSearchManager = new ContextualSearchManagerWrapper(activity);
|
| mPanel = new ContextualSearchPanelWrapper(activity, null, mPanelManager);
|
| mPanel.setManagementDelegate(mContextualSearchManager);
|
| mContextualSearchManager.setContextualSearchPanel(mPanel);
|
| @@ -253,6 +296,53 @@ public class ContextualSearchTapEventTest extends ChromeActivityTestCaseBase<Chr
|
| startMainActivityWithURL("about:blank");
|
| }
|
|
|
| + private void waitForPanelToShow() {
|
| + CriteriaHelper.pollInstrumentationThread(new Criteria() {
|
| + @Override
|
| + public boolean isSatisfied() {
|
| + return mPanel.isShowing();
|
| + }
|
| + });
|
| + }
|
| +
|
| + private void waitForPanelToHide() {
|
| + final int oldHideCount = mPanelManager.getPanelHideCount();
|
| + CriteriaHelper.pollInstrumentationThread(new Criteria() {
|
| + @Override
|
| + public boolean isSatisfied() {
|
| + // It might take a while for the hide to actually happen.
|
| + return !mPanel.isShowing() && oldHideCount < mPanelManager.getPanelHideCount();
|
| + }
|
| + });
|
| + }
|
| +
|
| + /**
|
| + * Tests that a Tap gesture followed by tapping empty space closes the panel.
|
| + */
|
| + @SmallTest
|
| + @Feature({"ContextualSearch"})
|
| + @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| + public void testLongpressFollowedByNonTextTap() {
|
| + assertTrue(mPanelManager.getRequestPanelShowCount() == 0);
|
| +
|
| + // Fake a selection event.
|
| + mockLongpressText("text");
|
| + // waitForPanelToShow();
|
| +
|
| + assertThat(mPanelManager.getRequestPanelShowCount(), is(1));
|
| + assertThat(mPanelManager.getPanelHideCount(), is(0));
|
| + assertThat(mContextualSearchManager.getSelectionController().getSelectedText(),
|
| + equalTo("text"));
|
| +
|
| + // Fake tap on non-text.
|
| + mockTapEmptySpace();
|
| + // waitForPanelToHide();
|
| +
|
| + assertThat(mPanelManager.getRequestPanelShowCount(), is(1));
|
| + assertThat(mPanelManager.getPanelHideCount(), is(1));
|
| + assertNull(mContextualSearchManager.getSelectionController().getSelectedText());
|
| + }
|
| +
|
| /**
|
| * Tests that a Tap gesture followed by tapping empty space closes the panel.
|
| */
|
| @@ -264,17 +354,19 @@ public class ContextualSearchTapEventTest extends ChromeActivityTestCaseBase<Chr
|
|
|
| // Fake a selection event.
|
| mockTapText("text");
|
| + // waitForPanelToShow();
|
|
|
| - assertTrue(mPanelManager.getRequestPanelShowCount() == 1);
|
| - assertTrue(mPanelManager.getPanelHideCount() == 0);
|
| - assertTrue(mContextualSearchManager.getSelectionController().getSelectedText()
|
| - .equals("text"));
|
| + assertThat(mPanelManager.getRequestPanelShowCount(), is(1));
|
| + assertThat(mPanelManager.getPanelHideCount(), is(0));
|
| + assertThat(mContextualSearchManager.getSelectionController().getSelectedText(),
|
| + equalTo("text"));
|
|
|
| // Fake tap on non-text.
|
| mockTapEmptySpace();
|
| + // waitForPanelToHide();
|
|
|
| - assertTrue(mPanelManager.getRequestPanelShowCount() == 1);
|
| - assertTrue(mPanelManager.getPanelHideCount() == 1);
|
| - assertTrue(mContextualSearchManager.getSelectionController().getSelectedText() == null);
|
| + assertThat(mPanelManager.getRequestPanelShowCount(), is(1));
|
| + assertThat(mPanelManager.getPanelHideCount(), is(1));
|
| + assertNull(mContextualSearchManager.getSelectionController().getSelectedText());
|
| }
|
| }
|
|
|