summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete
diff options
context:
space:
mode:
authorderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-18 21:13:13 +0000
committerderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-18 21:13:13 +0000
commitac17666d4e8076b9b076f49d1ce1822e8175409d (patch)
tree233beeeddcbc67c6d8c5e9cd1b1edb228531046d /chrome/browser/autocomplete
parentef1c5448ab2464dc6357151631a7977d7a6c8006 (diff)
downloadchromium_src-ac17666d4e8076b9b076f49d1ce1822e8175409d.zip
chromium_src-ac17666d4e8076b9b076f49d1ce1822e8175409d.tar.gz
chromium_src-ac17666d4e8076b9b076f49d1ce1822e8175409d.tar.bz2
chromeos: Delete old, unused contacts code.
This never got turned on. BUG=350213 TBR=darin@chromium.org Review URL: https://codereview.chromium.org/190063004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257754 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r--chrome/browser/autocomplete/autocomplete_controller.cc10
-rw-r--r--chrome/browser/autocomplete/autocomplete_match.cc2
-rw-r--r--chrome/browser/autocomplete/autocomplete_provider.cc4
-rw-r--r--chrome/browser/autocomplete/autocomplete_provider.h15
-rw-r--r--chrome/browser/autocomplete/contact_provider_chromeos.cc236
-rw-r--r--chrome/browser/autocomplete/contact_provider_chromeos.h77
-rw-r--r--chrome/browser/autocomplete/contact_provider_chromeos_unittest.cc283
7 files changed, 7 insertions, 620 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_controller.cc b/chrome/browser/autocomplete/autocomplete_controller.cc
index 8bb7e8b..1af794f 100644
--- a/chrome/browser/autocomplete/autocomplete_controller.cc
+++ b/chrome/browser/autocomplete/autocomplete_controller.cc
@@ -33,11 +33,6 @@
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
-#if defined(OS_CHROMEOS)
-#include "chrome/browser/autocomplete/contact_provider_chromeos.h"
-#include "chrome/browser/chromeos/contacts/contact_manager.h"
-#endif
-
namespace {
// Converts the given match to a type (and possibly subtype) based on the AQS
@@ -167,11 +162,6 @@ AutocompleteController::AutocompleteController(
providers_.push_back(new BookmarkProvider(this, profile));
if (provider_types & AutocompleteProvider::TYPE_BUILTIN)
providers_.push_back(new BuiltinProvider(this, profile));
-#if defined(OS_CHROMEOS)
- if (provider_types & AutocompleteProvider::TYPE_CONTACT)
- providers_.push_back(new ContactProvider(this, profile,
- contacts::ContactManager::GetInstance()->GetWeakPtr()));
-#endif
if (provider_types & AutocompleteProvider::TYPE_EXTENSION_APP)
providers_.push_back(new ExtensionAppProvider(this, profile));
if (provider_types & AutocompleteProvider::TYPE_HISTORY_QUICK)
diff --git a/chrome/browser/autocomplete/autocomplete_match.cc b/chrome/browser/autocomplete/autocomplete_match.cc
index 13fcdb0..4d04019 100644
--- a/chrome/browser/autocomplete/autocomplete_match.cc
+++ b/chrome/browser/autocomplete/autocomplete_match.cc
@@ -150,8 +150,6 @@ int AutocompleteMatch::TypeToIcon(Type type) {
IDR_OMNIBOX_SEARCH,
IDR_OMNIBOX_SEARCH,
IDR_OMNIBOX_EXTENSION_APP,
- // ContactProvider isn't used by the omnibox, so this icon is never
- // displayed.
IDR_OMNIBOX_SEARCH,
IDR_OMNIBOX_HTTP,
};
diff --git a/chrome/browser/autocomplete/autocomplete_provider.cc b/chrome/browser/autocomplete/autocomplete_provider.cc
index 76f5074..acd9878 100644
--- a/chrome/browser/autocomplete/autocomplete_provider.cc
+++ b/chrome/browser/autocomplete/autocomplete_provider.cc
@@ -38,8 +38,6 @@ const char* AutocompleteProvider::TypeToString(Type type) {
return "Bookmark";
case TYPE_BUILTIN:
return "Builtin";
- case TYPE_CONTACT:
- return "Contact";
case TYPE_EXTENSION_APP:
return "ExtensionApp";
case TYPE_HISTORY_QUICK:
@@ -75,8 +73,6 @@ metrics::OmniboxEventProto_ProviderType AutocompleteProvider::
return metrics::OmniboxEventProto::BOOKMARK;
case TYPE_BUILTIN:
return metrics::OmniboxEventProto::BUILTIN;
- case TYPE_CONTACT:
- return metrics::OmniboxEventProto::CONTACT;
case TYPE_EXTENSION_APP:
return metrics::OmniboxEventProto::EXTENSION_APPS;
case TYPE_HISTORY_QUICK:
diff --git a/chrome/browser/autocomplete/autocomplete_provider.h b/chrome/browser/autocomplete/autocomplete_provider.h
index 071a1fa..ef7790f 100644
--- a/chrome/browser/autocomplete/autocomplete_provider.h
+++ b/chrome/browser/autocomplete/autocomplete_provider.h
@@ -143,14 +143,13 @@ class AutocompleteProvider
enum Type {
TYPE_BOOKMARK = 1 << 0,
TYPE_BUILTIN = 1 << 1,
- TYPE_CONTACT = 1 << 2,
- TYPE_EXTENSION_APP = 1 << 3,
- TYPE_HISTORY_QUICK = 1 << 4,
- TYPE_HISTORY_URL = 1 << 5,
- TYPE_KEYWORD = 1 << 6,
- TYPE_SEARCH = 1 << 7,
- TYPE_SHORTCUTS = 1 << 8,
- TYPE_ZERO_SUGGEST = 1 << 9,
+ TYPE_EXTENSION_APP = 1 << 2,
+ TYPE_HISTORY_QUICK = 1 << 3,
+ TYPE_HISTORY_URL = 1 << 4,
+ TYPE_KEYWORD = 1 << 5,
+ TYPE_SEARCH = 1 << 6,
+ TYPE_SHORTCUTS = 1 << 7,
+ TYPE_ZERO_SUGGEST = 1 << 8,
};
AutocompleteProvider(AutocompleteProviderListener* listener,
diff --git a/chrome/browser/autocomplete/contact_provider_chromeos.cc b/chrome/browser/autocomplete/contact_provider_chromeos.cc
deleted file mode 100644
index 7a37bf0..0000000
--- a/chrome/browser/autocomplete/contact_provider_chromeos.cc
+++ /dev/null
@@ -1,236 +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/contact_provider_chromeos.h"
-
-#include <algorithm>
-#include <cmath>
-
-#include "base/i18n/break_iterator.h"
-#include "base/i18n/string_search.h"
-#include "base/strings/string16.h"
-#include "base/strings/string_split.h"
-#include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/autocomplete/autocomplete_input.h"
-#include "chrome/browser/chromeos/contacts/contact.pb.h"
-#include "chrome/browser/chromeos/contacts/contact_manager.h"
-#include "chrome/browser/profiles/profile.h"
-
-namespace {
-
-// Default affinity assigned to contacts whose |affinity| field is unset.
-// TODO(derat): Set this to something reasonable (probably 0.0) once we're
-// getting affinity for contacts.
-float kDefaultAffinity = 1.0;
-
-// Base match relevance assigned to a contact with an affinity of 0.0.
-int kBaseRelevance = 1300;
-
-// Maximum boost to relevance for a contact with an affinity of 1.0.
-int kAffinityRelevanceBoost = 200;
-
-// Returns true if |word_to_find| is a prefix of |name_to_search| and marks the
-// matching text in |classifications| (which corresponds to the contact's full
-// name). |name_index_in_full_name| contains |name_to_search|'s index within
-// the full name or base::string16::npos if it doesn't appear in it.
-bool WordIsNamePrefix(const base::string16& word_to_find,
- const base::string16& name_to_search,
- size_t name_index_in_full_name,
- size_t full_name_length,
- ACMatchClassifications* classifications) {
- DCHECK(classifications);
-
- size_t match_index = 0;
- size_t match_length = 0;
- if (!base::i18n::StringSearchIgnoringCaseAndAccents(word_to_find,
- name_to_search, &match_index, &match_length) || (match_index != 0))
- return false;
-
- if (name_index_in_full_name != base::string16::npos) {
- AutocompleteMatch::ACMatchClassifications new_class;
- AutocompleteMatch::ClassifyLocationInString(name_index_in_full_name,
- match_length, full_name_length, 0, &new_class);
- *classifications = AutocompleteMatch::MergeClassifications(
- *classifications, new_class);
- }
-
- return true;
-}
-
-} // namespace
-
-// static
-const char ContactProvider::kMatchContactIdKey[] = "contact_id";
-
-// Cached information about a contact.
-struct ContactProvider::ContactData {
- ContactData(const base::string16& full_name,
- const base::string16& given_name,
- const base::string16& family_name,
- const std::string& contact_id,
- float affinity)
- : full_name(full_name),
- given_name(given_name),
- family_name(family_name),
- given_name_index(base::string16::npos),
- family_name_index(base::string16::npos),
- contact_id(contact_id),
- affinity(affinity) {
- base::i18n::StringSearchIgnoringCaseAndAccents(
- given_name, full_name, &given_name_index, NULL);
- base::i18n::StringSearchIgnoringCaseAndAccents(
- family_name, full_name, &family_name_index, NULL);
- }
-
- base::string16 full_name;
- base::string16 given_name;
- base::string16 family_name;
-
- // Indices into |full_name| where |given_name| and |family_name| first appear,
- // or base::string16::npos if they don't appear in it.
- size_t given_name_index;
- size_t family_name_index;
-
- // Unique ID used to look up additional contact information.
- std::string contact_id;
-
- // Affinity between the user and this contact, in the range [0.0, 1.0].
- float affinity;
-};
-
-ContactProvider::ContactProvider(
- AutocompleteProviderListener* listener,
- Profile* profile,
- base::WeakPtr<contacts::ContactManagerInterface> contact_manager)
- : AutocompleteProvider(listener, profile, TYPE_CONTACT),
- contact_manager_(contact_manager) {
- contact_manager_->AddObserver(this, profile);
- RefreshContacts();
-}
-
-void ContactProvider::Start(const AutocompleteInput& input,
- bool minimal_changes) {
- if (minimal_changes)
- return;
-
- matches_.clear();
-
- if (input.type() != AutocompleteInput::UNKNOWN &&
- input.type() != AutocompleteInput::QUERY &&
- input.type() != AutocompleteInput::FORCED_QUERY)
- return;
-
- std::vector<base::string16> input_words;
- base::i18n::BreakIterator break_iterator(
- input.text(),
- base::i18n::BreakIterator::BREAK_WORD);
- if (break_iterator.Init()) {
- while (break_iterator.Advance()) {
- if (break_iterator.IsWord())
- input_words.push_back(break_iterator.GetString());
- }
- }
-
- // |contacts_| is ordered by descending affinity. Since affinity is currently
- // the only signal used for computing relevance, we can stop after we've found
- // kMaxMatches results.
- for (ContactDataVector::const_iterator it = contacts_.begin();
- it != contacts_.end() && matches_.size() < kMaxMatches; ++it)
- AddContactIfMatched(input, input_words, *it);
-}
-
-void ContactProvider::OnContactsUpdated(Profile* profile) {
- DCHECK_EQ(profile, profile_);
- RefreshContacts();
-}
-
-ContactProvider::~ContactProvider() {
- // Like ContactProvider, ContactManager gets destroyed at profile destruction.
- // Make sure that this class doesn't try to access ContactManager after
- // ContactManager is gone.
- if (contact_manager_.get())
- contact_manager_->RemoveObserver(this, profile_);
-}
-
-// static
-bool ContactProvider::CompareAffinity(const ContactData& a,
- const ContactData& b) {
- return a.affinity > b.affinity;
-}
-
-void ContactProvider::RefreshContacts() {
- if (!contact_manager_.get())
- return;
-
- scoped_ptr<contacts::ContactPointers> contacts =
- contact_manager_->GetAllContacts(profile_);
-
- contacts_.clear();
- contacts_.reserve(contacts->size());
- for (contacts::ContactPointers::const_iterator it = contacts->begin();
- it != contacts->end(); ++it) {
- const contacts::Contact& contact = **it;
- base::string16 full_name = AutocompleteMatch::SanitizeString(
- base::UTF8ToUTF16(contact.full_name()));
- base::string16 given_name = AutocompleteMatch::SanitizeString(
- base::UTF8ToUTF16(contact.given_name()));
- base::string16 family_name = AutocompleteMatch::SanitizeString(
- base::UTF8ToUTF16(contact.family_name()));
- float affinity =
- contact.has_affinity() ? contact.affinity() : kDefaultAffinity;
-
- if (!full_name.empty()) {
- contacts_.push_back(
- ContactData(full_name, given_name, family_name, contact.contact_id(),
- affinity));
- }
- }
- std::sort(contacts_.begin(), contacts_.end(), CompareAffinity);
-}
-
-void ContactProvider::AddContactIfMatched(
- const AutocompleteInput& input,
- const std::vector<base::string16>& input_words,
- const ContactData& contact) {
- // First, check if the whole input string is a prefix of the full name.
- // TODO(derat): Consider additionally segmenting the full name so we can match
- // e.g. middle names or initials even when they aren't typed as a prefix of
- // the full name.
- ACMatchClassifications classifications;
- if (!WordIsNamePrefix(input.text(), contact.full_name, 0,
- contact.full_name.size(), &classifications)) {
- // If not, check whether every search term is a prefix of the given name
- // or the family name.
- if (input_words.empty())
- return;
-
- // TODO(derat): Check new matches against previous ones to make sure they
- // don't overlap (e.g. the query "bob b" against a contact with full name
- // "Bob G. Bryson", given name "Bob", and family name "Bryson" should result
- // in classifications "_Bob_ G. _B_ryson" rather than "_Bob_ G. Bryson".
- for (std::vector<base::string16>::const_iterator it = input_words.begin();
- it != input_words.end(); ++it) {
- if (!WordIsNamePrefix(*it, contact.given_name, contact.given_name_index,
- contact.full_name.size(), &classifications) &&
- !WordIsNamePrefix(*it, contact.family_name, contact.family_name_index,
- contact.full_name.size(), &classifications))
- return;
- }
- }
-
- matches_.push_back(CreateAutocompleteMatch(input, contact));
- matches_.back().contents_class = classifications;
-}
-
-AutocompleteMatch ContactProvider::CreateAutocompleteMatch(
- const AutocompleteInput& input,
- const ContactData& contact) {
- AutocompleteMatch match(this, 0, false, AutocompleteMatchType::CONTACT);
- match.contents = contact.full_name;
- match.fill_into_edit = match.contents;
- match.relevance = kBaseRelevance +
- static_cast<int>(roundf(kAffinityRelevanceBoost * contact.affinity));
- match.RecordAdditionalInfo(kMatchContactIdKey, contact.contact_id);
- return match;
-}
diff --git a/chrome/browser/autocomplete/contact_provider_chromeos.h b/chrome/browser/autocomplete/contact_provider_chromeos.h
deleted file mode 100644
index 9ecb9db..0000000
--- a/chrome/browser/autocomplete/contact_provider_chromeos.h
+++ /dev/null
@@ -1,77 +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_CONTACT_PROVIDER_CHROMEOS_H_
-#define CHROME_BROWSER_AUTOCOMPLETE_CONTACT_PROVIDER_CHROMEOS_H_
-
-#include <utility>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "base/memory/weak_ptr.h"
-#include "chrome/browser/autocomplete/autocomplete_match.h"
-#include "chrome/browser/autocomplete/autocomplete_provider.h"
-#include "chrome/browser/chromeos/contacts/contact_manager_observer.h"
-
-class AutocompleteInput;
-
-namespace contacts {
-class ContactManagerInterface;
-}
-
-// AutocompleteProvider implementation that searches through the contacts
-// provided by contacts::ContactManager.
-class ContactProvider : public AutocompleteProvider,
- public contacts::ContactManagerObserver {
- public:
- // Key within AutocompleteMatch::additional_info where the corresponding
- // contact's ID is stored.
- static const char kMatchContactIdKey[];
-
- ContactProvider(
- AutocompleteProviderListener* listener,
- Profile* profile,
- base::WeakPtr<contacts::ContactManagerInterface> contact_manager);
-
- // AutocompleteProvider overrides:
- virtual void Start(const AutocompleteInput& input,
- bool minimal_changes) OVERRIDE;
-
- // contacts::ContactManagerObserver overrides:
- virtual void OnContactsUpdated(Profile* profile) OVERRIDE;
-
- private:
- struct ContactData;
- typedef std::vector<ContactData> ContactDataVector;
-
- virtual ~ContactProvider();
-
- // Returns true if |a|'s affinity is greater than |b|'s affinity.
- static bool CompareAffinity(const ContactData& a, const ContactData& b);
-
- // Updates |contacts_| to match the contacts currently reported by
- // ContactManager.
- void RefreshContacts();
-
- // Adds an AutocompleteMatch object for |contact| to |matches_| if |contact|
- // is matched by |input|. |input_words| is |input.text()| split on word
- // boundaries.
- void AddContactIfMatched(const AutocompleteInput& input,
- const std::vector<base::string16>& input_words,
- const ContactData& contact);
-
- // Returns an AutocompleteMatch object corresponding to the passed-in data.
- AutocompleteMatch CreateAutocompleteMatch(const AutocompleteInput& input,
- const ContactData& contact);
-
- base::WeakPtr<contacts::ContactManagerInterface> contact_manager_;
-
- // Contacts through which we search, ordered by descending affinity.
- ContactDataVector contacts_;
-
- DISALLOW_COPY_AND_ASSIGN(ContactProvider);
-};
-
-#endif // CHROME_BROWSER_AUTOCOMPLETE_CONTACT_PROVIDER_CHROMEOS_H_
diff --git a/chrome/browser/autocomplete/contact_provider_chromeos_unittest.cc b/chrome/browser/autocomplete/contact_provider_chromeos_unittest.cc
deleted file mode 100644
index 7e344f3..0000000
--- a/chrome/browser/autocomplete/contact_provider_chromeos_unittest.cc
+++ /dev/null
@@ -1,283 +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/contact_provider_chromeos.h"
-
-#include <cmath>
-#include <map>
-#include <string>
-#include <vector>
-
-#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
-#include "base/strings/string16.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/autocomplete/autocomplete_input.h"
-#include "chrome/browser/autocomplete/autocomplete_match.h"
-#include "chrome/browser/autocomplete/autocomplete_provider.h"
-#include "chrome/browser/chromeos/contacts/contact.pb.h"
-#include "chrome/browser/chromeos/contacts/contact_manager_stub.h"
-#include "chrome/browser/chromeos/contacts/contact_test_util.h"
-#include "chrome/test/base/testing_browser_process.h"
-#include "chrome/test/base/testing_profile.h"
-#include "chrome/test/base/testing_profile_manager.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/test/test_browser_thread.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using content::BrowserThread;
-
-namespace {
-
-// Initializes |contact| with the passed-in data.
-void InitContact(const std::string& contact_id,
- const std::string& full_name,
- const std::string& given_name,
- const std::string& family_name,
- contacts::Contact* contact) {
- contact->set_contact_id(contact_id);
- contact->set_full_name(full_name);
- contact->set_given_name(given_name);
- contact->set_family_name(family_name);
-}
-
-} // namespace
-
-class ContactProviderTest : public testing::Test {
- public:
- ContactProviderTest() : ui_thread_(BrowserThread::UI, &message_loop_) {}
- virtual ~ContactProviderTest() {}
-
- protected:
- // testing::Test implementation.
- virtual void SetUp() OVERRIDE {
- profile_manager_.reset(
- new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
- ASSERT_TRUE(profile_manager_->SetUp());
- profile_ = profile_manager_->CreateTestingProfile("test_profile");
- contact_manager_.reset(new contacts::ContactManagerStub(profile_));
- contact_provider_ =
- new ContactProvider(NULL, profile_, contact_manager_->GetWeakPtr());
- }
-
- // Starts a (synchronous) query for |utf8_text| in |contact_provider_|.
- void StartQuery(const std::string& utf8_text) {
- contact_provider_->Start(
- AutocompleteInput(base::UTF8ToUTF16(utf8_text),
- base::string16::npos,
- base::string16(),
- GURL(),
- AutocompleteInput::INVALID_SPEC,
- false,
- false,
- false,
- AutocompleteInput::ALL_MATCHES),
- false); // minimal_changes
- }
-
- // Returns the contact ID in |match|'s additional info, or an empty string if
- // no ID is present.
- std::string GetContactIdFromMatch(const AutocompleteMatch& match) {
- AutocompleteMatch::AdditionalInfo::const_iterator it =
- match.additional_info.find(ContactProvider::kMatchContactIdKey);
- return it != match.additional_info.end() ? it->second : std::string();
- }
-
- // Returns pointers to all of the Contact objects referenced in
- // |contact_provider_|'s current results.
- contacts::ContactPointers GetMatchedContacts() {
- contacts::ContactPointers contacts;
- const ACMatches& matches = contact_provider_->matches();
- for (size_t i = 0; i < matches.size(); ++i) {
- const contacts::Contact* contact = contact_manager_->GetContactById(
- profile_, GetContactIdFromMatch(matches[i]));
- DCHECK(contact) << "Unable to find contact for match " << i;
- contacts.push_back(contact);
- }
- return contacts;
- }
-
- // Returns a semicolon-separated string containing string representations (as
- // provided by AutocompleteMatch::ClassificationsToString()) of the
- // |contents_class| fields of all current matches. Results are sorted by
- // contact ID.
- std::string GetMatchClassifications() {
- typedef std::map<std::string, std::string> StringMap;
- StringMap contact_id_classifications;
- const ACMatches& matches = contact_provider_->matches();
- for (size_t i = 0; i < matches.size(); ++i) {
- std::string id = GetContactIdFromMatch(matches[i]);
- DCHECK(!id.empty()) << "Match " << i << " lacks contact ID";
- contact_id_classifications[id] = AutocompleteMatch::
- ClassificationsToString(matches[i].contents_class);
- }
-
- std::string result;
- for (StringMap::const_iterator it = contact_id_classifications.begin();
- it != contact_id_classifications.end(); ++it) {
- if (!result.empty())
- result += ";";
- result += it->second;
- }
- return result;
- }
-
- base::MessageLoopForUI message_loop_;
- content::TestBrowserThread ui_thread_;
-
- scoped_ptr<TestingProfileManager> profile_manager_;
- TestingProfile* profile_;
-
- scoped_ptr<contacts::ContactManagerStub> contact_manager_;
- scoped_refptr<ContactProvider> contact_provider_;
-};
-
-TEST_F(ContactProviderTest, BasicMatching) {
- const std::string kContactId1 = "contact_1";
- scoped_ptr<contacts::Contact> contact1(new contacts::Contact);
- InitContact(kContactId1, "Bob Smith", "Bob", "Smith", contact1.get());
-
- const std::string kContactId2 = "contact_2";
- scoped_ptr<contacts::Contact> contact2(new contacts::Contact);
- InitContact(kContactId2, "Dr. Jane Smith", "Jane", "Smith", contact2.get());
-
- contacts::ContactPointers contacts;
- contacts.push_back(contact1.get());
- contacts.push_back(contact2.get());
- contact_manager_->SetContacts(contacts);
- contact_manager_->NotifyObserversAboutUpdatedContacts();
-
- StartQuery("b");
- EXPECT_EQ(
- contacts::test::VarContactsToString(1, contact1.get()),
- contacts::test::ContactsToString(GetMatchedContacts()));
- EXPECT_EQ("0,2,1,0", GetMatchClassifications());
-
- StartQuery("bob");
- EXPECT_EQ(
- contacts::test::VarContactsToString(1, contact1.get()),
- contacts::test::ContactsToString(GetMatchedContacts()));
- EXPECT_EQ("0,2,3,0", GetMatchClassifications());
-
- StartQuery("bob smith");
- EXPECT_EQ(
- contacts::test::VarContactsToString(1, contact1.get()),
- contacts::test::ContactsToString(GetMatchedContacts()));
- EXPECT_EQ("0,2", GetMatchClassifications());
-
- StartQuery("sm");
- EXPECT_EQ(
- contacts::test::VarContactsToString(2, contact1.get(), contact2.get()),
- contacts::test::ContactsToString(GetMatchedContacts()));
- EXPECT_EQ("0,0,4,2,6,0;" "0,0,9,2,11,0", GetMatchClassifications());
-
- StartQuery("smith");
- EXPECT_EQ(
- contacts::test::VarContactsToString(2, contact1.get(), contact2.get()),
- contacts::test::ContactsToString(GetMatchedContacts()));
- EXPECT_EQ("0,0,4,2;" "0,0,9,2", GetMatchClassifications());
-
- StartQuery("smIth BOb");
- EXPECT_EQ(
- contacts::test::VarContactsToString(1, contact1.get()),
- contacts::test::ContactsToString(GetMatchedContacts()));
- EXPECT_EQ("0,2,3,0,4,2", GetMatchClassifications());
-
- StartQuery("bobo");
- EXPECT_EQ("", contacts::test::ContactsToString(GetMatchedContacts()));
- EXPECT_EQ("", GetMatchClassifications());
-
- StartQuery("mith");
- EXPECT_EQ("", contacts::test::ContactsToString(GetMatchedContacts()));
- EXPECT_EQ("", GetMatchClassifications());
-
- StartQuery("dr");
- EXPECT_EQ(
- contacts::test::VarContactsToString(1, contact2.get()),
- contacts::test::ContactsToString(GetMatchedContacts()));
- EXPECT_EQ("0,2,2,0", GetMatchClassifications());
-
- StartQuery("dr. j");
- EXPECT_EQ(
- contacts::test::VarContactsToString(1, contact2.get()),
- contacts::test::ContactsToString(GetMatchedContacts()));
- EXPECT_EQ("0,2,5,0", GetMatchClassifications());
-
- StartQuery("jane");
- EXPECT_EQ(
- contacts::test::VarContactsToString(1, contact2.get()),
- contacts::test::ContactsToString(GetMatchedContacts()));
- EXPECT_EQ("0,0,4,2,8,0", GetMatchClassifications());
-}
-
-TEST_F(ContactProviderTest, Collation) {
- scoped_ptr<contacts::Contact> contact(new contacts::Contact);
- InitContact("1", "Bj\xC3\xB6rn Adelsv\xC3\xA4rd",
- "Bj\xC3\xB6rn", "Adelsv\xC3\xA4rd",
- contact.get());
-
- contacts::ContactPointers contacts;
- contacts.push_back(contact.get());
- contact_manager_->SetContacts(contacts);
- contact_manager_->NotifyObserversAboutUpdatedContacts();
-
- StartQuery("bjorn");
- EXPECT_EQ(
- contacts::test::VarContactsToString(1, contact.get()),
- contacts::test::ContactsToString(GetMatchedContacts()));
- EXPECT_EQ("0,2,5,0", GetMatchClassifications());
-
- StartQuery("adelsvard");
- EXPECT_EQ(
- contacts::test::VarContactsToString(1, contact.get()),
- contacts::test::ContactsToString(GetMatchedContacts()));
- EXPECT_EQ("0,0,6,2", GetMatchClassifications());
-}
-
-TEST_F(ContactProviderTest, Relevance) {
- // Create more contacts than the maximum number of results that an
- // AutocompleteProvider should return. Give them all the same family name and
- // ascending affinities from 0.0 to 1.0.
- const size_t kNumContacts = AutocompleteProvider::kMaxMatches + 1;
- const std::string kFamilyName = "Jones";
-
- ScopedVector<contacts::Contact> contacts;
- contacts::ContactPointers contact_pointers;
- for (size_t i = 0; i < kNumContacts; ++i) {
- contacts::Contact* contact = new contacts::Contact;
- std::string id_string = base::IntToString(static_cast<int>(i));
- InitContact(id_string, id_string, kFamilyName,
- id_string + " " + kFamilyName, contact);
- contact->set_affinity(static_cast<float>(i) / kNumContacts);
- contacts.push_back(contact);
- contact_pointers.push_back(contact);
- }
-
- contact_manager_->SetContacts(contact_pointers);
- contact_manager_->NotifyObserversAboutUpdatedContacts();
-
- // Do a search for the family name and check that the total number of results
- // is limited as expected and that the results are ordered by descending
- // affinity.
- StartQuery(kFamilyName);
- const ACMatches& matches = contact_provider_->matches();
- ASSERT_EQ(AutocompleteProvider::kMaxMatches, matches.size());
-
- int previous_relevance = 0;
- for (size_t i = 0; i < matches.size(); ++i) {
- const contacts::Contact& exp_contact =
- *(contacts[kNumContacts - 1 - i]);
- std::string match_id = GetContactIdFromMatch(matches[i]);
- EXPECT_EQ(exp_contact.contact_id(), match_id)
- << "Expected contact ID " << exp_contact.contact_id()
- << " for match " << i << " but got " << match_id << " instead";
- if (i > 0) {
- EXPECT_LE(matches[i].relevance, previous_relevance)
- << "Match " << i << " has greater relevance than previous match";
- }
- EXPECT_FALSE(matches[i].allowed_to_be_default_match);
- previous_relevance = matches[i].relevance;
- }
-}