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

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

Issue 314773002: Omnibox: Send Input Type to Suggest Server (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix (legitimate) clang error Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/search_engines/template_url.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/autocomplete/autocomplete_input.h"
10 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/rlz/rlz.h" 12 #include "chrome/browser/rlz/rlz.h"
12 #include "chrome/browser/search_engines/search_terms_data.h" 13 #include "chrome/browser/search_engines/search_terms_data.h"
13 #include "chrome/browser/search_engines/template_url.h" 14 #include "chrome/browser/search_engines/template_url.h"
14 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "components/metrics/proto/omnibox_input_type.pb.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 18
17 #if defined(ENABLE_RLZ) 19 #if defined(ENABLE_RLZ)
18 #include "chrome/browser/google/google_brand.h" 20 #include "chrome/browser/google/google_brand.h"
19 #endif 21 #endif
20 22
21 #if defined(OS_ANDROID) 23 #if defined(OS_ANDROID)
22 #include "chrome/browser/search_engines/search_terms_data_android.h" 24 #include "chrome/browser/search_engines/search_terms_data_android.h"
23 #endif 25 #endif
24 26
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 EXPECT_TRUE(url.url_ref().IsValid()); 575 EXPECT_TRUE(url.url_ref().IsValid());
574 ASSERT_TRUE(url.url_ref().SupportsReplacement()); 576 ASSERT_TRUE(url.url_ref().SupportsReplacement());
575 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term); 577 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term);
576 search_terms_args.cursor_position = test_data[i].cursor_position; 578 search_terms_args.cursor_position = test_data[i].cursor_position;
577 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args)); 579 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args));
578 ASSERT_TRUE(result.is_valid()); 580 ASSERT_TRUE(result.is_valid());
579 EXPECT_EQ(test_data[i].expected_result, result.spec()); 581 EXPECT_EQ(test_data[i].expected_result, result.spec());
580 } 582 }
581 } 583 }
582 584
585 // Tests replacing input type (&oit=).
586 TEST_F(TemplateURLTest, ReplaceInputType) {
587 struct TestData {
588 const base::string16 search_term;
589 AutocompleteInput::Type input_type;
590 const std::string url;
591 const std::string expected_result;
592 } test_data[] = {
593 { ASCIIToUTF16("foo"),
594 metrics::OmniboxInputType::UNKNOWN,
595 "{google:baseURL}?{searchTerms}&{google:inputType}",
596 "http://www.google.com/?foo&oit=1&" },
597 { ASCIIToUTF16("foo"),
598 metrics::OmniboxInputType::URL,
599 "{google:baseURL}?{searchTerms}&{google:inputType}",
600 "http://www.google.com/?foo&oit=3&" },
601 { ASCIIToUTF16("foo"),
602 metrics::OmniboxInputType::FORCED_QUERY,
603 "{google:baseURL}?{searchTerms}&{google:inputType}",
604 "http://www.google.com/?foo&oit=5&" },
605 };
606 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.google.com/");
607 TemplateURLData data;
608 data.input_encodings.push_back("UTF-8");
609 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
610 data.SetURL(test_data[i].url);
611 TemplateURL url(NULL, data);
612 EXPECT_TRUE(url.url_ref().IsValid());
613 ASSERT_TRUE(url.url_ref().SupportsReplacement());
614 TemplateURLRef::SearchTermsArgs search_terms_args(test_data[i].search_term);
615 search_terms_args.input_type = test_data[i].input_type;
616 GURL result(url.url_ref().ReplaceSearchTerms(search_terms_args));
617 ASSERT_TRUE(result.is_valid());
618 EXPECT_EQ(test_data[i].expected_result, result.spec());
619 }
620 }
621
583 // Tests replacing currentPageUrl. 622 // Tests replacing currentPageUrl.
584 TEST_F(TemplateURLTest, ReplaceCurrentPageUrl) { 623 TEST_F(TemplateURLTest, ReplaceCurrentPageUrl) {
585 struct TestData { 624 struct TestData {
586 const base::string16 search_term; 625 const base::string16 search_term;
587 const std::string current_page_url; 626 const std::string current_page_url;
588 const std::string url; 627 const std::string url;
589 const std::string expected_result; 628 const std::string expected_result;
590 } test_data[] = { 629 } test_data[] = {
591 { ASCIIToUTF16("foo"), 630 { ASCIIToUTF16("foo"),
592 "http://www.google.com/", 631 "http://www.google.com/",
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo")); 1389 TemplateURLRef::SearchTermsArgs search_terms_args(ASCIIToUTF16("foo"));
1351 search_terms_args.session_token = "SESSIONTOKENGOESHERE"; 1390 search_terms_args.session_token = "SESSIONTOKENGOESHERE";
1352 std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args); 1391 std::string result = url.url_ref().ReplaceSearchTerms(search_terms_args);
1353 EXPECT_EQ("http://bar/search?q=foo&psi=SESSIONTOKENGOESHERE&xssi=t", result); 1392 EXPECT_EQ("http://bar/search?q=foo&psi=SESSIONTOKENGOESHERE&xssi=t", result);
1354 1393
1355 TemplateURL url2(NULL, data); 1394 TemplateURL url2(NULL, data);
1356 search_terms_args.session_token = ""; 1395 search_terms_args.session_token = "";
1357 result = url.url_ref().ReplaceSearchTerms(search_terms_args); 1396 result = url.url_ref().ReplaceSearchTerms(search_terms_args);
1358 EXPECT_EQ("http://bar/search?q=foo&xssi=t", result); 1397 EXPECT_EQ("http://bar/search?q=foo&xssi=t", result);
1359 } 1398 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698