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/search_engines/template_url.h" | 9 #include "chrome/browser/search_engines/template_url.h" |
10 #include "chrome/browser/search_engines/template_url_service.h" | 10 #include "chrome/browser/search_engines/template_url_service.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 virtual ~KeywordProviderTest() { } | 25 virtual ~KeywordProviderTest() { } |
26 | 26 |
27 virtual void SetUp(); | 27 virtual void SetUp(); |
28 virtual void TearDown(); | 28 virtual void TearDown(); |
29 | 29 |
30 template<class ResultType> | 30 template<class ResultType> |
31 void RunTest(test_data<ResultType>* keyword_cases, | 31 void RunTest(test_data<ResultType>* keyword_cases, |
32 int num_cases, | 32 int num_cases, |
33 ResultType AutocompleteMatch::* member); | 33 ResultType AutocompleteMatch::* member); |
34 | 34 |
35 void RunTest(const char* input, const char* keyword); | |
Peter Kasting
2011/12/15 22:56:04
I'd prefer not to add a function with the same nam
| |
36 | |
35 protected: | 37 protected: |
36 scoped_refptr<KeywordProvider> kw_provider_; | 38 scoped_refptr<KeywordProvider> kw_provider_; |
37 scoped_ptr<TemplateURLService> model_; | 39 scoped_ptr<TemplateURLService> model_; |
38 }; | 40 }; |
39 | 41 |
40 void KeywordProviderTest::SetUp() { | 42 void KeywordProviderTest::SetUp() { |
41 static const TemplateURLService::Initializer kTestKeywordData[] = { | 43 static const TemplateURLService::Initializer kTestKeywordData[] = { |
42 { "aa", "aa.com?foo=%s", "aa" }, | 44 { "aa", "aa.com?foo=%s", "aa" }, |
43 { "aaaa", "http://aaaa/?aaaa=1&b=%s&c", "aaaa" }, | 45 { "aaaa", "http://aaaa/?aaaa=1&b=%s&c", "aaaa" }, |
44 { "aaaaa", "%s", "aaaaa" }, | 46 { "aaaaa", "%s", "aaaaa" }, |
(...skipping 28 matching lines...) Expand all Loading... | |
73 EXPECT_EQ(keyword_cases[i].num_results, matches.size()) << | 75 EXPECT_EQ(keyword_cases[i].num_results, matches.size()) << |
74 ASCIIToUTF16("Input was: ") + keyword_cases[i].input; | 76 ASCIIToUTF16("Input was: ") + keyword_cases[i].input; |
75 if (matches.size() == keyword_cases[i].num_results) { | 77 if (matches.size() == keyword_cases[i].num_results) { |
76 for (size_t j = 0; j < keyword_cases[i].num_results; ++j) { | 78 for (size_t j = 0; j < keyword_cases[i].num_results; ++j) { |
77 EXPECT_EQ(keyword_cases[i].output[j], matches[j].*member); | 79 EXPECT_EQ(keyword_cases[i].output[j], matches[j].*member); |
78 } | 80 } |
79 } | 81 } |
80 } | 82 } |
81 } | 83 } |
82 | 84 |
85 void KeywordProviderTest::RunTest(const char* input, | |
86 const char* keyword) { | |
87 string16 keyword16(ASCIIToUTF16(keyword)); | |
88 string16 detected_keyword = | |
89 kw_provider_->GetKeywordForText(ASCIIToUTF16(input)); | |
90 EXPECT_EQ(keyword16, detected_keyword); | |
91 } | |
92 | |
83 // http://crbug.com/80612 | 93 // http://crbug.com/80612 |
84 TEST_F(KeywordProviderTest, DISABLED_Edit) { | 94 TEST_F(KeywordProviderTest, DISABLED_Edit) { |
85 test_data<string16> edit_cases[] = { | 95 test_data<string16> edit_cases[] = { |
86 // Searching for a nonexistent prefix should give nothing. | 96 // Searching for a nonexistent prefix should give nothing. |
87 {ASCIIToUTF16("Not Found"), 0, {}}, | 97 {ASCIIToUTF16("Not Found"), 0, {}}, |
88 {ASCIIToUTF16("aaaaaNot Found"), 0, {}}, | 98 {ASCIIToUTF16("aaaaaNot Found"), 0, {}}, |
89 | 99 |
90 // Check that tokenization only collapses whitespace between first tokens, | 100 // Check that tokenization only collapses whitespace between first tokens, |
91 // no-query-input cases have a space appended, and action is not escaped. | 101 // no-query-input cases have a space appended, and action is not escaped. |
92 {ASCIIToUTF16("z foo"), 1, {ASCIIToUTF16("z foo")}}, | 102 {ASCIIToUTF16("z foo"), 1, {ASCIIToUTF16("z foo")}}, |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 template_url->set_short_name(ASCIIToUTF16("Test")); | 219 template_url->set_short_name(ASCIIToUTF16("Test")); |
210 model_->Add(template_url); | 220 model_->Add(template_url); |
211 ASSERT_TRUE(template_url == model_->GetTemplateURLForKeyword(keyword)); | 221 ASSERT_TRUE(template_url == model_->GetTemplateURLForKeyword(keyword)); |
212 } | 222 } |
213 | 223 |
214 TEST_F(KeywordProviderTest, RemoveKeyword) { | 224 TEST_F(KeywordProviderTest, RemoveKeyword) { |
215 string16 url(ASCIIToUTF16("http://aaaa/?aaaa=1&b={searchTerms}&c")); | 225 string16 url(ASCIIToUTF16("http://aaaa/?aaaa=1&b={searchTerms}&c")); |
216 model_->Remove(model_->GetTemplateURLForKeyword(ASCIIToUTF16("aaaa"))); | 226 model_->Remove(model_->GetTemplateURLForKeyword(ASCIIToUTF16("aaaa"))); |
217 ASSERT_TRUE(model_->GetTemplateURLForKeyword(ASCIIToUTF16("aaaa")) == NULL); | 227 ASSERT_TRUE(model_->GetTemplateURLForKeyword(ASCIIToUTF16("aaaa")) == NULL); |
218 } | 228 } |
229 | |
230 TEST_F(KeywordProviderTest, GetKeywordForInput) { | |
231 RunTest("aa", "aa"); | |
232 RunTest("aafoo", ""); | |
233 RunTest("aa foo", "aa"); | |
234 } | |
235 | |
OLD | NEW |