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

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

Issue 23621037: Send URLs on non-zero prefix suggest requests also. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move set_current_page_url Created 7 years, 3 months 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
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/command_line.h" 6 #include "base/command_line.h"
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 EXPECT_TRUE(url.url_ref().IsValid()); 570 EXPECT_TRUE(url.url_ref().IsValid());
571 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 571 ASSERT_TRUE(url.url_ref().SupportsReplacement());
572 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term); 572 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term);
573 search_terms_args.cursor_position = test_data[i].cursor_position; 573 search_terms_args.cursor_position = test_data[i].cursor_position;
574 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args)); 574 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args));
575 ASSERT_TRUE(result.is_valid()); 575 ASSERT_TRUE(result.is_valid());
576 EXPECT_EQ(test_data[i].expected_result, result.spec()); 576 EXPECT_EQ(test_data[i].expected_result, result.spec());
577 } 577 }
578 } 578 }
579 579
580 // Tests replacing zeroPrefixUrl. 580 // Tests replacing currentPageUrl.
581 TEST_F(TemplateURLTest, ReplaceZeroPrefixUrl) { 581 TEST_F(TemplateURLTest, ReplaceCurrentPageUrl) {
582 struct TestData { 582 struct TestData {
583 const string16 search_term; 583 const string16 search_term;
584 const std::string zero_prefix_url; 584 const std::string current_page_url;
585 const std::string url; 585 const std::string url;
586 const std::string expected_result; 586 const std::string expected_result;
587 } test_data[] = { 587 } test_data[] = {
588 { ASCIIToUTF16("foo"), 588 { ASCIIToUTF16("foo"),
589 "http://www.google.com/", 589 "http://www.google.com/",
590 "{google:baseURL}?{searchTerms}&{google:zeroPrefixUrl}", 590 "{google:baseURL}?{searchTerms}&{google:currentPageUrl}",
591 "http://www.google.com/?foo&url=http%3A%2F%2Fwww.google.com%2F&" }, 591 "http://www.google.com/?foo&url=http%3A%2F%2Fwww.google.com%2F&" },
592 { ASCIIToUTF16("foo"), 592 { ASCIIToUTF16("foo"),
593 "", 593 "",
594 "{google:baseURL}?{searchTerms}&{google:zeroPrefixUrl}", 594 "{google:baseURL}?{searchTerms}&{google:currentPageUrl}",
595 "http://www.google.com/?foo&" }, 595 "http://www.google.com/?foo&" },
596 { ASCIIToUTF16("foo"), 596 { ASCIIToUTF16("foo"),
597 "http://g.com/+-/*&=", 597 "http://g.com/+-/*&=",
598 "{google:baseURL}?{searchTerms}&{google:zeroPrefixUrl}", 598 "{google:baseURL}?{searchTerms}&{google:currentPageUrl}",
599 "http://www.google.com/?foo&url=http%3A%2F%2Fg.com%2F%2B-%2F*%26%3D&" }, 599 "http://www.google.com/?foo&url=http%3A%2F%2Fg.com%2F%2B-%2F*%26%3D&" },
600 }; 600 };
601 TemplateURLData data; 601 TemplateURLData data;
602 data.input_encodings.push_back("UTF-8"); 602 data.input_encodings.push_back("UTF-8");
603 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 603 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
604 data.SetURL(test_data[i].url); 604 data.SetURL(test_data[i].url);
605 TemplateURL url(NULL, data); 605 TemplateURL url(NULL, data);
606 EXPECT_TRUE(url.url_ref().IsValid()); 606 EXPECT_TRUE(url.url_ref().IsValid());
607 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 607 ASSERT_TRUE(url.url_ref().SupportsReplacement());
608 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term); 608 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term);
609 search_terms_args.zero_prefix_url = test_data[i].zero_prefix_url; 609 search_terms_args.current_page_url = test_data[i].current_page_url;
610 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args)); 610 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args));
611 ASSERT_TRUE(result.is_valid()); 611 ASSERT_TRUE(result.is_valid());
612 EXPECT_EQ(test_data[i].expected_result, result.spec()); 612 EXPECT_EQ(test_data[i].expected_result, result.spec());
613 } 613 }
614 } 614 }
615 615
616 TEST_F(TemplateURLTest, Suggestions) { 616 TEST_F(TemplateURLTest, Suggestions) {
617 struct TestData { 617 struct TestData {
618 const int accepted_suggestion; 618 const int accepted_suggestion;
619 const string16 original_query_for_suggestion; 619 const string16 original_query_for_suggestion;
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 { "http://bar/", false, }, 1226 { "http://bar/", false, },
1227 { "http://foo/", false, }, 1227 { "http://foo/", false, },
1228 { "http://bar/newtab", false, }, 1228 { "http://bar/newtab", false, },
1229 }; 1229 };
1230 1230
1231 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(url_data); ++i) { 1231 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(url_data); ++i) {
1232 EXPECT_EQ(url_data[i].result, 1232 EXPECT_EQ(url_data[i].result,
1233 search_provider.IsSearchURL(GURL(url_data[i].url))); 1233 search_provider.IsSearchURL(GURL(url_data[i].url)));
1234 } 1234 }
1235 } 1235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698