Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: chrome/browser/autocomplete/history_url_provider_unittest.cc

Issue 372017: Fix various problems with inline autocomplete and URLs that change length dur... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/autocomplete/history_url_provider.h" 9 #include "chrome/browser/autocomplete/history_url_provider.h"
10 #include "chrome/browser/chrome_thread.h" 10 #include "chrome/browser/chrome_thread.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 {"http://bogussite.com/b", L"Bogus B", 10001, 10000}, 76 {"http://bogussite.com/b", L"Bogus B", 10001, 10000},
77 {"http://bogussite.com/c", L"Bogus C", 10000, 10000}, 77 {"http://bogussite.com/c", L"Bogus C", 10000, 10000},
78 78
79 // Domain name with number. 79 // Domain name with number.
80 {"http://www.17173.com/", L"Domain with number", 3, 3}, 80 {"http://www.17173.com/", L"Domain with number", 3, 3},
81 81
82 // URLs to test exact-matching behavior. 82 // URLs to test exact-matching behavior.
83 {"http://go/", L"Intranet URL", 1, 1}, 83 {"http://go/", L"Intranet URL", 1, 1},
84 {"http://gooey/", L"Intranet URL 2", 5, 5}, 84 {"http://gooey/", L"Intranet URL 2", 5, 5},
85 85
86 // URLs for testing offset adjustment
87 {"http://www.\xEA\xB5\x90\xEC\x9C\xA1.kr/", L"Korean", 2, 2},
88 {"http://spaces.com/path%20with%20spaces/foo.html", L"Spaces", 2, 2},
89 {"http://ms/c++%20style%20guide", L"Style guide", 2, 2},
90 {"http://foo:bar@baz.com/", L"HTTP auth", 2, 2},
86 }; 91 };
87 92
88 class HistoryURLProviderTest : public testing::Test, 93 class HistoryURLProviderTest : public testing::Test,
89 public ACProviderListener { 94 public ACProviderListener {
90 public: 95 public:
91 HistoryURLProviderTest() 96 HistoryURLProviderTest()
92 : ui_thread_(ChromeThread::UI, &message_loop_), 97 : ui_thread_(ChromeThread::UI, &message_loop_),
93 file_thread_(ChromeThread::FILE, &message_loop_) {} 98 file_thread_(ChromeThread::FILE, &message_loop_) {}
94 99
95 // ACProviderListener 100 // ACProviderListener
(...skipping 13 matching lines...) Expand all
109 void FillData(); 114 void FillData();
110 115
111 // Runs an autocomplete query on |text| and checks to see that the returned 116 // Runs an autocomplete query on |text| and checks to see that the returned
112 // results' destination URLs match those provided. 117 // results' destination URLs match those provided.
113 void RunTest(const std::wstring text, 118 void RunTest(const std::wstring text,
114 const std::wstring& desired_tld, 119 const std::wstring& desired_tld,
115 bool prevent_inline_autocomplete, 120 bool prevent_inline_autocomplete,
116 const std::string* expected_urls, 121 const std::string* expected_urls,
117 size_t num_results); 122 size_t num_results);
118 123
124 void RunAdjustOffsetTest(const std::wstring text, size_t expected_offset);
125
119 MessageLoopForUI message_loop_; 126 MessageLoopForUI message_loop_;
120 ChromeThread ui_thread_; 127 ChromeThread ui_thread_;
121 ChromeThread file_thread_; 128 ChromeThread file_thread_;
122 ACMatches matches_; 129 ACMatches matches_;
123 scoped_ptr<TestingProfile> profile_; 130 scoped_ptr<TestingProfile> profile_;
124 HistoryService* history_service_; 131 HistoryService* history_service_;
125 132
126 private: 133 private:
127 scoped_refptr<HistoryURLProvider> autocomplete_; 134 scoped_refptr<HistoryURLProvider> autocomplete_;
128 }; 135 };
129 136
130 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest { 137 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest {
131 protected: 138 protected:
132 virtual void SetUp() { 139 virtual void SetUp() {
133 SetUpImpl(true); 140 SetUpImpl(true);
134 } 141 }
135 }; 142 };
136 143
137 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) { 144 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) {
138 if (autocomplete_->done()) 145 if (autocomplete_->done())
139 MessageLoop::current()->Quit(); 146 MessageLoop::current()->Quit();
140 } 147 }
141 148
142 void HistoryURLProviderTest::SetUpImpl(bool no_db) { 149 void HistoryURLProviderTest::SetUpImpl(bool no_db) {
143 profile_.reset(new TestingProfile()); 150 profile_.reset(new TestingProfile());
144 profile_->CreateHistoryService(true, no_db); 151 profile_->CreateHistoryService(true, no_db);
145 history_service_ = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 152 history_service_ = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
146 153
147 autocomplete_ = new HistoryURLProvider(this, profile_.get()); 154 autocomplete_ = new HistoryURLProvider(this, profile_.get(), L"en-US,en,ko");
148 155
149 FillData(); 156 FillData();
150 } 157 }
151 158
152 void HistoryURLProviderTest::TearDown() { 159 void HistoryURLProviderTest::TearDown() {
153 autocomplete_ = NULL; 160 autocomplete_ = NULL;
154 } 161 }
155 162
156 void HistoryURLProviderTest::FillData() { 163 void HistoryURLProviderTest::FillData() {
157 // All visits are a long time ago (some tests require this since we do some 164 // All visits are a long time ago (some tests require this since we do some
(...skipping 24 matching lines...) Expand all
182 autocomplete_->Start(input, false); 189 autocomplete_->Start(input, false);
183 if (!autocomplete_->done()) 190 if (!autocomplete_->done())
184 MessageLoop::current()->Run(); 191 MessageLoop::current()->Run();
185 192
186 matches_ = autocomplete_->matches(); 193 matches_ = autocomplete_->matches();
187 ASSERT_EQ(num_results, matches_.size()) << "Input text: " << text; 194 ASSERT_EQ(num_results, matches_.size()) << "Input text: " << text;
188 for (size_t i = 0; i < num_results; ++i) 195 for (size_t i = 0; i < num_results; ++i)
189 EXPECT_EQ(expected_urls[i], matches_[i].destination_url.spec()); 196 EXPECT_EQ(expected_urls[i], matches_[i].destination_url.spec());
190 } 197 }
191 198
199 void HistoryURLProviderTest::RunAdjustOffsetTest(const std::wstring text,
200 size_t expected_offset) {
201 AutocompleteInput input(text, std::wstring(), false, false, false);
202 autocomplete_->Start(input, false);
203 if (!autocomplete_->done())
204 MessageLoop::current()->Run();
205
206 matches_ = autocomplete_->matches();
207 ASSERT_GE(matches_.size(), 1U) << "Input text: " << text;
208 EXPECT_EQ(expected_offset, matches_[0].inline_autocomplete_offset);
209 }
210
192 TEST_F(HistoryURLProviderTest, PromoteShorterURLs) { 211 TEST_F(HistoryURLProviderTest, PromoteShorterURLs) {
193 // Test that hosts get synthesized below popular pages. 212 // Test that hosts get synthesized below popular pages.
194 const std::string expected_nonsynth[] = { 213 const std::string expected_nonsynth[] = {
195 "http://slashdot.org/favorite_page.html", 214 "http://slashdot.org/favorite_page.html",
196 "http://slashdot.org/", 215 "http://slashdot.org/",
197 }; 216 };
198 RunTest(L"slash", std::wstring(), true, expected_nonsynth, 217 RunTest(L"slash", std::wstring(), true, expected_nonsynth,
199 arraysize(expected_nonsynth)); 218 arraysize(expected_nonsynth));
200 219
201 // Test that hosts get synthesized above less popular pages. 220 // Test that hosts get synthesized above less popular pages.
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 // An input looks like a IP address like "127.0.0.1" should result in 394 // An input looks like a IP address like "127.0.0.1" should result in
376 // "http://127.0.0.1/". 395 // "http://127.0.0.1/".
377 const std::string fixup_4[] = {"http://127.0.0.1/"}; 396 const std::string fixup_4[] = {"http://127.0.0.1/"};
378 RunTest(L"127.0.0.1", std::wstring(), false, fixup_4, arraysize(fixup_4)); 397 RunTest(L"127.0.0.1", std::wstring(), false, fixup_4, arraysize(fixup_4));
379 398
380 // An number "17173" should result in "http://www.17173.com/" in db. 399 // An number "17173" should result in "http://www.17173.com/" in db.
381 const std::string fixup_5[] = {"http://www.17173.com/"}; 400 const std::string fixup_5[] = {"http://www.17173.com/"};
382 RunTest(L"17173", std::wstring(), false, fixup_5, arraysize(fixup_5)); 401 RunTest(L"17173", std::wstring(), false, fixup_5, arraysize(fixup_5));
383 } 402 }
384 403
404 TEST_F(HistoryURLProviderTest, AdjustOffset) {
405 RunAdjustOffsetTest(L"http://www.\uAD50\uC721", 13);
406 RunAdjustOffsetTest(L"http://spaces.com/path%20with%20spa", 31);
407 RunAdjustOffsetTest(L"http://ms/c++ s", 15);
408 RunAdjustOffsetTest(L"http://foo:ba", std::wstring::npos);
409 RunAdjustOffsetTest(L"http://foo:bar@ba", 9);
410 }
411
385 TEST_F(HistoryURLProviderTestNoDB, NavigateWithoutDB) { 412 TEST_F(HistoryURLProviderTestNoDB, NavigateWithoutDB) {
386 // Ensure that we will still produce matches for navigation when there is no 413 // Ensure that we will still produce matches for navigation when there is no
387 // database. 414 // database.
388 std::string navigation_1[] = {"http://test.com/"}; 415 std::string navigation_1[] = {"http://test.com/"};
389 RunTest(L"test.com", std::wstring(), false, navigation_1, 416 RunTest(L"test.com", std::wstring(), false, navigation_1,
390 arraysize(navigation_1)); 417 arraysize(navigation_1));
391 418
392 std::string navigation_2[] = {"http://slash/"}; 419 std::string navigation_2[] = {"http://slash/"};
393 RunTest(L"slash", std::wstring(), false, navigation_2, 420 RunTest(L"slash", std::wstring(), false, navigation_2,
394 arraysize(navigation_2)); 421 arraysize(navigation_2));
395 422
396 RunTest(L"this is a query", std::wstring(), false, NULL, 0); 423 RunTest(L"this is a query", std::wstring(), false, NULL, 0);
397 } 424 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_url_provider.cc ('k') | chrome/browser/bookmarks/bookmark_table_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698