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