| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 selected_text, std::string(), GURL(kSomeSpecificBasePage), "utf-8"); |
| 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_->SetSelectionSurroundings(start_offset, end_offset, |
| 99 test_context_->end_offset = end_offset; | 99 surrounding_text); |
| 100 test_context_->surrounding_text = surrounding_text; | 100 delegate_->ResolveSearchTermFromContext(); |
| 101 delegate_->ContinueSearchTermResolutionRequest(); | |
| 102 fetcher_ = test_factory_.GetFetcherByID( | 101 fetcher_ = test_factory_.GetFetcherByID( |
| 103 ContextualSearchDelegate::kContextualSearchURLFetcherID); | 102 ContextualSearchDelegate::kContextualSearchURLFetcherID); |
| 104 ASSERT_TRUE(fetcher_); | 103 ASSERT_TRUE(fetcher_); |
| 105 ASSERT_TRUE(fetcher()); | 104 ASSERT_TRUE(fetcher()); |
| 106 } | 105 } |
| 107 | 106 |
| 108 // Allows using the vertical bar "|" as a quote character, which makes | 107 // Allows using the vertical bar "|" as a quote character, which makes |
| 109 // test cases more readable versus the escaped double quote that is otherwise | 108 // test cases more readable versus the escaped double quote that is otherwise |
| 110 // needed for JSON literals. | 109 // needed for JSON literals. |
| 111 std::string escapeBarQuoted(std::string bar_quoted) { | 110 std::string escapeBarQuoted(std::string bar_quoted) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 140 "\"selected_text\":\"" + selected_text + "\"," | 139 "\"selected_text\":\"" + selected_text + "\"," |
| 141 "\"resolved_term\":\"barack obama\"}"); | 140 "\"resolved_term\":\"barack obama\"}"); |
| 142 fetcher()->delegate()->OnURLFetchComplete(fetcher()); | 141 fetcher()->delegate()->OnURLFetchComplete(fetcher()); |
| 143 } | 142 } |
| 144 | 143 |
| 145 void SetSurroundingContext(const base::string16& surrounding_text, | 144 void SetSurroundingContext(const base::string16& surrounding_text, |
| 146 int start_offset, | 145 int start_offset, |
| 147 int end_offset) { | 146 int end_offset) { |
| 148 test_context_ = new ContextualSearchContext( | 147 test_context_ = new ContextualSearchContext( |
| 149 "Bogus", std::string(), GURL(kSomeSpecificBasePage), "utf-8"); | 148 "Bogus", std::string(), GURL(kSomeSpecificBasePage), "utf-8"); |
| 150 test_context_->surrounding_text = surrounding_text; | 149 test_context_->SetSelectionSurroundings(start_offset, end_offset, |
| 151 test_context_->start_offset = start_offset; | 150 surrounding_text); |
| 152 test_context_->end_offset = end_offset; | |
| 153 // ContextualSearchDelegate class takes ownership of the context. | 151 // ContextualSearchDelegate class takes ownership of the context. |
| 154 delegate_->set_context_for_testing(test_context_); | 152 delegate_->set_context_for_testing(test_context_); |
| 155 } | 153 } |
| 156 | 154 |
| 157 // Gets the Client Discourse Context proto from the request header. | 155 // Gets the Client Discourse Context proto from the request header. |
| 158 discourse_context::ClientDiscourseContext GetDiscourseContextFromRequest() { | 156 discourse_context::ClientDiscourseContext GetDiscourseContextFromRequest() { |
| 159 discourse_context::ClientDiscourseContext cdc; | 157 discourse_context::ClientDiscourseContext cdc; |
| 160 // Make sure we can get the actual raw headers from the fake fetcher. | 158 // Make sure we can get the actual raw headers from the fake fetcher. |
| 161 net::HttpRequestHeaders fetch_headers; | 159 net::HttpRequestHeaders fetch_headers; |
| 162 fetcher()->GetExtraRequestHeaders(&fetch_headers); | 160 fetcher()->GetExtraRequestHeaders(&fetch_headers); |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 EXPECT_EQ("", thumbnail_url()); | 594 EXPECT_EQ("", thumbnail_url()); |
| 597 } | 595 } |
| 598 | 596 |
| 599 // Test just the root level thumbnail. | 597 // Test just the root level thumbnail. |
| 600 TEST_F(ContextualSearchDelegateTest, ContextualCardsResponseWithThumbnail) { | 598 TEST_F(ContextualSearchDelegateTest, ContextualCardsResponseWithThumbnail) { |
| 601 CreateDefaultSearchWithAdditionalJsonData( | 599 CreateDefaultSearchWithAdditionalJsonData( |
| 602 ", |thumbnail|:|https://t0.gstatic.com/images?q=tbn:ANd9|"); | 600 ", |thumbnail|:|https://t0.gstatic.com/images?q=tbn:ANd9|"); |
| 603 EXPECT_EQ("", caption()); | 601 EXPECT_EQ("", caption()); |
| 604 EXPECT_EQ("https://t0.gstatic.com/images?q=tbn:ANd9", thumbnail_url()); | 602 EXPECT_EQ("https://t0.gstatic.com/images?q=tbn:ANd9", thumbnail_url()); |
| 605 } | 603 } |
| OLD | NEW |