Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(415)

Side by Side Diff: chrome/browser/search_engines/template_url_unittest.cc

Issue 11414303: Make Google Search autocomplete provider cursor aware. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/base_paths.h" 5 #include "base/base_paths.h"
6 #include "base/string_util.h" 6 #include "base/string_util.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/rlz/rlz.h" 9 #include "chrome/browser/rlz/rlz.h"
10 #include "chrome/browser/search_engines/search_terms_data.h" 10 #include "chrome/browser/search_engines/search_terms_data.h"
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 428 ASSERT_TRUE(url.url_ref().SupportsReplacement());
429 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term); 429 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term);
430 search_terms_args.assisted_query_stats = test_data[i].aqs; 430 search_terms_args.assisted_query_stats = test_data[i].aqs;
431 UIThreadSearchTermsData::SetGoogleBaseURL(test_data[i].base_url); 431 UIThreadSearchTermsData::SetGoogleBaseURL(test_data[i].base_url);
432 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args)); 432 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args));
433 ASSERT_TRUE(result.is_valid()); 433 ASSERT_TRUE(result.is_valid());
434 EXPECT_EQ(test_data[i].expected_result, result.spec()); 434 EXPECT_EQ(test_data[i].expected_result, result.spec());
435 } 435 }
436 } 436 }
437 437
438 // Tests replacing cursor position.
439 TEST_F(TemplateURLTest, ReplaceCursorPosition) {
440 struct TestData {
441 const string16 search_term;
442 size_t cursor_position;
443 const std::string url;
444 const std::string expected_result;
445 } test_data[] = {
446 { ASCIIToUTF16("foo"),
447 string16::npos,
448 "{google:baseURL}?{searchTerms}&{google:cursorPosition}",
449 "http://www.google.com/?foo&" },
450 { ASCIIToUTF16("foo"),
451 2,
452 "{google:baseURL}?{searchTerms}&{google:cursorPosition}",
453 "http://www.google.com/?foo&cp=2&" },
454 { ASCIIToUTF16("foo"),
455 15,
456 "{google:baseURL}?{searchTerms}&{google:cursorPosition}",
457 "http://www.google.com/?foo&cp=15&" },
458 };
459 TemplateURLData data;
460 data.input_encodings.push_back("UTF-8");
461 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
462 data.SetURL(test_data[i].url);
463 TemplateURL url(NULL, data);
464 EXPECT_TRUE(url.url_ref().IsValid());
465 ASSERT_TRUE(url.url_ref().SupportsReplacement());
466 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term);
467 search_terms_args.cursor_position = test_data[i].cursor_position;
468 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args));
469 ASSERT_TRUE(result.is_valid());
470 EXPECT_EQ(test_data[i].expected_result, result.spec());
471 }
472 }
473
438 TEST_F(TemplateURLTest, Suggestions) { 474 TEST_F(TemplateURLTest, Suggestions) {
439 struct TestData { 475 struct TestData {
440 const int accepted_suggestion; 476 const int accepted_suggestion;
441 const string16 original_query_for_suggestion; 477 const string16 original_query_for_suggestion;
442 const std::string expected_result; 478 const std::string expected_result;
443 } test_data[] = { 479 } test_data[] = {
444 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(), 480 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(),
445 "http://bar/foo?aq=f&q=foobar" }, 481 "http://bar/foo?aq=f&q=foobar" },
446 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"), 482 { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"),
447 "http://bar/foo?aq=f&q=foobar" }, 483 "http://bar/foo?aq=f&q=foobar" },
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 EXPECT_EQ(string16(), result); 805 EXPECT_EQ(string16(), result);
770 806
771 EXPECT_FALSE(url.ExtractSearchTermsFromURL( 807 EXPECT_FALSE(url.ExtractSearchTermsFromURL(
772 GURL("http://google.com/alt/?q=123#q="), &result)); 808 GURL("http://google.com/alt/?q=123#q="), &result));
773 EXPECT_EQ(string16(), result); 809 EXPECT_EQ(string16(), result);
774 810
775 EXPECT_TRUE(url.ExtractSearchTermsFromURL( 811 EXPECT_TRUE(url.ExtractSearchTermsFromURL(
776 GURL("http://google.com/alt/?q=#q=123"), &result)); 812 GURL("http://google.com/alt/?q=#q=123"), &result));
777 EXPECT_EQ(ASCIIToUTF16("123"), result); 813 EXPECT_EQ(ASCIIToUTF16("123"), result);
778 } 814 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698