| OLD | NEW |
| 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/search_engines/template_url.h" | 9 #include "chrome/browser/search_engines/template_url.h" |
| 10 #include "chrome/browser/search_engines/template_url_parser.h" | 10 #include "chrome/browser/search_engines/template_url_parser.h" |
| 11 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 // ParamFilterImpl ------------------------------------------------------------ | 14 // ParamFilterImpl ------------------------------------------------------------ |
| 15 | 15 |
| 16 // Filters any param which as an occurrence of name_str_ in its name or an | 16 // Filters any param which as an occurrence of name_str_ in its name or an |
| 17 // occurrence of value_str_ in its value. | 17 // occurrence of value_str_ in its value. |
| 18 class ParamFilterImpl : public TemplateURLParser::ParameterFilter { | 18 class ParamFilterImpl : public TemplateURLParser::ParameterFilter { |
| 19 public: | 19 public: |
| 20 ParamFilterImpl(std::string name_str, std::string value_str); | 20 ParamFilterImpl(std::string name_str, std::string value_str); |
| 21 ~ParamFilterImpl(); | 21 virtual ~ParamFilterImpl(); |
| 22 | 22 |
| 23 virtual bool KeepParameter(const std::string& key, | 23 virtual bool KeepParameter(const std::string& key, |
| 24 const std::string& value) OVERRIDE; | 24 const std::string& value) OVERRIDE; |
| 25 | 25 |
| 26 private: | 26 private: |
| 27 std::string name_str_; | 27 std::string name_str_; |
| 28 std::string value_str_; | 28 std::string value_str_; |
| 29 | 29 |
| 30 DISALLOW_COPY_AND_ASSIGN(ParamFilterImpl); | 30 DISALLOW_COPY_AND_ASSIGN(ParamFilterImpl); |
| 31 }; | 31 }; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 43 return (name_str_.empty() || key.find(name_str_) == std::string::npos) && | 43 return (name_str_.empty() || key.find(name_str_) == std::string::npos) && |
| 44 (value_str_.empty() || value.find(value_str_) == std::string::npos); | 44 (value_str_.empty() || value.find(value_str_) == std::string::npos); |
| 45 } | 45 } |
| 46 | 46 |
| 47 | 47 |
| 48 // TemplateURLParserTest ------------------------------------------------------ | 48 // TemplateURLParserTest ------------------------------------------------------ |
| 49 | 49 |
| 50 class TemplateURLParserTest : public testing::Test { | 50 class TemplateURLParserTest : public testing::Test { |
| 51 protected: | 51 protected: |
| 52 TemplateURLParserTest(); | 52 TemplateURLParserTest(); |
| 53 ~TemplateURLParserTest(); | 53 virtual ~TemplateURLParserTest(); |
| 54 | 54 |
| 55 virtual void SetUp() OVERRIDE; | 55 virtual void SetUp() OVERRIDE; |
| 56 | 56 |
| 57 bool is_disabled() const; | 57 bool is_disabled() const; |
| 58 | 58 |
| 59 // Parses the OpenSearch description document at file_name (relative to the | 59 // Parses the OpenSearch description document at file_name (relative to the |
| 60 // data dir). The TemplateURL is placed in |template_url_|. | 60 // data dir). The TemplateURL is placed in |template_url_|. |
| 61 void ParseFile(const std::string& file_name, | 61 void ParseFile(const std::string& file_name, |
| 62 TemplateURLParser::ParameterFilter* filter); | 62 TemplateURLParser::ParameterFilter* filter); |
| 63 | 63 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 EXPECT_EQ(ASCIIToUTF16("Yahoo"), template_url_->short_name()); | 250 EXPECT_EQ(ASCIIToUTF16("Yahoo"), template_url_->short_name()); |
| 251 EXPECT_TRUE(template_url_->url_ref().SupportsReplacement()); | 251 EXPECT_TRUE(template_url_->url_ref().SupportsReplacement()); |
| 252 EXPECT_TRUE(template_url_->suggestions_url().empty()); | 252 EXPECT_TRUE(template_url_->suggestions_url().empty()); |
| 253 EXPECT_EQ("http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8", | 253 EXPECT_EQ("http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8", |
| 254 template_url_->url()); | 254 template_url_->url()); |
| 255 ASSERT_EQ(1U, template_url_->input_encodings().size()); | 255 ASSERT_EQ(1U, template_url_->input_encodings().size()); |
| 256 EXPECT_EQ("UTF-8", template_url_->input_encodings()[0]); | 256 EXPECT_EQ("UTF-8", template_url_->input_encodings()[0]); |
| 257 EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"), | 257 EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"), |
| 258 template_url_->favicon_url()); | 258 template_url_->favicon_url()); |
| 259 } | 259 } |
| OLD | NEW |