| 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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" |
| 10 #include "chrome/browser/android/contextualsearch/contextual_search_context.h" | 11 #include "chrome/browser/android/contextualsearch/contextual_search_context.h" |
| 11 #include "components/search_engines/template_url_service.h" | 12 #include "components/search_engines/template_url_service.h" |
| 12 #include "net/url_request/test_url_fetcher_factory.h" | 13 #include "net/url_request/test_url_fetcher_factory.h" |
| 13 #include "net/url_request/url_request_test_util.h" | 14 #include "net/url_request/url_request_test_util.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 17 using base::ListValue; |
| 18 |
| 16 namespace { | 19 namespace { |
| 17 | 20 |
| 18 const char kSomeSpecificBasePage[] = "http://some.specific.host.name.com"; | 21 const char kSomeSpecificBasePage[] = "http://some.specific.host.name.com"; |
| 19 | 22 |
| 20 } // namespace | 23 } // namespace |
| 21 | 24 |
| 22 class ContextualSearchDelegateTest : public testing::Test { | 25 class ContextualSearchDelegateTest : public testing::Test { |
| 23 public: | 26 public: |
| 24 ContextualSearchDelegateTest() {} | 27 ContextualSearchDelegateTest() {} |
| 25 ~ContextualSearchDelegateTest() override {} | 28 ~ContextualSearchDelegateTest() override {} |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 } | 278 } |
| 276 | 279 |
| 277 TEST_F(ContextualSearchDelegateTest, SurroundingTextNoBeforeText) { | 280 TEST_F(ContextualSearchDelegateTest, SurroundingTextNoBeforeText) { |
| 278 base::string16 surrounding = base::ASCIIToUTF16("Bogus ee ff gg"); | 281 base::string16 surrounding = base::ASCIIToUTF16("Bogus ee ff gg"); |
| 279 SetSurroundingContext(surrounding, 0, 5); | 282 SetSurroundingContext(surrounding, 0, 5); |
| 280 delegate_->SendSurroundingText(5); | 283 delegate_->SendSurroundingText(5); |
| 281 EXPECT_EQ("", before_text()); | 284 EXPECT_EQ("", before_text()); |
| 282 EXPECT_EQ("ee f", after_text()); | 285 EXPECT_EQ("ee f", after_text()); |
| 283 } | 286 } |
| 284 | 287 |
| 288 TEST_F(ContextualSearchDelegateTest, ExtractMentionsStartEnd) { |
| 289 ListValue mentions_list; |
| 290 mentions_list.AppendInteger(1); |
| 291 mentions_list.AppendInteger(2); |
| 292 size_t start = 0; |
| 293 size_t end = 0; |
| 294 delegate_->ExtractMentionsStartEnd(mentions_list, &start, &end); |
| 295 EXPECT_EQ(static_cast<size_t>(1), start); |
| 296 EXPECT_EQ(static_cast<size_t>(2), end); |
| 297 } |
| 298 |
| 285 TEST_F(ContextualSearchDelegateTest, SurroundingTextForIcing) { | 299 TEST_F(ContextualSearchDelegateTest, SurroundingTextForIcing) { |
| 286 base::string16 sample = base::ASCIIToUTF16("this is Barack Obama in office."); | 300 base::string16 sample = base::ASCIIToUTF16("this is Barack Obama in office."); |
| 287 int limit_each_side = 3; | 301 int limit_each_side = 3; |
| 288 size_t start = 8; | 302 size_t start = 8; |
| 289 size_t end = 20; | 303 size_t end = 20; |
| 290 base::string16 result = | 304 base::string16 result = |
| 291 delegate_->SurroundingTextForIcing(sample, limit_each_side, &start, &end); | 305 delegate_->SurroundingTextForIcing(sample, limit_each_side, &start, &end); |
| 292 EXPECT_EQ(static_cast<size_t>(3), start); | 306 EXPECT_EQ(static_cast<size_t>(3), start); |
| 293 EXPECT_EQ(static_cast<size_t>(15), end); | 307 EXPECT_EQ(static_cast<size_t>(15), end); |
| 294 EXPECT_EQ(base::ASCIIToUTF16("is Barack Obama in"), result); | 308 EXPECT_EQ(base::ASCIIToUTF16("is Barack Obama in"), result); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 318 std::string alternate_term; | 332 std::string alternate_term; |
| 319 std::string prevent_preload; | 333 std::string prevent_preload; |
| 320 delegate_->DecodeSearchTermsFromJsonResponse(json_with_escape, &search_term, | 334 delegate_->DecodeSearchTermsFromJsonResponse(json_with_escape, &search_term, |
| 321 &display_text, &alternate_term, | 335 &display_text, &alternate_term, |
| 322 &prevent_preload); | 336 &prevent_preload); |
| 323 EXPECT_EQ("obama", search_term); | 337 EXPECT_EQ("obama", search_term); |
| 324 EXPECT_EQ("Barack Obama", display_text); | 338 EXPECT_EQ("Barack Obama", display_text); |
| 325 EXPECT_EQ("barack obama", alternate_term); | 339 EXPECT_EQ("barack obama", alternate_term); |
| 326 EXPECT_EQ("", prevent_preload); | 340 EXPECT_EQ("", prevent_preload); |
| 327 } | 341 } |
| OLD | NEW |