| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.contextualsearch; | 5 package org.chromium.chrome.browser.contextualsearch; |
| 6 | 6 |
| 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; | 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; |
| 8 | 8 |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.net.Uri; | 10 import android.net.Uri; |
| 11 import android.test.suitebuilder.annotation.SmallTest; | 11 import android.test.suitebuilder.annotation.SmallTest; |
| 12 import android.widget.LinearLayout; | 12 import android.widget.LinearLayout; |
| 13 | 13 |
| 14 import org.chromium.base.test.util.Feature; | 14 import org.chromium.base.test.util.Feature; |
| 15 import org.chromium.base.test.util.Restriction; | 15 import org.chromium.base.test.util.Restriction; |
| 16 import org.chromium.base.test.util.RetryOnFailure; | 16 import org.chromium.base.test.util.RetryOnFailure; |
| 17 import org.chromium.chrome.browser.ChromeActivity; | 17 import org.chromium.chrome.browser.ChromeActivity; |
| 18 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManager; | 18 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManager; |
| 19 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManagerWrapp
er; | 19 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManagerWrapp
er; |
| 20 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchPanel; | 20 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
ualSearchPanel; |
| 21 import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost; | 21 import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost; |
| 22 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EventFilterHos
t; | 22 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EventFilterHos
t; |
| 23 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 23 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
| 24 import org.chromium.content.browser.ContentViewCore; | 24 import org.chromium.content.browser.ContentViewCore; |
| 25 import org.chromium.content.browser.ContextualSearchClient; | 25 import org.chromium.content.browser.ContextualSearchClient; |
| 26 import org.chromium.content.browser.SelectionPopupController; |
| 26 import org.chromium.content_public.browser.WebContents; | 27 import org.chromium.content_public.browser.WebContents; |
| 27 import org.chromium.ui.base.WindowAndroid; | 28 import org.chromium.ui.base.WindowAndroid; |
| 28 import org.chromium.ui.resources.dynamics.DynamicResourceLoader; | 29 import org.chromium.ui.resources.dynamics.DynamicResourceLoader; |
| 29 import org.chromium.ui.touch_selection.SelectionEventType; | 30 import org.chromium.ui.touch_selection.SelectionEventType; |
| 30 | 31 |
| 31 import javax.annotation.Nullable; | 32 import javax.annotation.Nullable; |
| 32 | 33 |
| 33 /** | 34 /** |
| 34 * Mock touch events with Contextual Search to test behavior of its panel and ma
nager. | 35 * Mock touch events with Contextual Search to test behavior of its panel and ma
nager. |
| 35 */ | 36 */ |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 // -------------------------------------------------------------------------
------------------- | 80 // -------------------------------------------------------------------------
------------------- |
| 80 | 81 |
| 81 /** | 82 /** |
| 82 * ContextualSearchManager wrapper that prevents network requests and most n
ative calls. | 83 * ContextualSearchManager wrapper that prevents network requests and most n
ative calls. |
| 83 */ | 84 */ |
| 84 private static class ContextualSearchManagerWrapper extends ContextualSearch
Manager { | 85 private static class ContextualSearchManagerWrapper extends ContextualSearch
Manager { |
| 85 public ContextualSearchManagerWrapper(ChromeActivity activity, | 86 public ContextualSearchManagerWrapper(ChromeActivity activity, |
| 86 WindowAndroid windowAndroid) { | 87 WindowAndroid windowAndroid) { |
| 87 super(activity, windowAndroid, null); | 88 super(activity, windowAndroid, null); |
| 88 setSelectionController(new MockCSSelectionController(activity, this)
); | 89 setSelectionController(new MockCSSelectionController(activity, this)
); |
| 89 getSelectionController().getBaseContentView().setContextualSearchCli
ent(this); | 90 ContentViewCore contentView = getSelectionController().getBaseConten
tView(); |
| 91 contentView.setSelectionPopupControllerForTesting( |
| 92 new SelectionPopupController(activity, null, null, null, |
| 93 contentView.getRenderCoordinates(), null)); |
| 94 contentView.setContextualSearchClient(this); |
| 90 MockContextualSearchPolicy policy = new MockContextualSearchPolicy(a
ctivity); | 95 MockContextualSearchPolicy policy = new MockContextualSearchPolicy(a
ctivity); |
| 91 setContextualSearchPolicy(policy); | 96 setContextualSearchPolicy(policy); |
| 92 mTranslateController = new MockedCSTranslateController(activity, pol
icy, null); | 97 mTranslateController = new MockedCSTranslateController(activity, pol
icy, null); |
| 93 } | 98 } |
| 94 | 99 |
| 95 @Override | 100 @Override |
| 96 public void startSearchTermResolutionRequest(String selection) { | 101 public void startSearchTermResolutionRequest(String selection) { |
| 97 // Skip native calls and immediately "resolve" the search term. | 102 // Skip native calls and immediately "resolve" the search term. |
| 98 onSearchTermResolutionResponse( | 103 onSearchTermResolutionResponse( |
| 99 true, 200, selection, selection, "", "", false, 0, 10, "", "
", "", "", | 104 true, 200, selection, selection, "", "", false, 0, 10, "", "
", "", "", |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 .equals("text")); | 257 .equals("text")); |
| 253 | 258 |
| 254 // Fake tap on non-text. | 259 // Fake tap on non-text. |
| 255 mockTapEmptySpace(); | 260 mockTapEmptySpace(); |
| 256 | 261 |
| 257 assertTrue(mPanelManager.getRequestPanelShowCount() == 1); | 262 assertTrue(mPanelManager.getRequestPanelShowCount() == 1); |
| 258 assertTrue(mPanelManager.getPanelHideCount() == 1); | 263 assertTrue(mPanelManager.getPanelHideCount() == 1); |
| 259 assertTrue(mContextualSearchManager.getSelectionController().getSelected
Text() == null); | 264 assertTrue(mContextualSearchManager.getSelectionController().getSelected
Text() == null); |
| 260 } | 265 } |
| 261 } | 266 } |
| OLD | NEW |