| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/autocomplete/keyword_provider.h" | 6 #include "chrome/browser/autocomplete/keyword_provider.h" |
| 7 #include "chrome/browser/search_engines/template_url.h" | 7 #include "chrome/browser/search_engines/template_url.h" |
| 8 #include "chrome/browser/search_engines/template_url_model.h" | 8 #include "chrome/browser/search_engines/template_url_model.h" |
| 9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 92 |
| 93 // Matches should be limited to three, and sorted in quality order, not | 93 // Matches should be limited to three, and sorted in quality order, not |
| 94 // alphabetical. | 94 // alphabetical. |
| 95 {L"aaa", 2, {L"aaaa ", L"aaaaa "}}, | 95 {L"aaa", 2, {L"aaaa ", L"aaaaa "}}, |
| 96 {L"a 1 2 3", 3, {L"aa 1 2 3", L"ab 1 2 3", L"aaaa 1 2 3"}}, | 96 {L"a 1 2 3", 3, {L"aa 1 2 3", L"ab 1 2 3", L"aaaa 1 2 3"}}, |
| 97 {L"www.a", 3, {L"aa ", L"ab ", L"aaaa "}}, | 97 {L"www.a", 3, {L"aa ", L"ab ", L"aaaa "}}, |
| 98 // Exact matches should prevent returning inexact matches. | 98 // Exact matches should prevent returning inexact matches. |
| 99 {L"aaaa foo", 1, {L"aaaa foo"}}, | 99 {L"aaaa foo", 1, {L"aaaa foo"}}, |
| 100 {L"www.aaaa foo", 1, {L"aaaa foo"}}, | 100 {L"www.aaaa foo", 1, {L"aaaa foo"}}, |
| 101 | 101 |
| 102 // Clean up keyword input properly. | 102 // Clean up keyword input properly. "http" and "https" are the only |
| 103 // allowed schemes. |
| 103 {L"www", 1, {L"www "}}, | 104 {L"www", 1, {L"www "}}, |
| 104 {L"www.", 0, {}}, | 105 {L"www.", 0, {}}, |
| 105 {L"www.w w", 2, {L"www w", L"weasel w"}}, | 106 {L"www.w w", 2, {L"www w", L"weasel w"}}, |
| 106 {L"http://www", 1, {L"www "}}, | 107 {L"http://www", 1, {L"www "}}, |
| 107 {L"http://www.", 0, {}}, | 108 {L"http://www.", 0, {}}, |
| 108 {L"ftp: blah", 0, {}}, | 109 {L"ftp: blah", 0, {}}, |
| 109 {L"mailto:z", 1, {L"z "}}, | 110 {L"mailto:z", 0, {}}, |
| 111 {L"ftp://z", 0, {}}, |
| 112 {L"https://z", 1, {L"z "}}, |
| 110 }; | 113 }; |
| 111 | 114 |
| 112 RunTest<std::wstring>(edit_cases, arraysize(edit_cases), | 115 RunTest<std::wstring>(edit_cases, arraysize(edit_cases), |
| 113 &AutocompleteMatch::fill_into_edit); | 116 &AutocompleteMatch::fill_into_edit); |
| 114 } | 117 } |
| 115 | 118 |
| 116 TEST_F(KeywordProviderTest, URL) { | 119 TEST_F(KeywordProviderTest, URL) { |
| 117 test_data<GURL> url_cases[] = { | 120 test_data<GURL> url_cases[] = { |
| 118 // No query input -> empty destination URL. | 121 // No query input -> empty destination URL. |
| 119 {L"z", 1, {GURL()}}, | 122 {L"z", 1, {GURL()}}, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 RunTest<std::wstring>(contents_cases, arraysize(contents_cases), | 161 RunTest<std::wstring>(contents_cases, arraysize(contents_cases), |
| 159 &AutocompleteMatch::contents); | 162 &AutocompleteMatch::contents); |
| 160 } | 163 } |
| 161 | 164 |
| 162 TEST_F(KeywordProviderTest, Description) { | 165 TEST_F(KeywordProviderTest, Description) { |
| 163 test_data<std::wstring> description_cases[] = { | 166 test_data<std::wstring> description_cases[] = { |
| 164 // Whole keyword should be returned for both exact and inexact matches. | 167 // Whole keyword should be returned for both exact and inexact matches. |
| 165 {L"z foo", 1, {L"(Keyword: z)"}}, | 168 {L"z foo", 1, {L"(Keyword: z)"}}, |
| 166 {L"a foo", 3, {L"(Keyword: aa)", L"(Keyword: ab)", | 169 {L"a foo", 3, {L"(Keyword: aa)", L"(Keyword: ab)", |
| 167 L"(Keyword: aaaa)"}}, | 170 L"(Keyword: aaaa)"}}, |
| 168 {L"ftp://www.www w", 1, {L"(Keyword: www)"}}, | 171 {L"ftp://www.www w", 0, {}}, |
| 172 {L"http://www.ab w", 1, {L"(Keyword: ab)"}}, |
| 169 | 173 |
| 170 // Keyword should be returned regardless of query input. | 174 // Keyword should be returned regardless of query input. |
| 171 {L"z", 1, {L"(Keyword: z)"}}, | 175 {L"z", 1, {L"(Keyword: z)"}}, |
| 172 {L"z \t", 1, {L"(Keyword: z)"}}, | 176 {L"z \t", 1, {L"(Keyword: z)"}}, |
| 173 {L"z a b c++", 1, {L"(Keyword: z)"}}, | 177 {L"z a b c++", 1, {L"(Keyword: z)"}}, |
| 174 }; | 178 }; |
| 175 | 179 |
| 176 RunTest<std::wstring>(description_cases, arraysize(description_cases), | 180 RunTest<std::wstring>(description_cases, arraysize(description_cases), |
| 177 &AutocompleteMatch::description); | 181 &AutocompleteMatch::description); |
| 178 } | 182 } |
| 179 | 183 |
| 180 TEST_F(KeywordProviderTest, AddKeyword) { | 184 TEST_F(KeywordProviderTest, AddKeyword) { |
| 181 TemplateURL* template_url = new TemplateURL(); | 185 TemplateURL* template_url = new TemplateURL(); |
| 182 std::wstring keyword(L"foo"); | 186 std::wstring keyword(L"foo"); |
| 183 std::string url("http://www.google.com/foo?q={searchTerms}"); | 187 std::string url("http://www.google.com/foo?q={searchTerms}"); |
| 184 template_url->SetURL(url, 0, 0); | 188 template_url->SetURL(url, 0, 0); |
| 185 template_url->set_keyword(keyword); | 189 template_url->set_keyword(keyword); |
| 186 template_url->set_short_name(L"Test"); | 190 template_url->set_short_name(L"Test"); |
| 187 model_->Add(template_url); | 191 model_->Add(template_url); |
| 188 ASSERT_TRUE(template_url == model_->GetTemplateURLForKeyword(keyword)); | 192 ASSERT_TRUE(template_url == model_->GetTemplateURLForKeyword(keyword)); |
| 189 } | 193 } |
| 190 | 194 |
| 191 TEST_F(KeywordProviderTest, RemoveKeyword) { | 195 TEST_F(KeywordProviderTest, RemoveKeyword) { |
| 192 std::wstring url(L"http://aaaa/?aaaa=1&b={searchTerms}&c"); | 196 std::wstring url(L"http://aaaa/?aaaa=1&b={searchTerms}&c"); |
| 193 model_->Remove(model_->GetTemplateURLForKeyword(L"aaaa")); | 197 model_->Remove(model_->GetTemplateURLForKeyword(L"aaaa")); |
| 194 ASSERT_TRUE(model_->GetTemplateURLForKeyword(L"aaaa") == NULL); | 198 ASSERT_TRUE(model_->GetTemplateURLForKeyword(L"aaaa") == NULL); |
| 195 } | 199 } |
| OLD | NEW |