| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 {"http://abcdefghixyzjklmnopqrstuvw.com/a", "", 3, 1, 0}, | 66 {"http://abcdefghixyzjklmnopqrstuvw.com/a", "", 3, 1, 0}, |
| 67 {"http://spaces.com/path%20with%20spaces/foo.html", "Spaces", 2, 2, 0}, | 67 {"http://spaces.com/path%20with%20spaces/foo.html", "Spaces", 2, 2, 0}, |
| 68 {"http://abcdefghijklxyzmnopqrstuvw.com/a", "", 3, 1, 0}, | 68 {"http://abcdefghijklxyzmnopqrstuvw.com/a", "", 3, 1, 0}, |
| 69 {"http://abcdefxyzghijklmnopqrstuvw.com/a", "", 3, 1, 0}, | 69 {"http://abcdefxyzghijklmnopqrstuvw.com/a", "", 3, 1, 0}, |
| 70 {"http://abcxyzdefghijklmnopqrstuvw.com/a", "", 3, 1, 0}, | 70 {"http://abcxyzdefghijklmnopqrstuvw.com/a", "", 3, 1, 0}, |
| 71 {"http://xyzabcdefghijklmnopqrstuvw.com/a", "", 3, 1, 0}, | 71 {"http://xyzabcdefghijklmnopqrstuvw.com/a", "", 3, 1, 0}, |
| 72 {"http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice", | 72 {"http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice", |
| 73 "Dogs & Cats & Mice & Other Animals", 1, 1, 0}, | 73 "Dogs & Cats & Mice & Other Animals", 1, 1, 0}, |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 // ----------------------------------------------------------------------------- |
| 77 |
| 76 class HistoryQuickProviderTest : public testing::Test, | 78 class HistoryQuickProviderTest : public testing::Test, |
| 77 public ACProviderListener { | 79 public ACProviderListener { |
| 78 public: | 80 public: |
| 79 HistoryQuickProviderTest() | 81 HistoryQuickProviderTest() |
| 80 : ui_thread_(BrowserThread::UI, &message_loop_), | 82 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 81 file_thread_(BrowserThread::FILE, &message_loop_) {} | 83 file_thread_(BrowserThread::FILE, &message_loop_) {} |
| 82 | 84 |
| 83 // ACProviderListener | 85 // ACProviderListener |
| 84 virtual void OnProviderUpdate(bool updated_matches); | 86 virtual void OnProviderUpdate(bool updated_matches); |
| 85 | 87 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } | 140 } |
| 139 | 141 |
| 140 void HistoryQuickProviderTest::OnProviderUpdate(bool updated_matches) { | 142 void HistoryQuickProviderTest::OnProviderUpdate(bool updated_matches) { |
| 141 MessageLoop::current()->Quit(); | 143 MessageLoop::current()->Quit(); |
| 142 } | 144 } |
| 143 | 145 |
| 144 void HistoryQuickProviderTest::FillData() { | 146 void HistoryQuickProviderTest::FillData() { |
| 145 history::URLDatabase* db = history_service_->InMemoryDatabase(); | 147 history::URLDatabase* db = history_service_->InMemoryDatabase(); |
| 146 ASSERT_TRUE(db != NULL); | 148 ASSERT_TRUE(db != NULL); |
| 147 | 149 |
| 148 history::InMemoryURLIndex* index = | 150 history::InMemoryURLIndex* index = provider_->GetIndex(); |
| 149 new history::InMemoryURLIndex(FilePath()); | |
| 150 PrefService* prefs = profile_->GetPrefs(); | |
| 151 std::string languages(prefs->GetString(prefs::kAcceptLanguages)); | |
| 152 index->Init(db, languages); | |
| 153 for (size_t i = 0; i < arraysize(quick_test_db); ++i) { | 151 for (size_t i = 0; i < arraysize(quick_test_db); ++i) { |
| 154 const TestURLInfo& cur = quick_test_db[i]; | 152 const TestURLInfo& cur = quick_test_db[i]; |
| 155 const GURL current_url(cur.url); | 153 const GURL current_url(cur.url); |
| 156 Time visit_time = Time::Now() - TimeDelta::FromDays(cur.days_from_now); | 154 Time visit_time = Time::Now() - TimeDelta::FromDays(cur.days_from_now); |
| 157 | 155 |
| 158 history::URLRow url_info(current_url); | 156 history::URLRow url_info(current_url); |
| 157 url_info.set_id(i + 5000); |
| 159 url_info.set_title(UTF8ToUTF16(cur.title)); | 158 url_info.set_title(UTF8ToUTF16(cur.title)); |
| 160 url_info.set_visit_count(cur.visit_count); | 159 url_info.set_visit_count(cur.visit_count); |
| 161 url_info.set_typed_count(cur.typed_count); | 160 url_info.set_typed_count(cur.typed_count); |
| 162 url_info.set_last_visit(visit_time); | 161 url_info.set_last_visit(visit_time); |
| 163 url_info.set_hidden(false); | 162 url_info.set_hidden(false); |
| 164 index->UpdateURL(i, url_info); | 163 index->UpdateURL(url_info); |
| 165 } | 164 } |
| 166 | |
| 167 provider_->set_index(index); | |
| 168 } | 165 } |
| 169 | 166 |
| 170 HistoryQuickProviderTest::SetShouldContain::SetShouldContain( | 167 HistoryQuickProviderTest::SetShouldContain::SetShouldContain( |
| 171 const ACMatches& matched_urls) { | 168 const ACMatches& matched_urls) { |
| 172 for (ACMatches::const_iterator iter = matched_urls.begin(); | 169 for (ACMatches::const_iterator iter = matched_urls.begin(); |
| 173 iter != matched_urls.end(); ++iter) | 170 iter != matched_urls.end(); ++iter) |
| 174 matches_.insert(iter->destination_url.spec()); | 171 matches_.insert(iter->destination_url.spec()); |
| 175 } | 172 } |
| 176 | 173 |
| 177 void HistoryQuickProviderTest::SetShouldContain::operator()( | 174 void HistoryQuickProviderTest::SetShouldContain::operator()( |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 kMaxNonInliningScore - 1); | 417 kMaxNonInliningScore - 1); |
| 421 EXPECT_EQ(next_score, kMaxNonInliningScore - 2); | 418 EXPECT_EQ(next_score, kMaxNonInliningScore - 2); |
| 422 | 419 |
| 423 // Low score, can inline, not clamped. | 420 // Low score, can inline, not clamped. |
| 424 next_score = 1500; | 421 next_score = 1500; |
| 425 match.raw_score = 500; | 422 match.raw_score = 500; |
| 426 match.can_inline = true; | 423 match.can_inline = true; |
| 427 EXPECT_EQ(HistoryQuickProvider::CalculateRelevance(match, &next_score), 500); | 424 EXPECT_EQ(HistoryQuickProvider::CalculateRelevance(match, &next_score), 500); |
| 428 EXPECT_EQ(next_score, 499); | 425 EXPECT_EQ(next_score, 499); |
| 429 } | 426 } |
| OLD | NEW |