Index: chrome/browser/autocomplete/keyword_provider_unittest.cc |
=================================================================== |
--- chrome/browser/autocomplete/keyword_provider_unittest.cc (revision 107110) |
+++ chrome/browser/autocomplete/keyword_provider_unittest.cc (working copy) |
@@ -6,8 +6,10 @@ |
#include "base/utf_string_conversions.h" |
#include "chrome/browser/autocomplete/autocomplete_match.h" |
#include "chrome/browser/autocomplete/keyword_provider.h" |
+#include "chrome/browser/extensions/extension_omnibox_api.h" |
#include "chrome/browser/search_engines/template_url.h" |
#include "chrome/browser/search_engines/template_url_service.h" |
+#include "chrome/common/url_constants.h" |
#include "chrome/test/base/testing_browser_process.h" |
#include "googleurl/src/gurl.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -216,3 +218,38 @@ |
model_->Remove(model_->GetTemplateURLForKeyword(ASCIIToUTF16("aaaa"))); |
ASSERT_TRUE(model_->GetTemplateURLForKeyword(ASCIIToUTF16("aaaa")) == NULL); |
} |
+ |
+TEST_F(KeywordProviderTest, SuggestionMatchSanitize) { |
+ struct TestData { |
+ const char* description; |
+ const char* match_contents; |
+ } cases[] = { |
+ { "Test", "Test" }, |
+ { "Test \n Test", "Test Test" }, |
+ { "Test\r\t\nTest", "TestTest" }, |
+ }; |
+ |
+ // Register the "Test" keyword to avoid hitting a DCHECK() in |
+ // |KeywordProvider::CreateAutocompleteMatch()|. |
+ TemplateURL* template_url = new TemplateURL(); |
+ string16 keyword(ASCIIToUTF16("test")); |
+ std::string url("http://www.example.com/?q={searchTerms}"); |
+ template_url->SetURL(url, 0, 0); |
+ template_url->set_keyword(keyword); |
+ template_url->set_short_name(ASCIIToUTF16("Test")); |
+ model_->Add(template_url); |
+ |
+ AutocompleteInput input(keyword, ASCIIToUTF16(""), |
+ true, true, true, AutocompleteInput::BEST_MATCH); |
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
+ ExtensionOmniboxSuggestion suggestion; |
+ suggestion.description = ASCIIToUTF16(cases[i].description); |
+ AutocompleteMatch match = |
+ kw_provider_->CreateAutocompleteMatchFromSuggestion(model_.get(), |
+ keyword, |
+ input, |
+ suggestion, |
+ 1); |
+ EXPECT_EQ(ASCIIToUTF16(cases[i].match_contents), match.contents); |
+ } |
+} |