| 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 #include "chrome/browser/android/contextualsearch/contextual_search_delegate.h" | 5 #include "chrome/browser/android/contextualsearch/contextual_search_delegate.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 void CreateDefaultSearchContextAndRequestSearchTerm() { | 83 void CreateDefaultSearchContextAndRequestSearchTerm() { |
| 84 base::string16 surrounding = base::UTF8ToUTF16("Barack Obama just spoke."); | 84 base::string16 surrounding = base::UTF8ToUTF16("Barack Obama just spoke."); |
| 85 CreateSearchContextAndRequestSearchTerm("Barack Obama", surrounding, 0, 6); | 85 CreateSearchContextAndRequestSearchTerm("Barack Obama", surrounding, 0, 6); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void CreateSearchContextAndRequestSearchTerm( | 88 void CreateSearchContextAndRequestSearchTerm( |
| 89 const std::string& selected_text, | 89 const std::string& selected_text, |
| 90 const base::string16& surrounding_text, | 90 const base::string16& surrounding_text, |
| 91 int start_offset, | 91 int start_offset, |
| 92 int end_offset) { | 92 int end_offset) { |
| 93 test_context_ = new ContextualSearchContext( | 93 test_context_ = new ContextualSearchContext(); |
| 94 selected_text, std::string(), GURL(kSomeSpecificBasePage), "utf-8"); | 94 test_context_->SetPropertiesInternal(selected_text, std::string(), true); |
| 95 // ContextualSearchDelegate class takes ownership of the context. | 95 // ContextualSearchDelegate class takes ownership of the context. |
| 96 delegate_->set_context_for_testing(test_context_); | 96 delegate_->set_context_for_testing(test_context_); |
| 97 | 97 |
| 98 test_context_->start_offset = start_offset; | 98 test_context_->start_offset = start_offset; |
| 99 test_context_->end_offset = end_offset; | 99 test_context_->end_offset = end_offset; |
| 100 test_context_->surrounding_text = surrounding_text; | 100 test_context_->surrounding_text = surrounding_text; |
| 101 delegate_->ContinueSearchTermResolutionRequest(); | 101 delegate_->ResolveSearchTermFromContext(); |
| 102 fetcher_ = test_factory_.GetFetcherByID( | 102 fetcher_ = test_factory_.GetFetcherByID( |
| 103 ContextualSearchDelegate::kContextualSearchURLFetcherID); | 103 ContextualSearchDelegate::kContextualSearchURLFetcherID); |
| 104 ASSERT_TRUE(fetcher_); | 104 ASSERT_TRUE(fetcher_); |
| 105 ASSERT_TRUE(fetcher()); | 105 ASSERT_TRUE(fetcher()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Allows using the vertical bar "|" as a quote character, which makes | 108 // Allows using the vertical bar "|" as a quote character, which makes |
| 109 // test cases more readable versus the escaped double quote that is otherwise | 109 // test cases more readable versus the escaped double quote that is otherwise |
| 110 // needed for JSON literals. | 110 // needed for JSON literals. |
| 111 std::string escapeBarQuoted(std::string bar_quoted) { | 111 std::string escapeBarQuoted(std::string bar_quoted) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 138 "\"display_text\":\"Barack Obama\"," | 138 "\"display_text\":\"Barack Obama\"," |
| 139 "\"mentions\":[" + mentions_start + ","+ mentions_end + "]," | 139 "\"mentions\":[" + mentions_start + ","+ mentions_end + "]," |
| 140 "\"selected_text\":\"" + selected_text + "\"," | 140 "\"selected_text\":\"" + selected_text + "\"," |
| 141 "\"resolved_term\":\"barack obama\"}"); | 141 "\"resolved_term\":\"barack obama\"}"); |
| 142 fetcher()->delegate()->OnURLFetchComplete(fetcher()); | 142 fetcher()->delegate()->OnURLFetchComplete(fetcher()); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void SetSurroundingContext(const base::string16& surrounding_text, | 145 void SetSurroundingContext(const base::string16& surrounding_text, |
| 146 int start_offset, | 146 int start_offset, |
| 147 int end_offset) { | 147 int end_offset) { |
| 148 test_context_ = new ContextualSearchContext( | 148 test_context_ = new ContextualSearchContext(); |
| 149 "Bogus", std::string(), GURL(kSomeSpecificBasePage), "utf-8"); | 149 test_context_->SetPropertiesInternal("Bogus", std::string(), true); |
| 150 test_context_->surrounding_text = surrounding_text; | 150 test_context_->surrounding_text = surrounding_text; |
| 151 test_context_->start_offset = start_offset; | 151 test_context_->start_offset = start_offset; |
| 152 test_context_->end_offset = end_offset; | 152 test_context_->end_offset = end_offset; |
| 153 // ContextualSearchDelegate class takes ownership of the context. | 153 // ContextualSearchDelegate class takes ownership of the context. |
| 154 delegate_->set_context_for_testing(test_context_); | 154 delegate_->set_context_for_testing(test_context_); |
| 155 } | 155 } |
| 156 | 156 |
| 157 // Gets the Client Discourse Context proto from the request header. | 157 // Gets the Client Discourse Context proto from the request header. |
| 158 discourse_context::ClientDiscourseContext GetDiscourseContextFromRequest() { | 158 discourse_context::ClientDiscourseContext GetDiscourseContextFromRequest() { |
| 159 discourse_context::ClientDiscourseContext cdc; | 159 discourse_context::ClientDiscourseContext cdc; |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 EXPECT_EQ("", thumbnail_url()); | 596 EXPECT_EQ("", thumbnail_url()); |
| 597 } | 597 } |
| 598 | 598 |
| 599 // Test just the root level thumbnail. | 599 // Test just the root level thumbnail. |
| 600 TEST_F(ContextualSearchDelegateTest, ContextualCardsResponseWithThumbnail) { | 600 TEST_F(ContextualSearchDelegateTest, ContextualCardsResponseWithThumbnail) { |
| 601 CreateDefaultSearchWithAdditionalJsonData( | 601 CreateDefaultSearchWithAdditionalJsonData( |
| 602 ", |thumbnail|:|https://t0.gstatic.com/images?q=tbn:ANd9|"); | 602 ", |thumbnail|:|https://t0.gstatic.com/images?q=tbn:ANd9|"); |
| 603 EXPECT_EQ("", caption()); | 603 EXPECT_EQ("", caption()); |
| 604 EXPECT_EQ("https://t0.gstatic.com/images?q=tbn:ANd9", thumbnail_url()); | 604 EXPECT_EQ("https://t0.gstatic.com/images?q=tbn:ANd9", thumbnail_url()); |
| 605 } | 605 } |
| OLD | NEW |