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 "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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 EXPECT_TRUE(history_service_); | 135 EXPECT_TRUE(history_service_); |
136 provider_ = new HistoryQuickProvider(this, profile_.get()); | 136 provider_ = new HistoryQuickProvider(this, profile_.get()); |
137 FillData(); | 137 FillData(); |
138 } | 138 } |
139 | 139 |
140 void HistoryQuickProviderTest::OnProviderUpdate(bool updated_matches) { | 140 void HistoryQuickProviderTest::OnProviderUpdate(bool updated_matches) { |
141 MessageLoop::current()->Quit(); | 141 MessageLoop::current()->Quit(); |
142 } | 142 } |
143 | 143 |
144 void HistoryQuickProviderTest::FillData() { | 144 void HistoryQuickProviderTest::FillData() { |
145 history::URLDatabase* db = history_service_->InMemoryDatabase(); | |
146 ASSERT_TRUE(db != NULL); | |
147 | |
148 history::InMemoryURLIndex* index = | 145 history::InMemoryURLIndex* index = |
149 new history::InMemoryURLIndex(FilePath()); | 146 new history::InMemoryURLIndex(profile_.get(), FilePath()); |
150 PrefService* prefs = profile_->GetPrefs(); | 147 PrefService* prefs = profile_->GetPrefs(); |
151 std::string languages(prefs->GetString(prefs::kAcceptLanguages)); | 148 std::string languages(prefs->GetString(prefs::kAcceptLanguages)); |
152 index->Init(db, languages); | 149 index->Init(languages); |
153 for (size_t i = 0; i < arraysize(quick_test_db); ++i) { | 150 for (size_t i = 0; i < arraysize(quick_test_db); ++i) { |
154 const TestURLInfo& cur = quick_test_db[i]; | 151 const TestURLInfo& cur = quick_test_db[i]; |
155 const GURL current_url(cur.url); | 152 const GURL current_url(cur.url); |
156 Time visit_time = Time::Now() - TimeDelta::FromDays(cur.days_from_now); | 153 Time visit_time = Time::Now() - TimeDelta::FromDays(cur.days_from_now); |
157 | 154 |
158 history::URLRow url_info(current_url); | 155 history::URLRow url_info(current_url); |
159 url_info.set_title(UTF8ToUTF16(cur.title)); | 156 url_info.set_title(UTF8ToUTF16(cur.title)); |
160 url_info.set_visit_count(cur.visit_count); | 157 url_info.set_visit_count(cur.visit_count); |
161 url_info.set_typed_count(cur.typed_count); | 158 url_info.set_typed_count(cur.typed_count); |
162 url_info.set_last_visit(visit_time); | 159 url_info.set_last_visit(visit_time); |
163 url_info.set_hidden(false); | 160 url_info.set_hidden(false); |
164 index->UpdateURL(i, url_info); | 161 url_info.set_id(i); |
| 162 index->UpdateURL(url_info); |
165 } | 163 } |
166 | 164 |
167 provider_->set_index(index); | 165 provider_->set_index(index); |
168 } | 166 } |
169 | 167 |
170 HistoryQuickProviderTest::SetShouldContain::SetShouldContain( | 168 HistoryQuickProviderTest::SetShouldContain::SetShouldContain( |
171 const ACMatches& matched_urls) { | 169 const ACMatches& matched_urls) { |
172 for (ACMatches::const_iterator iter = matched_urls.begin(); | 170 for (ACMatches::const_iterator iter = matched_urls.begin(); |
173 iter != matched_urls.end(); ++iter) | 171 iter != matched_urls.end(); ++iter) |
174 matches_.insert(iter->destination_url.spec()); | 172 matches_.insert(iter->destination_url.spec()); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 kMaxNonInliningScore - 1); | 418 kMaxNonInliningScore - 1); |
421 EXPECT_EQ(next_score, kMaxNonInliningScore - 2); | 419 EXPECT_EQ(next_score, kMaxNonInliningScore - 2); |
422 | 420 |
423 // Low score, can inline, not clamped. | 421 // Low score, can inline, not clamped. |
424 next_score = 1500; | 422 next_score = 1500; |
425 match.raw_score = 500; | 423 match.raw_score = 500; |
426 match.can_inline = true; | 424 match.can_inline = true; |
427 EXPECT_EQ(HistoryQuickProvider::CalculateRelevance(match, &next_score), 500); | 425 EXPECT_EQ(HistoryQuickProvider::CalculateRelevance(match, &next_score), 500); |
428 EXPECT_EQ(next_score, 499); | 426 EXPECT_EQ(next_score, 499); |
429 } | 427 } |
OLD | NEW |