Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/FakeNowOnTapResults.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/FakeNowOnTapResults.java b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/FakeNowOnTapResults.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..18aa7ffcf7d3b9b5bacea61512e9450284762d21 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/FakeNowOnTapResults.java |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
|
Theresa
2016/09/20 19:51:39
s/2015/2016
Donn Denman
2016/09/20 21:16:36
Doh!
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.contextualsearch; |
| + |
| +import android.text.TextUtils; |
| +import android.util.Pair; |
| + |
| +import org.chromium.base.CommandLine; |
| + |
| +import java.util.HashMap; |
| + |
| +/** |
| + * Returns fake Now on Tap results for captions and thumbnails to make testing easier until |
| + * the server returns real data. |
| + * TODO(donnd): remove this throw-away code! |
|
Theresa
2016/09/20 19:51:39
The server code is getting close, right? How long
Donn Denman
2016/09/20 21:16:36
Great idea, I'll hopefully use this in the future!
|
| + */ |
| +class FakeNowOnTapResults { |
| + private static final String CONTEXTUAL_SEARCH_CAPTION = "contextual-search-caption"; |
| + private static final String CONTEXTUAL_SEARCH_THUMBNAIL = "contextual-search-thumbnail"; |
| + |
| + private final HashMap<String, Pair<String, String>> mMap; |
| + |
| + private boolean mIsEnabled; |
| + private String mSearchTerm; |
| + |
| + FakeNowOnTapResults() { |
| + mIsEnabled = ContextualSearchFieldTrial.isNowOnTapBarIntegrationEnabled(); |
| + mMap = new HashMap<String, Pair<String, String>>(); |
| + Pair<String, String> obamaData = Pair.create("44th U.S. President", |
| + "https://t2.gstatic.com/images?q=tbn:ANd9GcQDVqhlepIBWJpJwhlgfDF4FRwZvWfqe72sCdHKj4y-7_fAg_cW"); |
| + mMap.put("Obama", obamaData); |
| + mMap.put("Barack Obama", obamaData); |
| + } |
| + |
| + String fakeThumbnail(String thumbnailUrl, String searchTerm) { |
| + mSearchTerm = null; |
| + if (mIsEnabled && TextUtils.isEmpty(thumbnailUrl)) { |
| + mSearchTerm = searchTerm; |
| + thumbnailUrl = lookupThumbnailFor(mSearchTerm, thumbnailUrl); |
| + } |
| + return thumbnailUrl; |
| + } |
| + |
| + String fakeCaption(String caption) { |
| + if (mIsEnabled && TextUtils.isEmpty(caption) && mSearchTerm != null) { |
| + caption = lookupCaptionFor(mSearchTerm, caption); |
| + } |
| + return caption; |
| + } |
| + |
| + private String lookupCaptionFor(String searchTerm, String caption) { |
| + String result = caption; |
| + if (CommandLine.getInstance().hasSwitch(CONTEXTUAL_SEARCH_CAPTION)) { |
| + result = CommandLine.getInstance().getSwitchValue(CONTEXTUAL_SEARCH_CAPTION); |
| + } else if (mMap.containsKey(searchTerm)) { |
| + result = mMap.get(searchTerm).first; |
| + } |
| + return result; |
| + } |
| + |
| + private String lookupThumbnailFor(String searchTerm, String thumbnail) { |
| + String result = thumbnail; |
| + if (CommandLine.getInstance().hasSwitch(CONTEXTUAL_SEARCH_THUMBNAIL)) { |
| + result = CommandLine.getInstance().getSwitchValue(CONTEXTUAL_SEARCH_THUMBNAIL); |
| + } else if (mMap.containsKey(searchTerm)) { |
| + result = mMap.get(searchTerm).second; |
| + } |
| + return result; |
| + } |
| +} |