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

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

Issue 9316109: Move Ownership of IMUI to HistoryService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 months 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
« no previous file with comments | « no previous file | chrome/browser/history/history.h » ('j') | chrome/browser/history/history.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_quick_provider.h" 5 #include "chrome/browser/autocomplete/history_quick_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 void operator()(const std::string& expected); 93 void operator()(const std::string& expected);
94 94
95 std::set<std::string> LeftOvers() const { return matches_; } 95 std::set<std::string> LeftOvers() const { return matches_; }
96 96
97 private: 97 private:
98 std::set<std::string> matches_; 98 std::set<std::string> matches_;
99 }; 99 };
100 100
101 void SetUp(); 101 void SetUp();
102 102 void TearDown();
103 void TearDown() {
104 provider_ = NULL;
105 }
106 103
107 virtual void GetTestData(size_t* data_count, TestURLInfo** test_data); 104 virtual void GetTestData(size_t* data_count, TestURLInfo** test_data);
108 105
109 // Fills test data into the history system. 106 // Fills test data into the history system.
110 void FillData(); 107 void FillData();
111 108
112 // Runs an autocomplete query on |text| and checks to see that the returned 109 // Runs an autocomplete query on |text| and checks to see that the returned
113 // results' destination URLs match those provided. |expected_urls| does not 110 // results' destination URLs match those provided. |expected_urls| does not
114 // need to be in sorted order. 111 // need to be in sorted order.
115 void RunTest(const string16 text, 112 void RunTest(const string16 text,
(...skipping 18 matching lines...) Expand all
134 profile_.reset(new TestingProfile()); 131 profile_.reset(new TestingProfile());
135 profile_->CreateHistoryService(true, false); 132 profile_->CreateHistoryService(true, false);
136 profile_->CreateBookmarkModel(true); 133 profile_->CreateBookmarkModel(true);
137 profile_->BlockUntilBookmarkModelLoaded(); 134 profile_->BlockUntilBookmarkModelLoaded();
138 history_service_ = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 135 history_service_ = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
139 EXPECT_TRUE(history_service_); 136 EXPECT_TRUE(history_service_);
140 provider_ = new HistoryQuickProvider(this, profile_.get()); 137 provider_ = new HistoryQuickProvider(this, profile_.get());
141 FillData(); 138 FillData();
142 } 139 }
143 140
141 void HistoryQuickProviderTest::TearDown() {
142 provider_ = NULL;
143 }
144
144 void HistoryQuickProviderTest::OnProviderUpdate(bool updated_matches) { 145 void HistoryQuickProviderTest::OnProviderUpdate(bool updated_matches) {
145 MessageLoop::current()->Quit(); 146 MessageLoop::current()->Quit();
146 } 147 }
147 148
148 void HistoryQuickProviderTest::GetTestData(size_t* data_count, 149 void HistoryQuickProviderTest::GetTestData(size_t* data_count,
149 TestURLInfo** test_data) { 150 TestURLInfo** test_data) {
150 DCHECK(data_count); 151 DCHECK(data_count);
151 DCHECK(test_data); 152 DCHECK(test_data);
152 *data_count = arraysize(quick_test_db); 153 *data_count = arraysize(quick_test_db);
153 *test_data = &quick_test_db[0]; 154 *test_data = &quick_test_db[0];
154 } 155 }
155 156
156 void HistoryQuickProviderTest::FillData() { 157 void HistoryQuickProviderTest::FillData() {
157 history::URLDatabase* db = history_service_->InMemoryDatabase(); 158 history::URLDatabase* db = history_service_->InMemoryDatabase();
158 ASSERT_TRUE(db != NULL); 159 ASSERT_TRUE(db != NULL);
159 160 #if 1
161 // DO WE WANT THIS CHANGE?
Peter Kasting 2012/02/04 02:20:31 ?
mrossetti 2012/02/04 04:30:53 I apologize. I thought I'd gotten all the conditio
162 history::InMemoryURLIndex* index = provider_->GetIndex();
163 #else
164 // CURRENT REPO
160 history::InMemoryURLIndex* index = 165 history::InMemoryURLIndex* index =
161 new history::InMemoryURLIndex(FilePath()); 166 new history::InMemoryURLIndex(FilePath());
162 PrefService* prefs = profile_->GetPrefs(); 167 PrefService* prefs = profile_->GetPrefs();
163 std::string languages(prefs->GetString(prefs::kAcceptLanguages)); 168 std::string languages(prefs->GetString(prefs::kAcceptLanguages));
164 index->Init(db, languages); 169 index->Init(db, languages);
170 #endif
165 size_t data_count = 0; 171 size_t data_count = 0;
166 TestURLInfo* test_data = NULL; 172 TestURLInfo* test_data = NULL;
167 GetTestData(&data_count, &test_data); 173 GetTestData(&data_count, &test_data);
168 for (size_t i = 0; i < data_count; ++i) { 174 for (size_t i = 0; i < data_count; ++i) {
169 const TestURLInfo& cur(test_data[i]); 175 const TestURLInfo& cur(test_data[i]);
170 const GURL current_url(cur.url); 176 const GURL current_url(cur.url);
171 Time visit_time = Time::Now() - TimeDelta::FromDays(cur.days_from_now); 177 Time visit_time = Time::Now() - TimeDelta::FromDays(cur.days_from_now);
172 178
173 history::URLRow url_info(current_url); 179 history::URLRow url_info(current_url);
180 url_info.set_id(i + 5000);
174 url_info.set_title(UTF8ToUTF16(cur.title)); 181 url_info.set_title(UTF8ToUTF16(cur.title));
175 url_info.set_visit_count(cur.visit_count); 182 url_info.set_visit_count(cur.visit_count);
176 url_info.set_typed_count(cur.typed_count); 183 url_info.set_typed_count(cur.typed_count);
177 url_info.set_last_visit(visit_time); 184 url_info.set_last_visit(visit_time);
178 url_info.set_hidden(false); 185 url_info.set_hidden(false);
179 index->UpdateURL(i, url_info); 186 index->UpdateURL(url_info);
180 } 187 }
181
182 provider_->set_index(index);
183 } 188 }
184 189
185 HistoryQuickProviderTest::SetShouldContain::SetShouldContain( 190 HistoryQuickProviderTest::SetShouldContain::SetShouldContain(
186 const ACMatches& matched_urls) { 191 const ACMatches& matched_urls) {
187 for (ACMatches::const_iterator iter = matched_urls.begin(); 192 for (ACMatches::const_iterator iter = matched_urls.begin();
188 iter != matched_urls.end(); ++iter) 193 iter != matched_urls.end(); ++iter)
189 matches_.insert(iter->destination_url.spec()); 194 matches_.insert(iter->destination_url.spec());
190 } 195 }
191 196
192 void HistoryQuickProviderTest::SetShouldContain::operator()( 197 void HistoryQuickProviderTest::SetShouldContain::operator()(
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 538
534 TEST_F(HQPOrderingTest, TEAMatch) { 539 TEST_F(HQPOrderingTest, TEAMatch) {
535 std::vector<std::string> expected_urls; 540 std::vector<std::string> expected_urls;
536 expected_urls.push_back("http://www.teamliquid.net/"); 541 expected_urls.push_back("http://www.teamliquid.net/");
537 expected_urls.push_back("http://www.teamliquid.net/tlpd"); 542 expected_urls.push_back("http://www.teamliquid.net/tlpd");
538 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); 543 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players");
539 RunTest(ASCIIToUTF16("tea"), expected_urls, true, 544 RunTest(ASCIIToUTF16("tea"), expected_urls, true,
540 ASCIIToUTF16("www.teamliquid.net")); 545 ASCIIToUTF16("www.teamliquid.net"));
541 } 546 }
542 547
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/history/history.h » ('j') | chrome/browser/history/history.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698