diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-14 21:34:32 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-14 21:34:32 +0000 |
commit | 9d2b5f3b2a8640c6fbb067b16cb22eb0d081568e (patch) | |
tree | 90bb6891dd794d538dcea68e3ba27b0c31fa9fee /chrome/browser/autocomplete | |
parent | 8579b5cac19f736f344fb8354448d469ccaf23ec (diff) | |
download | chromium_src-9d2b5f3b2a8640c6fbb067b16cb22eb0d081568e.zip chromium_src-9d2b5f3b2a8640c6fbb067b16cb22eb0d081568e.tar.gz chromium_src-9d2b5f3b2a8640c6fbb067b16cb22eb0d081568e.tar.bz2 |
Clean up ShortcutsProvider and related classes:
* Move SpansToString()/SpansFromString() and AddLastMatchIfNeeded() from static functions in shortcuts_provider_shortcut.cc to static members on AutocompleteMatch and rename them, to go along with the other existing classification-related functions there, since there's nothing particularly shortcut-related about them.
* Move the definitions of Shortcut and ShortcutMap to the ShortcutsBackend, mainly to "namespace" them -- having a global-scope type named "Shortcut" didn't seem like a good idea. This made sense as a location anyway since the backend already depended heavily on these types.
* Eliminate using statements.
* Modify ShortcutsProviderTest::FillData() so it can be reused in an additional place.
* Shortcut had two different constructors whose function and use was confusing and error-prone -- they took some of the same fields but as different types, and didn't guarantee all the members were initialized. Condense to one constructor which takes the most logical types and sets all members.
* Eliminate ShortcutsBackend::guid_map() (unused).
* Simplify/clarify code.
* Eliminate 2K clamp on shortcut data fields. We don't clamp like this elsewhere, and if the clamp kicks in, it could lead to corrupted results -- e.g. trimming a "description" field but not updating the classifications for that field.
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/9689085
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126743 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
7 files changed, 111 insertions, 296 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_match.cc b/chrome/browser/autocomplete/autocomplete_match.cc index 14684a5..4d4f256 100644 --- a/chrome/browser/autocomplete/autocomplete_match.cc +++ b/chrome/browser/autocomplete/autocomplete_match.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/logging.h" +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "chrome/browser/autocomplete/autocomplete_match.h" #include "chrome/browser/search_engines/template_url.h" @@ -216,6 +217,53 @@ void AutocompleteMatch::ClassifyLocationInString( } // static +std::string AutocompleteMatch::ClassificationsToString( + const ACMatchClassifications& classifications) { + std::string serialized_classifications; + for (size_t i = 0; i < classifications.size(); ++i) { + if (i) + serialized_classifications += ','; + serialized_classifications += base::IntToString(classifications[i].offset) + + ',' + base::IntToString(classifications[i].style); + } + return serialized_classifications; +} + +// static +ACMatchClassifications AutocompleteMatch::ClassificationsFromString( + const std::string& serialized_classifications) { + ACMatchClassifications classifications; + std::vector<std::string> tokens; + Tokenize(serialized_classifications, ",", &tokens); + DCHECK(!(tokens.size() & 1)); // The number of tokens should be even. + for (size_t i = 0; i < tokens.size(); i += 2) { + int classification_offset = 0; + int classification_style = ACMatchClassification::NONE; + if (!base::StringToInt(tokens[i], &classification_offset) || + !base::StringToInt(tokens[i + 1], &classification_style)) { + NOTREACHED(); + return classifications; + } + classifications.push_back(ACMatchClassification(classification_offset, + classification_style)); + } + return classifications; +} + +// static +void AutocompleteMatch::AddLastClassificationIfNecessary( + ACMatchClassifications* classifications, + size_t offset, + int style) { + DCHECK(classifications); + if (classifications->empty() || classifications->back().style != style) { + DCHECK(classifications->empty() || + (offset > classifications->back().offset)); + classifications->push_back(ACMatchClassification(offset, style)); + } +} + +// static string16 AutocompleteMatch::SanitizeString(const string16& text) { // NOTE: This logic is mirrored by |sanitizeString()| in // schema_generated_bindings.js. diff --git a/chrome/browser/autocomplete/autocomplete_match.h b/chrome/browser/autocomplete/autocomplete_match.h index 096ee71..a0260ae 100644 --- a/chrome/browser/autocomplete/autocomplete_match.h +++ b/chrome/browser/autocomplete/autocomplete_match.h @@ -134,6 +134,21 @@ struct AutocompleteMatch { int style, ACMatchClassifications* classifications); + // Converts classifications to and from a serialized string representation + // (using comma-separated integers to sequentially list positions and styles). + static std::string ClassificationsToString( + const ACMatchClassifications& classifications); + static ACMatchClassifications ClassificationsFromString( + const std::string& serialized_classifications); + + // Adds a classification to the end of |classifications| iff its style is + // different from the last existing classification. |offset| must be larger + // than the offset of the last classification in |classifications|. + static void AddLastClassificationIfNecessary( + ACMatchClassifications* classifications, + size_t offset, + int style); + // Removes invalid characters from |text|. Should be called on strings coming // from external sources (such as extensions) before assigning to |contents| // or |description|. diff --git a/chrome/browser/autocomplete/shortcuts_provider.cc b/chrome/browser/autocomplete/shortcuts_provider.cc index bbc02e7b..96bb9d1 100644 --- a/chrome/browser/autocomplete/shortcuts_provider.cc +++ b/chrome/browser/autocomplete/shortcuts_provider.cc @@ -30,9 +30,6 @@ #include "net/base/escape.h" #include "net/base/net_util.h" -using shortcuts_provider::Shortcut; -using shortcuts_provider::ShortcutMap; - namespace { class RemoveMatchPredicate { @@ -137,10 +134,11 @@ void ShortcutsProvider::GetMatches(const AutocompleteInput& input) { string16 term_string(base::i18n::ToLower(input.text())); DCHECK(!term_string.empty()); - for (ShortcutMap::const_iterator it = FindFirstMatch(term_string); + for (history::ShortcutsBackend::ShortcutMap::const_iterator it = + FindFirstMatch(term_string); it != shortcuts_backend_->shortcuts_map().end() && StartsWith(it->first, term_string, true); ++it) - matches_.push_back(ShortcutToACMatch(input, term_string, it)); + matches_.push_back(ShortcutToACMatch(input, term_string, it->second)); std::partial_sort(matches_.begin(), matches_.begin() + std::min(AutocompleteProvider::kMaxMatches, matches_.size()), @@ -154,21 +152,21 @@ void ShortcutsProvider::GetMatches(const AutocompleteInput& input) { AutocompleteMatch ShortcutsProvider::ShortcutToACMatch( const AutocompleteInput& input, const string16& term_string, - ShortcutMap::const_iterator it) { - AutocompleteMatch match(this, CalculateScore(term_string, it->second), + const history::ShortcutsBackend::Shortcut& shortcut) { + AutocompleteMatch match(this, CalculateScore(term_string, shortcut), true, AutocompleteMatch::HISTORY_TITLE); - match.destination_url = it->second.url; + match.destination_url = shortcut.url; DCHECK(match.destination_url.is_valid()); - match.fill_into_edit = UTF8ToUTF16(it->second.url.spec()); + match.fill_into_edit = UTF8ToUTF16(shortcut.url.spec()); - match.contents = it->second.contents; + match.contents = shortcut.contents; match.contents_class = ClassifyAllMatchesInString(term_string, match.contents, - it->second.contents_class); + shortcut.contents_class); - match.description = it->second.description; + match.description = shortcut.description; match.description_class = ClassifyAllMatchesInString( - term_string, match.description, it->second.description_class); + term_string, match.description, shortcut.description_class); return match; } @@ -223,11 +221,11 @@ ACMatchClassifications ShortcutsProvider::ClassifyAllMatchesInString( if (!match_class.empty() && match_class.back().offset == match_start) match_class.pop_back(); - shortcuts_provider::AddLastMatchIfNeeded(&match_class, match_start, - ACMatchClassification::MATCH); + AutocompleteMatch::AddLastClassificationIfNecessary(&match_class, + match_start, ACMatchClassification::MATCH); if (match_end < text_lowercase.length()) { - shortcuts_provider::AddLastMatchIfNeeded(&match_class, match_end, - ACMatchClassification::NONE); + AutocompleteMatch::AddLastClassificationIfNecessary(&match_class, + match_end, ACMatchClassification::NONE); } last_position = match_end; @@ -240,9 +238,8 @@ ACMatchClassifications ShortcutsProvider::ClassifyAllMatchesInString( ACMatchClassifications output; for (ACMatchClassifications::const_iterator i = original_class.begin(), j = match_class.begin(); i != original_class.end();) { - shortcuts_provider::AddLastMatchIfNeeded(&output, - std::max(i->offset, j->offset), - i->style | j->style); + AutocompleteMatch::AddLastClassificationIfNecessary(&output, + std::max(i->offset, j->offset), i->style | j->style); const size_t next_i_offset = (i + 1) == original_class.end() ? static_cast<size_t>(-1) : (i + 1)->offset; const size_t next_j_offset = (j + 1) == match_class.end() ? @@ -256,9 +253,9 @@ ACMatchClassifications ShortcutsProvider::ClassifyAllMatchesInString( return output; } -ShortcutMap::const_iterator ShortcutsProvider::FindFirstMatch( - const string16& keyword) { - ShortcutMap::const_iterator it = +history::ShortcutsBackend::ShortcutMap::const_iterator + ShortcutsProvider::FindFirstMatch(const string16& keyword) { + history::ShortcutsBackend::ShortcutMap::const_iterator it = shortcuts_backend_->shortcuts_map().lower_bound(keyword); // Lower bound not necessarily matches the keyword, check for item pointed by // the lower bound iterator to at least start with keyword. @@ -268,8 +265,9 @@ ShortcutMap::const_iterator ShortcutsProvider::FindFirstMatch( } // static -int ShortcutsProvider::CalculateScore(const string16& terms, - const Shortcut& shortcut) { +int ShortcutsProvider::CalculateScore( + const string16& terms, + const history::ShortcutsBackend::Shortcut& shortcut) { DCHECK(!terms.empty()); DCHECK_LE(terms.length(), shortcut.text.length()); diff --git a/chrome/browser/autocomplete/shortcuts_provider.h b/chrome/browser/autocomplete/shortcuts_provider.h index d5e1129..46260de 100644 --- a/chrome/browser/autocomplete/shortcuts_provider.h +++ b/chrome/browser/autocomplete/shortcuts_provider.h @@ -6,16 +6,13 @@ #define CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_H_ #pragma once -#include <map> #include <set> #include <string> -#include <vector> #include "base/gtest_prod_util.h" #include "base/time.h" #include "chrome/browser/autocomplete/autocomplete_match.h" #include "chrome/browser/autocomplete/history_provider.h" -#include "chrome/browser/autocomplete/shortcuts_provider_shortcut.h" #include "chrome/browser/history/shortcuts_backend.h" class Profile; @@ -56,7 +53,7 @@ class ShortcutsProvider AutocompleteMatch ShortcutToACMatch( const AutocompleteInput& input, const string16& terms, - shortcuts_provider::ShortcutMap::const_iterator it); + const history::ShortcutsBackend::Shortcut& shortcut); // Given |text| and a corresponding base set of classifications // |original_class|, adds ACMatchClassification::MATCH markers for all @@ -76,11 +73,12 @@ class ShortcutsProvider // Returns iterator to first item in |shortcuts_map_| matching |keyword|. // Returns shortcuts_map_.end() if there are no matches. - shortcuts_provider::ShortcutMap::const_iterator FindFirstMatch( + history::ShortcutsBackend::ShortcutMap::const_iterator FindFirstMatch( const string16& keyword); - static int CalculateScore(const string16& terms, - const shortcuts_provider::Shortcut& shortcut); + static int CalculateScore( + const string16& terms, + const history::ShortcutsBackend::Shortcut& shortcut); // For unit-test only. void set_shortcuts_backend(history::ShortcutsBackend* shortcuts_backend); diff --git a/chrome/browser/autocomplete/shortcuts_provider_shortcut.cc b/chrome/browser/autocomplete/shortcuts_provider_shortcut.cc deleted file mode 100644 index 634c9a3..0000000 --- a/chrome/browser/autocomplete/shortcuts_provider_shortcut.cc +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -#include "chrome/browser/autocomplete/shortcuts_provider_shortcut.h" - -#include "base/string_number_conversions.h" -#include "base/string_util.h" -#include "base/time.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/autocomplete/shortcuts_provider.h" - -namespace { - -// Takes Match classification vector and removes all matched positions, -// compacting repetitions if necessary. -void StripMatchMarkersFromClassifications(ACMatchClassifications* matches) { - DCHECK(matches); - ACMatchClassifications unmatched; - for (ACMatchClassifications::iterator i = matches->begin(); - i != matches->end(); ++i) { - shortcuts_provider::AddLastMatchIfNeeded(&unmatched, i->offset, - i->style & ~ACMatchClassification::MATCH); - } - matches->swap(unmatched); -} - -} // namespace - -namespace shortcuts_provider { - -Shortcut::Shortcut(const string16& text, - const GURL& url, - const string16& contents, - const ACMatchClassifications& in_contents_class, - const string16& description, - const ACMatchClassifications& in_description_class) - : text(text), - url(url), - contents(contents), - contents_class(in_contents_class), - description(description), - description_class(in_description_class), - last_access_time(base::Time::Now()), - number_of_hits(1) { - StripMatchMarkersFromClassifications(&contents_class); - StripMatchMarkersFromClassifications(&description_class); -} - -Shortcut::Shortcut(const std::string& id, - const string16& text, - const string16& url, - const string16& contents, - const string16& contents_class, - const string16& description, - const string16& description_class, - int64 time_of_last_access, - int number_of_hits) - : id(id), - text(text), - url(url), - contents(contents), - contents_class(SpansFromString(contents_class)), - description(description), - description_class(SpansFromString(description_class)), - last_access_time(base::Time::FromInternalValue(time_of_last_access)), - number_of_hits(1) {} - -Shortcut::Shortcut() - : last_access_time(base::Time::Now()), - number_of_hits(0) {} - -Shortcut::~Shortcut() {} - -string16 Shortcut::contents_class_as_str() const { - return SpansToString(contents_class); -} - -string16 Shortcut::description_class_as_str() const { - return SpansToString(description_class); -} - -string16 SpansToString(const ACMatchClassifications& value) { - string16 spans; - string16 comma(ASCIIToUTF16(",")); - for (size_t i = 0; i < value.size(); ++i) { - if (i) - spans.append(comma); - spans.append(base::IntToString16(value[i].offset)); - spans.append(comma); - spans.append(base::IntToString16(value[i].style)); - } - return spans; -} - -ACMatchClassifications SpansFromString(const string16& value) { - ACMatchClassifications spans; - std::vector<string16> tokens; - Tokenize(value, ASCIIToUTF16(","), &tokens); - // The number of tokens should be even. - if ((tokens.size() & 1) == 1) { - NOTREACHED(); - return spans; - } - for (size_t i = 0; i < tokens.size(); i += 2) { - int span_start = 0; - int span_type = ACMatchClassification::NONE; - if (!base::StringToInt(tokens[i], &span_start) || - !base::StringToInt(tokens[i + 1], &span_type)) { - NOTREACHED(); - return spans; - } - spans.push_back(ACMatchClassification(span_start, span_type)); - } - return spans; -} - -// Adds match at the end if and only if its style is different from the last -// match. -void AddLastMatchIfNeeded(ACMatchClassifications* matches, - size_t position, - int style) { - DCHECK(matches); - if (matches->empty() || matches->back().style != style) { - if (!matches->empty()) - DCHECK_GT(position, matches->back().offset); - matches->push_back(ACMatchClassification(position, style)); - } -} - -} // namespace shortcuts_provider diff --git a/chrome/browser/autocomplete/shortcuts_provider_shortcut.h b/chrome/browser/autocomplete/shortcuts_provider_shortcut.h deleted file mode 100644 index aadb230..0000000 --- a/chrome/browser/autocomplete/shortcuts_provider_shortcut.h +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_SHORTCUT_H_ -#define CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_SHORTCUT_H_ -#pragma once - -#include <map> -#include <string> -#include <vector> - -#include "base/string16.h" -#include "base/time.h" -#include "chrome/browser/autocomplete/autocomplete_match.h" -#include "googleurl/src/gurl.h" - -namespace shortcuts_provider { - -// The following struct encapsulates one previously selected omnibox shortcut. -struct Shortcut { - Shortcut(const string16& text, - const GURL& url, - const string16& contents, - const ACMatchClassifications& contents_class, - const string16& description, - const ACMatchClassifications& description_class); - // This constructor is used for creation of the structure from DB data. - Shortcut(const std::string& id, - const string16& text, - const string16& url, - const string16& contents, - const string16& contents_class, - const string16& description, - const string16& description_class, - int64 time_of_last_access, - int number_of_hits); - // Required for STL, we don't use this directly. - Shortcut(); - ~Shortcut(); - - string16 contents_class_as_str() const; - string16 description_class_as_str() const; - - std::string id; // Unique guid for the shortcut. - string16 text; // The user's original input string. - GURL url; // The corresponding destination URL. - - // Contents and description from the original match, along with their - // corresponding markup. We need these in order to correctly mark which - // parts are URLs, dim, etc. However, we strip all MATCH classifications - // from these since we'll mark the matching portions ourselves as we match - // the user's current typing against these Shortcuts. - string16 contents; - ACMatchClassifications contents_class; - string16 description; - ACMatchClassifications description_class; - - base::Time last_access_time; // Last time shortcut was selected. - int number_of_hits; // How many times shortcut was selected. -}; - -// Maps the original match (|text| in the Shortcut) to Shortcut for quick -// search. -typedef std::multimap<string16, Shortcut> ShortcutMap; - -// Quick access guid maps - first one for loading, the second one is a shadow -// map for access. -typedef std::map<std::string, Shortcut> GuidToShortcutMap; -typedef std::map<std::string, ShortcutMap::iterator> GuidToShortcutsIteratorMap; - -// Helpers dealing with database update. -// Converts spans vector to comma-separated string. -string16 SpansToString(const ACMatchClassifications& value); -// Coverts comma-separated unsigned integer values into spans vector. -ACMatchClassifications SpansFromString(const string16& value); - -// Helper for initialization and update. -// Adds match at the end if and only if its style is different from the last -// match. -void AddLastMatchIfNeeded(ACMatchClassifications* matches, - size_t position, - int style); -} // namespace shortcuts_provider - -#endif // CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_SHORTCUT_H_ diff --git a/chrome/browser/autocomplete/shortcuts_provider_unittest.cc b/chrome/browser/autocomplete/shortcuts_provider_unittest.cc index 33598b6..07d3223 100644 --- a/chrome/browser/autocomplete/shortcuts_provider_unittest.cc +++ b/chrome/browser/autocomplete/shortcuts_provider_unittest.cc @@ -28,9 +28,6 @@ #include "content/test/test_browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" -using base::Time; -using base::TimeDelta; - using content::BrowserThread; namespace { @@ -145,7 +142,7 @@ class ShortcutsProviderTest : public testing::Test, void TearDown(); // Fills test data into the provider. - void FillData(); + void FillData(TestShortcutInfo* db, size_t db_size); // Runs an autocomplete query on |text| and checks to see that the returned // results' destination URLs match those provided. |expected_urls| does not @@ -181,31 +178,24 @@ void ShortcutsProviderTest::SetUp() { mock_backend_ = new history::ShortcutsBackend(FilePath(), profile_.get()); mock_backend_->Init(); provider_->set_shortcuts_backend(mock_backend_.get()); - FillData(); + FillData(shortcut_test_db, arraysize(shortcut_test_db)); } void ShortcutsProviderTest::TearDown() { provider_ = NULL; } -void ShortcutsProviderTest::FillData() { +void ShortcutsProviderTest::FillData(TestShortcutInfo* db, size_t db_size) { DCHECK(provider_.get()); - mock_backend_->DeleteAllShortcuts(); - for (size_t i = 0; i < arraysize(shortcut_test_db); ++i) { - const TestShortcutInfo& cur = shortcut_test_db[i]; - const GURL current_url(cur.url); - Time visit_time = Time::Now() - TimeDelta::FromDays(cur.days_from_now); - shortcuts_provider::Shortcut shortcut( - ASCIIToUTF16(cur.title), - current_url, - ASCIIToUTF16(cur.contents), - shortcuts_provider::SpansFromString(ASCIIToUTF16(cur.contents_class)), + for (size_t i = 0; i < db_size; ++i) { + const TestShortcutInfo& cur = db[i]; + history::ShortcutsBackend::Shortcut shortcut(cur.guid, + ASCIIToUTF16(cur.title), GURL(cur.url), ASCIIToUTF16(cur.contents), + AutocompleteMatch::ClassificationsFromString(cur.contents_class), ASCIIToUTF16(cur.description), - shortcuts_provider::SpansFromString( - ASCIIToUTF16(cur.description_class))); - shortcut.last_access_time = visit_time; - shortcut.number_of_hits = cur.typed_count; - shortcut.id = cur.guid; + AutocompleteMatch::ClassificationsFromString(cur.description_class), + base::Time::Now() - base::TimeDelta::FromDays(cur.days_from_now), + cur.typed_count); mock_backend_->AddShortcut(shortcut); } } @@ -565,15 +555,12 @@ TEST_F(ShortcutsProviderTest, CalculateScore) { ACMatchClassification(0, ACMatchClassification::NONE)); spans_description.push_back( ACMatchClassification(2, ACMatchClassification::MATCH)); - shortcuts_provider::Shortcut shortcut(ASCIIToUTF16("test"), - GURL("http://www.test.com"), - ASCIIToUTF16("www.test.com"), - spans_content, - ASCIIToUTF16("A test"), - spans_description); + history::ShortcutsBackend::Shortcut shortcut(std::string(), + ASCIIToUTF16("test"), GURL("http://www.test.com"), + ASCIIToUTF16("www.test.com"), spans_content, ASCIIToUTF16("A test"), + spans_description, base::Time::Now(), 1); // Maximal score. - shortcut.last_access_time = Time::Now(); const int kMaxScore = ShortcutsProvider::CalculateScore( ASCIIToUTF16("test"), shortcut); @@ -589,20 +576,20 @@ TEST_F(ShortcutsProviderTest, CalculateScore) { EXPECT_LT(score_one_quarter, score_one_half); // Should decay with time - one week. - shortcut.last_access_time = Time::Now() - TimeDelta::FromDays(7); + shortcut.last_access_time = base::Time::Now() - base::TimeDelta::FromDays(7); int score_week_old = ShortcutsProvider::CalculateScore(ASCIIToUTF16("test"), shortcut); EXPECT_LT(score_week_old, kMaxScore); // Should decay more in two weeks. - shortcut.last_access_time = Time::Now() - TimeDelta::FromDays(14); + shortcut.last_access_time = base::Time::Now() - base::TimeDelta::FromDays(14); int score_two_weeks_old = ShortcutsProvider::CalculateScore(ASCIIToUTF16("test"), shortcut); EXPECT_LT(score_two_weeks_old, score_week_old); // But not if it was activly clicked on. 2 hits slow decaying power. shortcut.number_of_hits = 2; - shortcut.last_access_time = Time::Now() - TimeDelta::FromDays(14); + shortcut.last_access_time = base::Time::Now() - base::TimeDelta::FromDays(14); int score_popular_two_weeks_old = ShortcutsProvider::CalculateScore(ASCIIToUTF16("test"), shortcut); EXPECT_LT(score_two_weeks_old, score_popular_two_weeks_old); @@ -611,7 +598,7 @@ TEST_F(ShortcutsProviderTest, CalculateScore) { // 3 hits slow decaying power even more. shortcut.number_of_hits = 3; - shortcut.last_access_time = Time::Now() - TimeDelta::FromDays(14); + shortcut.last_access_time = base::Time::Now() - base::TimeDelta::FromDays(14); int score_more_popular_two_weeks_old = ShortcutsProvider::CalculateScore(ASCIIToUTF16("test"), shortcut); EXPECT_LT(score_two_weeks_old, score_more_popular_two_weeks_old); @@ -639,22 +626,7 @@ TEST_F(ShortcutsProviderTest, DeleteMatch) { size_t original_shortcuts_count = provider_->shortcuts_backend_->shortcuts_map().size(); - for (size_t i = 0; i < arraysize(shortcuts_to_test_delete); ++i) { - const TestShortcutInfo& cur = shortcuts_to_test_delete[i]; - const GURL current_url(cur.url); - Time visit_time = Time::Now() - TimeDelta::FromDays(cur.days_from_now); - shortcuts_provider::Shortcut shortcut( - ASCIIToUTF16(cur.title), - current_url, - ASCIIToUTF16(cur.contents), - shortcuts_provider::SpansFromString(ASCIIToUTF16(cur.contents_class)), - ASCIIToUTF16(cur.description), - shortcuts_provider::SpansFromString( - ASCIIToUTF16(cur.description_class))); - shortcut.last_access_time = visit_time; - shortcut.id = cur.guid; - mock_backend_->AddShortcut(shortcut); - } + FillData(shortcuts_to_test_delete, arraysize(shortcuts_to_test_delete)); EXPECT_EQ(original_shortcuts_count + 3, provider_->shortcuts_backend_->shortcuts_map().size()); |