Chromium Code Reviews| 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.base.test.util.Restriction.RESTRICTION_TYPE_PHONE; | 8 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_PHONE; |
| 9 import static org.chromium.content.browser.test.util.CriteriaHelper.DEFAULT_POLL ING_INTERVAL; | 9 import static org.chromium.content.browser.test.util.CriteriaHelper.DEFAULT_POLL ING_INTERVAL; |
| 10 | 10 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 private final class FakeResponseOnMainThread implements Runnable { | 261 private final class FakeResponseOnMainThread implements Runnable { |
| 262 | 262 |
| 263 private final boolean mIsNetworkUnavailable; | 263 private final boolean mIsNetworkUnavailable; |
| 264 private final int mResponseCode; | 264 private final int mResponseCode; |
| 265 private final String mSearchTerm; | 265 private final String mSearchTerm; |
| 266 private final String mDisplayText; | 266 private final String mDisplayText; |
| 267 private final String mAlternateTerm; | 267 private final String mAlternateTerm; |
| 268 private final boolean mDoPreventPreload; | 268 private final boolean mDoPreventPreload; |
| 269 private final int mStartAdjust; | 269 private final int mStartAdjust; |
| 270 private final int mEndAdjust; | 270 private final int mEndAdjust; |
| 271 private final String mContextLanguage; | |
| 271 | 272 |
| 272 public FakeResponseOnMainThread(boolean isNetworkUnavailable, int respon seCode, | 273 public FakeResponseOnMainThread(boolean isNetworkUnavailable, int respon seCode, |
| 273 String searchTerm, String displayText, S tring alternateTerm, | 274 String searchTerm, String displayText, S tring alternateTerm, |
| 274 boolean doPreventPreload, int startAdjus t, int endAdjudst) { | 275 boolean doPreventPreload, int startAdjus t, int endAdjudst, |
| 276 String contextLanguage) { | |
| 275 mIsNetworkUnavailable = isNetworkUnavailable; | 277 mIsNetworkUnavailable = isNetworkUnavailable; |
| 276 mResponseCode = responseCode; | 278 mResponseCode = responseCode; |
| 277 mSearchTerm = searchTerm; | 279 mSearchTerm = searchTerm; |
| 278 mDisplayText = displayText; | 280 mDisplayText = displayText; |
| 279 mAlternateTerm = alternateTerm; | 281 mAlternateTerm = alternateTerm; |
| 280 mDoPreventPreload = doPreventPreload; | 282 mDoPreventPreload = doPreventPreload; |
| 281 mStartAdjust = startAdjust; | 283 mStartAdjust = startAdjust; |
| 282 mEndAdjust = endAdjudst; | 284 mEndAdjust = endAdjudst; |
| 285 mContextLanguage = contextLanguage; | |
| 283 } | 286 } |
| 284 | 287 |
| 285 @Override | 288 @Override |
| 286 public void run() { | 289 public void run() { |
| 287 mFakeServer.handleSearchTermResolutionResponse( | 290 mFakeServer.handleSearchTermResolutionResponse(mIsNetworkUnavailable , mResponseCode, |
| 288 mIsNetworkUnavailable, mResponseCode, mSearchTerm, mDisplayT ext, | 291 mSearchTerm, mDisplayText, mAlternateTerm, mDoPreventPreload , mStartAdjust, |
| 289 mAlternateTerm, mDoPreventPreload, mStartAdjust, mEndAdjust) ; | 292 mEndAdjust, mContextLanguage); |
| 290 } | 293 } |
| 291 } | 294 } |
| 292 | 295 |
| 293 /** | 296 /** |
| 294 * Fakes a server response with the parameters given and startAdjust and end Adjust equal to 0. | 297 * Fakes a server response with the parameters given and startAdjust and end Adjust equal to 0. |
| 295 * {@See ContextualSearchManager#handleSearchTermResolutionResponse}. | 298 * {@See ContextualSearchManager#handleSearchTermResolutionResponse}. |
| 296 */ | 299 */ |
| 297 private void fakeResponse(boolean isNetworkUnavailable, int responseCode, | 300 private void fakeResponse(boolean isNetworkUnavailable, int responseCode, |
| 298 String searchTerm, String displayText, String alternateTerm, boolean doPreventPreload) { | 301 String searchTerm, String displayText, String alternateTerm, boolean doPreventPreload) { |
| 299 fakeResponse(isNetworkUnavailable, responseCode, searchTerm, displayText , alternateTerm, | 302 fakeResponse(isNetworkUnavailable, responseCode, searchTerm, displayText , alternateTerm, |
| 300 doPreventPreload, 0, 0); | 303 doPreventPreload, 0, 0, ""); |
| 301 } | 304 } |
| 302 | 305 |
| 303 /** | 306 /** |
| 304 * Fakes a server response with the parameters given. | 307 * Fakes a server response with the parameters given. |
| 305 * {@See ContextualSearchManager#handleSearchTermResolutionResponse}. | 308 * {@See ContextualSearchManager#handleSearchTermResolutionResponse}. |
| 306 */ | 309 */ |
| 307 private void fakeResponse(boolean isNetworkUnavailable, int responseCode, | 310 private void fakeResponse(boolean isNetworkUnavailable, int responseCode, St ring searchTerm, |
| 308 String searchTerm, String displayText, String alternateTerm, boolean doPreventPreload, | 311 String displayText, String alternateTerm, boolean doPreventPreload, int startAdjust, |
| 309 int startAdjust, int endAdjust) { | 312 int endAdjust, String contextLanguage) { |
| 310 if (mFakeServer.getSearchTermRequested() != null) { | 313 if (mFakeServer.getSearchTermRequested() != null) { |
| 311 getInstrumentation().runOnMainSync( | 314 getInstrumentation().runOnMainSync(new FakeResponseOnMainThread(isNe tworkUnavailable, |
| 312 new FakeResponseOnMainThread(isNetworkUnavailable, responseC ode, searchTerm, | 315 responseCode, searchTerm, displayText, alternateTerm, doPrev entPreload, |
| 313 displayText, alternateTerm, doPreventPreload, startA djust, endAdjust)); | 316 startAdjust, endAdjust, contextLanguage)); |
| 314 } | 317 } |
| 315 } | 318 } |
| 316 | 319 |
| 317 //========================================================================== ================== | 320 //========================================================================== ================== |
| 318 // Content Helpers | 321 // Content Helpers |
| 319 //========================================================================== ================== | 322 //========================================================================== ================== |
| 320 | 323 |
| 321 /** | 324 /** |
| 322 * @return The Panel's ContentViewCore. | 325 * @return The Panel's ContentViewCore. |
| 323 */ | 326 */ |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 private String getSelectedText() { | 445 private String getSelectedText() { |
| 443 return mSelectionController.getSelectedText(); | 446 return mSelectionController.getSelectedText(); |
| 444 } | 447 } |
| 445 | 448 |
| 446 /** | 449 /** |
| 447 * Asserts that the loaded search term matches the provided value. | 450 * Asserts that the loaded search term matches the provided value. |
| 448 * @param searchTerm The provided search term. | 451 * @param searchTerm The provided search term. |
| 449 */ | 452 */ |
| 450 private void assertLoadedSearchTermMatches(String searchTerm) { | 453 private void assertLoadedSearchTermMatches(String searchTerm) { |
| 451 boolean doesMatch = false; | 454 boolean doesMatch = false; |
| 455 String message = "but there was no loaded URL!"; | |
| 452 if (mFakeServer != null) { | 456 if (mFakeServer != null) { |
| 453 doesMatch = mFakeServer.getLoadedUrl().contains("q=" + searchTerm); | 457 doesMatch = mFakeServer.getLoadedUrl().contains("q=" + searchTerm); |
| 458 // TODO(donnd): remove the following line once the Translate API is updated! | |
| 459 doesMatch = doesMatch || mFakeServer.getLoadedUrl().contains("tlitet xt=" + searchTerm); | |
|
pedro (no code reviews)
2015/11/05 02:09:58
Nit: Please add a comment explaining what is happe
Donn Denman
2015/11/05 17:51:08
Done.
| |
| 460 message = "in URL: " + mFakeServer.getLoadedUrl(); | |
| 454 } | 461 } |
| 455 assertTrue(doesMatch); | 462 assertTrue("Expected to find searchTerm " + searchTerm + ", " + message, doesMatch); |
| 456 } | 463 } |
| 457 | 464 |
| 458 private void assertContainsParameters(String searchTerm, String alternateTer m) { | 465 private void assertContainsParameters(String searchTerm, String alternateTer m) { |
| 459 assertTrue(mFakeServer == null || mFakeServer.getSearchTermRequested() = = null | 466 assertTrue(mFakeServer == null || mFakeServer.getSearchTermRequested() = = null |
| 460 || mFakeServer.getLoadedUrl().contains(searchTerm) | 467 || mFakeServer.getLoadedUrl().contains(searchTerm) |
| 461 && mFakeServer.getLoadedUrl().contains(alternateTerm)); | 468 && mFakeServer.getLoadedUrl().contains(alternateTerm)); |
| 462 } | 469 } |
| 463 | 470 |
| 464 private void assertContainsNoParameters() { | 471 private void assertContainsNoParameters() { |
| 465 assertTrue(mFakeServer == null || mFakeServer.getLoadedUrl() == null); | 472 assertTrue(mFakeServer == null || mFakeServer.getLoadedUrl() == null); |
| (...skipping 1693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2159 @SmallTest | 2166 @SmallTest |
| 2160 @Feature({"ContextualSearch"}) | 2167 @Feature({"ContextualSearch"}) |
| 2161 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 2168 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 2162 public void testSelectionExpansionOnSearchTermResolution() | 2169 public void testSelectionExpansionOnSearchTermResolution() |
| 2163 throws InterruptedException, TimeoutException { | 2170 throws InterruptedException, TimeoutException { |
| 2164 mFakeServer.reset(); | 2171 mFakeServer.reset(); |
| 2165 clickWordNode("intelligence"); | 2172 clickWordNode("intelligence"); |
| 2166 waitForPanelToPeekAndAssert(); | 2173 waitForPanelToPeekAndAssert(); |
| 2167 | 2174 |
| 2168 fakeResponse(false, 200, "Intelligence", "United States Intelligence", " alternate-term", | 2175 fakeResponse(false, 200, "Intelligence", "United States Intelligence", " alternate-term", |
| 2169 false, -14, 0); | 2176 false, -14, 0, ""); |
| 2170 waitForSelectionToBe("United States Intelligence"); | 2177 waitForSelectionToBe("United States Intelligence"); |
| 2171 } | 2178 } |
| 2172 | 2179 |
| 2173 /** | 2180 /** |
| 2174 * Tests that long-press triggers the Peek Promo, and expanding the Panel di smisses it. | 2181 * Tests that long-press triggers the Peek Promo, and expanding the Panel di smisses it. |
| 2175 * | 2182 * |
| 2176 * Re-enable the test after fixing http://crbug.com/540820. | 2183 * Re-enable the test after fixing http://crbug.com/540820. |
| 2177 * @SmallTest | 2184 * @SmallTest |
| 2178 * @Feature({"ContextualSearch"}) | 2185 * @Feature({"ContextualSearch"}) |
| 2179 */ | 2186 */ |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2403 | 2410 |
| 2404 // Close the Panel without seeing any Content. | 2411 // Close the Panel without seeing any Content. |
| 2405 tapBasePageToClosePanel(); | 2412 tapBasePageToClosePanel(); |
| 2406 | 2413 |
| 2407 // Now check that all three URLs have been removed from history. | 2414 // Now check that all three URLs have been removed from history. |
| 2408 assertEquals(3, mFakeServer.getLoadedUrlCount()); | 2415 assertEquals(3, mFakeServer.getLoadedUrlCount()); |
| 2409 assertTrue(mFakeServer.hasRemovedUrl(url1)); | 2416 assertTrue(mFakeServer.hasRemovedUrl(url1)); |
| 2410 assertTrue(mFakeServer.hasRemovedUrl(url2)); | 2417 assertTrue(mFakeServer.hasRemovedUrl(url2)); |
| 2411 assertTrue(mFakeServer.hasRemovedUrl(url3)); | 2418 assertTrue(mFakeServer.hasRemovedUrl(url3)); |
| 2412 } | 2419 } |
| 2420 | |
| 2421 /** | |
| 2422 * Tests that a simple Tap with language determination triggers translation. | |
| 2423 */ | |
| 2424 @SmallTest | |
| 2425 @Feature({"ContextualSearch"}) | |
| 2426 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | |
| 2427 @CommandLineFlags.Add(ContextualSearchFieldTrial.TRANSLATION_ONEBOX_ENABLED + "=true") | |
| 2428 public void testTapWithLanguage() throws InterruptedException, TimeoutExcept ion { | |
| 2429 // Tapping a german word should trigger translation. | |
| 2430 simulateTapSearch("german"); | |
| 2431 | |
| 2432 // Make sure we tried to trigger translate. | |
| 2433 assertTrue(mManager.getRequest().isTranslationForced()); | |
| 2434 } | |
| 2435 | |
| 2436 /** | |
| 2437 * Tests that a simple Tap without language determination does not trigger t ranslation. | |
| 2438 */ | |
| 2439 @SmallTest | |
| 2440 @Feature({"ContextualSearch"}) | |
| 2441 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | |
| 2442 @CommandLineFlags.Add(ContextualSearchFieldTrial.TRANSLATION_ONEBOX_ENABLED + "=true") | |
| 2443 public void testTapWithoutLanguage() throws InterruptedException, TimeoutExc eption { | |
| 2444 // Tapping an English word should NOT trigger translation. | |
| 2445 simulateTapSearch("search"); | |
| 2446 | |
| 2447 // Make sure we did not try to trigger translate. | |
| 2448 assertFalse(mManager.getRequest().isTranslationForced()); | |
| 2449 } | |
| 2413 } | 2450 } |
| OLD | NEW |