OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "chrome/browser/autocomplete/autocomplete_match.h" | 7 #include "chrome/browser/autocomplete/autocomplete_match.h" |
8 #include "chrome/browser/autocomplete/keyword_provider.h" | 8 #include "chrome/browser/autocomplete/keyword_provider.h" |
| 9 #include "chrome/browser/extensions/extension_omnibox_api.h" |
9 #include "chrome/browser/search_engines/template_url.h" | 10 #include "chrome/browser/search_engines/template_url.h" |
10 #include "chrome/browser/search_engines/template_url_service.h" | 11 #include "chrome/browser/search_engines/template_url_service.h" |
| 12 #include "chrome/common/url_constants.h" |
11 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
12 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
14 | 16 |
15 class KeywordProviderTest : public testing::Test { | 17 class KeywordProviderTest : public testing::Test { |
16 protected: | 18 protected: |
17 template<class ResultType> | 19 template<class ResultType> |
18 struct test_data { | 20 struct test_data { |
19 const string16 input; | 21 const string16 input; |
20 const size_t num_results; | 22 const size_t num_results; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 template_url->set_short_name(ASCIIToUTF16("Test")); | 211 template_url->set_short_name(ASCIIToUTF16("Test")); |
210 model_->Add(template_url); | 212 model_->Add(template_url); |
211 ASSERT_TRUE(template_url == model_->GetTemplateURLForKeyword(keyword)); | 213 ASSERT_TRUE(template_url == model_->GetTemplateURLForKeyword(keyword)); |
212 } | 214 } |
213 | 215 |
214 TEST_F(KeywordProviderTest, RemoveKeyword) { | 216 TEST_F(KeywordProviderTest, RemoveKeyword) { |
215 string16 url(ASCIIToUTF16("http://aaaa/?aaaa=1&b={searchTerms}&c")); | 217 string16 url(ASCIIToUTF16("http://aaaa/?aaaa=1&b={searchTerms}&c")); |
216 model_->Remove(model_->GetTemplateURLForKeyword(ASCIIToUTF16("aaaa"))); | 218 model_->Remove(model_->GetTemplateURLForKeyword(ASCIIToUTF16("aaaa"))); |
217 ASSERT_TRUE(model_->GetTemplateURLForKeyword(ASCIIToUTF16("aaaa")) == NULL); | 219 ASSERT_TRUE(model_->GetTemplateURLForKeyword(ASCIIToUTF16("aaaa")) == NULL); |
218 } | 220 } |
| 221 |
| 222 TEST_F(KeywordProviderTest, SuggestionMatchSanitize) { |
| 223 struct TestData { |
| 224 const char* description; |
| 225 const char* match_contents; |
| 226 } cases[] = { |
| 227 { "Test", "Test" }, |
| 228 { "Test \n Test", "Test Test" }, |
| 229 { "Test\r\t\nTest", "TestTest" }, |
| 230 }; |
| 231 |
| 232 // Register the "Test" keyword to avoid hitting a DCHECK() in |
| 233 // |KeywordProvider::CreateAutocompleteMatch()|. |
| 234 TemplateURL* template_url = new TemplateURL(); |
| 235 string16 keyword(ASCIIToUTF16("test")); |
| 236 std::string url("http://www.example.com/?q={searchTerms}"); |
| 237 template_url->SetURL(url, 0, 0); |
| 238 template_url->set_keyword(keyword); |
| 239 template_url->set_short_name(ASCIIToUTF16("Test")); |
| 240 model_->Add(template_url); |
| 241 |
| 242 AutocompleteInput input(keyword, string16(), |
| 243 true, true, true, AutocompleteInput::BEST_MATCH); |
| 244 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
| 245 ExtensionOmniboxSuggestion suggestion; |
| 246 suggestion.description = ASCIIToUTF16(cases[i].description); |
| 247 AutocompleteMatch match = |
| 248 kw_provider_->CreateAutocompleteMatchFromSuggestion(model_.get(), |
| 249 keyword, |
| 250 input, |
| 251 suggestion, |
| 252 1); |
| 253 EXPECT_EQ(ASCIIToUTF16(cases[i].match_contents), match.contents); |
| 254 } |
| 255 } |
OLD | NEW |