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 "chrome/browser/autocomplete/history_url_provider.h" | 5 #include "chrome/browser/autocomplete/history_url_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 158 } |
159 virtual void TearDown(); | 159 virtual void TearDown(); |
160 | 160 |
161 // Does the real setup. | 161 // Does the real setup. |
162 void SetUpImpl(bool no_db); | 162 void SetUpImpl(bool no_db); |
163 | 163 |
164 // Fills test data into the history system. | 164 // Fills test data into the history system. |
165 void FillData(); | 165 void FillData(); |
166 | 166 |
167 // Runs an autocomplete query on |text| and checks to see that the returned | 167 // Runs an autocomplete query on |text| and checks to see that the returned |
168 // results' destination URLs match those provided. | 168 // results' destination URLs match those provided. Also allows checking |
| 169 // that the input type was identified correctly. |
169 void RunTest(const string16 text, | 170 void RunTest(const string16 text, |
170 const string16& desired_tld, | 171 const string16& desired_tld, |
171 bool prevent_inline_autocomplete, | 172 bool prevent_inline_autocomplete, |
172 const std::string* expected_urls, | 173 const std::string* expected_urls, |
173 size_t num_results); | 174 size_t num_results, |
| 175 AutocompleteInput::Type* identified_input_type); |
| 176 |
| 177 // A version of the above without the final |type| output parameter. |
| 178 void RunTest(const string16 text, |
| 179 const string16& desired_tld, |
| 180 bool prevent_inline_autocomplete, |
| 181 const std::string* expected_urls, |
| 182 size_t num_results) { |
| 183 AutocompleteInput::Type type; |
| 184 return RunTest(text, desired_tld, prevent_inline_autocomplete, |
| 185 expected_urls, num_results, &type); |
| 186 } |
174 | 187 |
175 void RunAdjustOffsetTest(const string16 text, size_t expected_offset); | 188 void RunAdjustOffsetTest(const string16 text, size_t expected_offset); |
176 | 189 |
177 MessageLoopForUI message_loop_; | 190 MessageLoopForUI message_loop_; |
178 content::TestBrowserThread ui_thread_; | 191 content::TestBrowserThread ui_thread_; |
179 content::TestBrowserThread file_thread_; | 192 content::TestBrowserThread file_thread_; |
180 ACMatches matches_; | 193 ACMatches matches_; |
181 scoped_ptr<TestingProfile> profile_; | 194 scoped_ptr<TestingProfile> profile_; |
182 HistoryService* history_service_; | 195 HistoryService* history_service_; |
183 scoped_refptr<HistoryURLProvider> autocomplete_; | 196 scoped_refptr<HistoryURLProvider> autocomplete_; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 history::SOURCE_BROWSED); | 246 history::SOURCE_BROWSED); |
234 } | 247 } |
235 | 248 |
236 history_service_->AddPageWithDetails( | 249 history_service_->AddPageWithDetails( |
237 GURL("http://p/"), UTF8ToUTF16("p"), 0, 0, | 250 GURL("http://p/"), UTF8ToUTF16("p"), 0, 0, |
238 Time::Now() - | 251 Time::Now() - |
239 TimeDelta::FromDays(history::kLowQualityMatchAgeLimitInDays - 1), | 252 TimeDelta::FromDays(history::kLowQualityMatchAgeLimitInDays - 1), |
240 false, history::SOURCE_BROWSED); | 253 false, history::SOURCE_BROWSED); |
241 } | 254 } |
242 | 255 |
243 void HistoryURLProviderTest::RunTest(const string16 text, | 256 void HistoryURLProviderTest::RunTest( |
244 const string16& desired_tld, | 257 const string16 text, |
245 bool prevent_inline_autocomplete, | 258 const string16& desired_tld, |
246 const std::string* expected_urls, | 259 bool prevent_inline_autocomplete, |
247 size_t num_results) { | 260 const std::string* expected_urls, |
| 261 size_t num_results, |
| 262 AutocompleteInput::Type* identified_input_type) { |
248 AutocompleteInput input(text, string16::npos, desired_tld, GURL(), | 263 AutocompleteInput input(text, string16::npos, desired_tld, GURL(), |
249 prevent_inline_autocomplete, false, true, | 264 prevent_inline_autocomplete, false, true, |
250 AutocompleteInput::ALL_MATCHES); | 265 AutocompleteInput::ALL_MATCHES); |
| 266 *identified_input_type = input.type(); |
251 autocomplete_->Start(input, false); | 267 autocomplete_->Start(input, false); |
252 if (!autocomplete_->done()) | 268 if (!autocomplete_->done()) |
253 MessageLoop::current()->Run(); | 269 MessageLoop::current()->Run(); |
254 | 270 |
255 matches_ = autocomplete_->matches(); | 271 matches_ = autocomplete_->matches(); |
256 if (sort_matches_) { | 272 if (sort_matches_) { |
257 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) | 273 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) |
258 i->ComputeStrippedDestinationURL(profile_.get()); | 274 i->ComputeStrippedDestinationURL(profile_.get()); |
259 std::sort(matches_.begin(), matches_.end(), | 275 std::sort(matches_.begin(), matches_.end(), |
260 &AutocompleteMatch::DestinationSortFunc); | 276 &AutocompleteMatch::DestinationSortFunc); |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), | 619 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), |
604 string16(), false, output, arraysize(output))); | 620 string16(), false, output, arraysize(output))); |
605 // Actual relevance should be at least what test_cases expects and | 621 // Actual relevance should be at least what test_cases expects and |
606 // and no more than 10 more. | 622 // and no more than 10 more. |
607 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance); | 623 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance); |
608 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10); | 624 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10); |
609 } | 625 } |
610 } | 626 } |
611 } | 627 } |
612 | 628 |
| 629 TEST_F(HistoryURLProviderTest, IntranetURLsWithRefs) { |
| 630 struct TestCase { |
| 631 const char* input; |
| 632 int relevance; |
| 633 AutocompleteInput::Type type; |
| 634 } test_cases[] = { |
| 635 { "gooey", 1410, AutocompleteInput::UNKNOWN }, |
| 636 { "gooey/", 1410, AutocompleteInput::URL }, |
| 637 { "gooey#", 1200, AutocompleteInput::UNKNOWN }, |
| 638 { "gooey/#", 1200, AutocompleteInput::URL }, |
| 639 { "gooey#foo", 1200, AutocompleteInput::UNKNOWN }, |
| 640 { "gooey/#foo", 1200, AutocompleteInput::URL }, |
| 641 { "gooey# foo", 1200, AutocompleteInput::UNKNOWN }, |
| 642 { "gooey/# foo", 1200, AutocompleteInput::URL }, |
| 643 }; |
| 644 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
| 645 SCOPED_TRACE(test_cases[i].input); |
| 646 const std::string output[] = { |
| 647 URLFixerUpper::FixupURL(test_cases[i].input, std::string()).spec() |
| 648 }; |
| 649 AutocompleteInput::Type type; |
| 650 ASSERT_NO_FATAL_FAILURE( |
| 651 RunTest(ASCIIToUTF16(test_cases[i].input), |
| 652 string16(), false, output, arraysize(output), &type)); |
| 653 // Actual relevance should be at least what test_cases expects and |
| 654 // and no more than 10 more. |
| 655 EXPECT_LE(test_cases[i].relevance, matches_[0].relevance); |
| 656 EXPECT_LT(matches_[0].relevance, test_cases[i].relevance + 10); |
| 657 // Input type should be what we expect. This is important because |
| 658 // this provider counts on SearchProvider to give queries a relevance |
| 659 // score >1200 for UNKNOWN inputs and <1200 for URL inputs. (That's |
| 660 // already tested in search_provider_unittest.cc.) For this test |
| 661 // here to test that the user sees the correct behavior, it needs |
| 662 // to check that the input type was identified correctly. |
| 663 EXPECT_EQ(test_cases[i].type, type); |
| 664 } |
| 665 } |
| 666 |
613 // Makes sure autocompletion happens for intranet sites that have been | 667 // Makes sure autocompletion happens for intranet sites that have been |
614 // previoulsy visited. | 668 // previoulsy visited. |
615 TEST_F(HistoryURLProviderTest, IntranetURLCompletion) { | 669 TEST_F(HistoryURLProviderTest, IntranetURLCompletion) { |
616 sort_matches_ = true; | 670 sort_matches_ = true; |
617 | 671 |
618 const std::string expected1[] = { | 672 const std::string expected1[] = { |
619 "http://intra/three", | 673 "http://intra/three", |
620 "http://intra/two", | 674 "http://intra/two", |
621 }; | 675 }; |
622 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/t"), string16(), false, | 676 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("intra/t"), string16(), false, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 RunTest(ASCIIToUTF16("foobar"), string16(), true, | 784 RunTest(ASCIIToUTF16("foobar"), string16(), true, |
731 expected_when_searching_query, arraysize(expected_when_searching_query)); | 785 expected_when_searching_query, arraysize(expected_when_searching_query)); |
732 | 786 |
733 // We should not see search URLs when typing the search engine name. | 787 // We should not see search URLs when typing the search engine name. |
734 const std::string expected_when_searching_site[] = { | 788 const std::string expected_when_searching_site[] = { |
735 test_cases[0].url | 789 test_cases[0].url |
736 }; | 790 }; |
737 RunTest(ASCIIToUTF16("testsearch"), string16(), true, | 791 RunTest(ASCIIToUTF16("testsearch"), string16(), true, |
738 expected_when_searching_site, arraysize(expected_when_searching_site)); | 792 expected_when_searching_site, arraysize(expected_when_searching_site)); |
739 } | 793 } |
OLD | NEW |