| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 import static org.chromium.content.browser.test.util.CriteriaHelper.DEFAULT_POLL
ING_INTERVAL; | 8 import static org.chromium.content.browser.test.util.CriteriaHelper.DEFAULT_POLL
ING_INTERVAL; |
| 9 | 9 |
| 10 import android.app.Activity; | 10 import android.app.Activity; |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 private final boolean mIsNetworkUnavailable; | 324 private final boolean mIsNetworkUnavailable; |
| 325 private final int mResponseCode; | 325 private final int mResponseCode; |
| 326 private final String mSearchTerm; | 326 private final String mSearchTerm; |
| 327 private final String mDisplayText; | 327 private final String mDisplayText; |
| 328 private final String mAlternateTerm; | 328 private final String mAlternateTerm; |
| 329 private final String mMid; | 329 private final String mMid; |
| 330 private final boolean mDoPreventPreload; | 330 private final boolean mDoPreventPreload; |
| 331 private final int mStartAdjust; | 331 private final int mStartAdjust; |
| 332 private final int mEndAdjust; | 332 private final int mEndAdjust; |
| 333 private final String mContextLanguage; | 333 private final String mContextLanguage; |
| 334 private final String mThumbnailUrl; |
| 334 | 335 |
| 335 public FakeResponseOnMainThread(boolean isNetworkUnavailable, int respon
seCode, | 336 public FakeResponseOnMainThread(boolean isNetworkUnavailable, int respon
seCode, |
| 336 String searchTerm, String displayText, String alternateTerm, Str
ing mid, | 337 String searchTerm, String displayText, String alternateTerm, Str
ing mid, |
| 337 boolean doPreventPreload, int startAdjust, int endAdjudst, Strin
g contextLanguage) { | 338 boolean doPreventPreload, int startAdjust, int endAdjudst, Strin
g contextLanguage, |
| 339 String thumbnailUrl) { |
| 338 mIsNetworkUnavailable = isNetworkUnavailable; | 340 mIsNetworkUnavailable = isNetworkUnavailable; |
| 339 mResponseCode = responseCode; | 341 mResponseCode = responseCode; |
| 340 mSearchTerm = searchTerm; | 342 mSearchTerm = searchTerm; |
| 341 mDisplayText = displayText; | 343 mDisplayText = displayText; |
| 342 mAlternateTerm = alternateTerm; | 344 mAlternateTerm = alternateTerm; |
| 343 mMid = mid; | 345 mMid = mid; |
| 344 mDoPreventPreload = doPreventPreload; | 346 mDoPreventPreload = doPreventPreload; |
| 345 mStartAdjust = startAdjust; | 347 mStartAdjust = startAdjust; |
| 346 mEndAdjust = endAdjudst; | 348 mEndAdjust = endAdjudst; |
| 347 mContextLanguage = contextLanguage; | 349 mContextLanguage = contextLanguage; |
| 350 mThumbnailUrl = thumbnailUrl; |
| 348 } | 351 } |
| 349 | 352 |
| 350 @Override | 353 @Override |
| 351 public void run() { | 354 public void run() { |
| 352 mFakeServer.handleSearchTermResolutionResponse(mIsNetworkUnavailable
, mResponseCode, | 355 mFakeServer.handleSearchTermResolutionResponse(mIsNetworkUnavailable
, mResponseCode, |
| 353 mSearchTerm, mDisplayText, mAlternateTerm, mMid, mDoPreventP
reload, | 356 mSearchTerm, mDisplayText, mAlternateTerm, mMid, mDoPreventP
reload, |
| 354 mStartAdjust, mEndAdjust, mContextLanguage); | 357 mStartAdjust, mEndAdjust, mContextLanguage, mThumbnailUrl); |
| 355 } | 358 } |
| 356 } | 359 } |
| 357 | 360 |
| 358 /** | 361 /** |
| 359 * Fakes a server response with the parameters given and startAdjust and end
Adjust equal to 0. | 362 * Fakes a server response with the parameters given and startAdjust and end
Adjust equal to 0. |
| 360 * {@See ContextualSearchManager#handleSearchTermResolutionResponse}. | 363 * {@See ContextualSearchManager#handleSearchTermResolutionResponse}. |
| 361 */ | 364 */ |
| 362 private void fakeResponse(boolean isNetworkUnavailable, int responseCode, | 365 private void fakeResponse(boolean isNetworkUnavailable, int responseCode, |
| 363 String searchTerm, String displayText, String alternateTerm, boolean
doPreventPreload) { | 366 String searchTerm, String displayText, String alternateTerm, boolean
doPreventPreload) { |
| 364 fakeResponse(isNetworkUnavailable, responseCode, searchTerm, displayText
, alternateTerm, | 367 fakeResponse(isNetworkUnavailable, responseCode, searchTerm, displayText
, alternateTerm, |
| 365 null, doPreventPreload, 0, 0, ""); | 368 null, doPreventPreload, 0, 0, "", ""); |
| 366 } | 369 } |
| 367 | 370 |
| 368 /** | 371 /** |
| 369 * Fakes a server response with the parameters given. | 372 * Fakes a server response with the parameters given. |
| 370 * {@See ContextualSearchManager#handleSearchTermResolutionResponse}. | 373 * {@See ContextualSearchManager#handleSearchTermResolutionResponse}. |
| 371 */ | 374 */ |
| 372 private void fakeResponse(boolean isNetworkUnavailable, int responseCode, St
ring searchTerm, | 375 private void fakeResponse(boolean isNetworkUnavailable, int responseCode, St
ring searchTerm, |
| 373 String displayText, String alternateTerm, String mid, boolean doPrev
entPreload, | 376 String displayText, String alternateTerm, String mid, boolean doPrev
entPreload, |
| 374 int startAdjust, int endAdjust, String contextLanguage) { | 377 int startAdjust, int endAdjust, String contextLanguage, String thumb
nailUrl) { |
| 375 if (mFakeServer.getSearchTermRequested() != null) { | 378 if (mFakeServer.getSearchTermRequested() != null) { |
| 376 getInstrumentation().runOnMainSync(new FakeResponseOnMainThread(isNe
tworkUnavailable, | 379 getInstrumentation().runOnMainSync(new FakeResponseOnMainThread(isNe
tworkUnavailable, |
| 377 responseCode, searchTerm, displayText, alternateTerm, mid, d
oPreventPreload, | 380 responseCode, searchTerm, displayText, alternateTerm, mid, d
oPreventPreload, |
| 378 startAdjust, endAdjust, contextLanguage)); | 381 startAdjust, endAdjust, contextLanguage, thumbnailUrl)); |
| 379 } | 382 } |
| 380 } | 383 } |
| 381 | 384 |
| 382 //==========================================================================
================== | 385 //==========================================================================
================== |
| 383 // Content Helpers | 386 // Content Helpers |
| 384 //==========================================================================
================== | 387 //==========================================================================
================== |
| 385 | 388 |
| 386 /** | 389 /** |
| 387 * @return The Panel's ContentViewCore. | 390 * @return The Panel's ContentViewCore. |
| 388 */ | 391 */ |
| (...skipping 1690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2079 @SmallTest | 2082 @SmallTest |
| 2080 @Feature({"ContextualSearch"}) | 2083 @Feature({"ContextualSearch"}) |
| 2081 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 2084 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 2082 public void testSelectionExpansionOnSearchTermResolution() | 2085 public void testSelectionExpansionOnSearchTermResolution() |
| 2083 throws InterruptedException, TimeoutException { | 2086 throws InterruptedException, TimeoutException { |
| 2084 mFakeServer.reset(); | 2087 mFakeServer.reset(); |
| 2085 clickWordNode("intelligence"); | 2088 clickWordNode("intelligence"); |
| 2086 waitForPanelToPeek(); | 2089 waitForPanelToPeek(); |
| 2087 | 2090 |
| 2088 fakeResponse(false, 200, "Intelligence", "United States Intelligence", "
alternate-term", | 2091 fakeResponse(false, 200, "Intelligence", "United States Intelligence", "
alternate-term", |
| 2089 null, false, -14, 0, ""); | 2092 null, false, -14, 0, "", ""); |
| 2090 waitForSelectionToBe("United States Intelligence"); | 2093 waitForSelectionToBe("United States Intelligence"); |
| 2091 } | 2094 } |
| 2092 | 2095 |
| 2093 /** | 2096 /** |
| 2094 * Tests that long-press triggers the Peek Promo, and expanding the Panel di
smisses it. | 2097 * Tests that long-press triggers the Peek Promo, and expanding the Panel di
smisses it. |
| 2095 */ | 2098 */ |
| 2096 @SmallTest | 2099 @SmallTest |
| 2097 @Feature({"ContextualSearch"}) | 2100 @Feature({"ContextualSearch"}) |
| 2098 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) | 2101 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) |
| 2099 @CommandLineFlags.Add(ContextualSearchFieldTrial.PEEK_PROMO_ENABLED + "=true
") | 2102 @CommandLineFlags.Add(ContextualSearchFieldTrial.PEEK_PROMO_ENABLED + "=true
") |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2593 // Simulate a tap and assert that the panel peeks. | 2596 // Simulate a tap and assert that the panel peeks. |
| 2594 simulateTapSearch("search"); | 2597 simulateTapSearch("search"); |
| 2595 | 2598 |
| 2596 // Toggle tab to non-fullscreen. | 2599 // Toggle tab to non-fullscreen. |
| 2597 FullscreenTestUtils.togglePersistentFullscreenAndAssert(tab, false, getA
ctivity()); | 2600 FullscreenTestUtils.togglePersistentFullscreenAndAssert(tab, false, getA
ctivity()); |
| 2598 | 2601 |
| 2599 // Assert that the panel is closed. | 2602 // Assert that the panel is closed. |
| 2600 waitForPanelToClose(); | 2603 waitForPanelToClose(); |
| 2601 } | 2604 } |
| 2602 } | 2605 } |
| OLD | NEW |