diff options
author | skrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-10 23:29:36 +0000 |
---|---|---|
committer | skrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-10 23:29:36 +0000 |
commit | f2fe1ca87ec71708ed70382d3ef44523fb06befc (patch) | |
tree | 5fb2d4ad8ff660ba3fdcbe529bce6d2f63fb91fb | |
parent | c25ef90d9557c8430b4bc998cbf751bb8753a909 (diff) | |
download | chromium_src-f2fe1ca87ec71708ed70382d3ef44523fb06befc.zip chromium_src-f2fe1ca87ec71708ed70382d3ef44523fb06befc.tar.gz chromium_src-f2fe1ca87ec71708ed70382d3ef44523fb06befc.tar.bz2 |
Added the GetAllAutofillEntries function to the WebDatabase class in preparation for autofill sync.
BUG=30959
TEST=WebDatabaseTest.GetAllAutofillEntries
Review URL: http://codereview.chromium.org/598004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38699 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | chrome/browser/webdata/autofill_entry.cc | 5 | ||||
-rw-r--r-- | chrome/browser/webdata/autofill_entry.h | 1 | ||||
-rw-r--r-- | chrome/browser/webdata/web_database.cc | 18 | ||||
-rw-r--r-- | chrome/browser/webdata/web_database.h | 4 | ||||
-rw-r--r-- | chrome/browser/webdata/web_database_unittest.cc | 68 |
6 files changed, 97 insertions, 0 deletions
@@ -62,3 +62,4 @@ Bernard Cafarelli <voyageur@gentoo.org> Vernon Tang <vt@foilhead.net> Alexander Sulfrian <alexander@sulfrian.net> Philippe Beaudoin <philippe.beaudoin@gmail.com> +Mark Hahnenberg <mhahnenb@gmail.com> diff --git a/chrome/browser/webdata/autofill_entry.cc b/chrome/browser/webdata/autofill_entry.cc index 7e0b106..19344402 100644 --- a/chrome/browser/webdata/autofill_entry.cc +++ b/chrome/browser/webdata/autofill_entry.cc @@ -7,3 +7,8 @@ bool AutofillKey::operator==(const AutofillKey& key) const { return name_ == key.name() && value_ == key.value(); } + +bool AutofillEntry::operator==(const AutofillEntry& entry) const { + return key_ == entry.key(); +} + diff --git a/chrome/browser/webdata/autofill_entry.h b/chrome/browser/webdata/autofill_entry.h index 664cbaeb..add7201 100644 --- a/chrome/browser/webdata/autofill_entry.h +++ b/chrome/browser/webdata/autofill_entry.h @@ -33,6 +33,7 @@ class AutofillEntry { const AutofillKey& key() const { return key_; } + bool operator==(const AutofillEntry& entry) const; private: AutofillKey key_; }; diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc index 3bc0438..6642529 100644 --- a/chrome/browser/webdata/web_database.cc +++ b/chrome/browser/webdata/web_database.cc @@ -985,6 +985,24 @@ bool WebDatabase::GetCountOfFormElement(int64 pair_id, int* count) { return false; } +bool WebDatabase::GetAllAutofillEntries(std::vector<AutofillEntry>* entries) { + DCHECK(entries); + sql::Statement s(db_.GetUniqueStatement("SELECT name, value FROM autofill")); + if (!s) { + NOTREACHED() << "Statement prepare failed"; + return false; + } + + while (s.Step()) { + AutofillKey key(UTF8ToUTF16(s.ColumnString(0)), + UTF8ToUTF16(s.ColumnString(1))); + AutofillEntry entry(key); + entries->push_back(entry); + } + + return s.Succeeded(); +} + bool WebDatabase::InsertFormElement(const FormField& element, int64* pair_id) { sql::Statement s(db_.GetUniqueStatement( diff --git a/chrome/browser/webdata/web_database.h b/chrome/browser/webdata/web_database.h index d8179b1..d3ece62 100644 --- a/chrome/browser/webdata/web_database.h +++ b/chrome/browser/webdata/web_database.h @@ -16,6 +16,7 @@ #include "webkit/glue/form_field.h" class AutofillChange; +class AutofillEntry; class AutoFillProfile; class CreditCard; class FilePath; @@ -233,6 +234,9 @@ class WebDatabase { // Retrieves all profiles in the database. Caller owns the returned profiles. bool GetCreditCards(std::vector<CreditCard*>* profiles); + // Retrieves all of the entries in the autofill table. + bool GetAllAutofillEntries(std::vector<AutofillEntry>* entries); + ////////////////////////////////////////////////////////////////////////////// // // Web Apps diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc index 1b950c8..ec7cef5 100644 --- a/chrome/browser/webdata/web_database_unittest.cc +++ b/chrome/browser/webdata/web_database_unittest.cc @@ -2,7 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <list> #include <string> +#include <vector> #include "base/file_util.h" #include "base/path_service.h" @@ -1000,3 +1002,69 @@ TEST_F(WebDatabaseTest, CreditCard) { EXPECT_FALSE(db.GetCreditCardForLabel(ASCIIToUTF16("Target"), &db_creditcard)); } + +TEST_F(WebDatabaseTest, GetAllAutofillEntries) { + WebDatabase db; + + ASSERT_EQ(sql::INIT_OK, db.Init(file_)); + + // Simulate the submission of a handful of entries in a field called "Name", + // some more often than others. + AutofillChangeList changes; + EXPECT_TRUE(db.AddFormFieldValue( + FormField(string16(), + ASCIIToUTF16("Name"), + string16(), + ASCIIToUTF16("Superman")), + &changes)); + for (int i = 0; i < 5; i++) { + EXPECT_TRUE(db.AddFormFieldValue( + FormField(string16(), + ASCIIToUTF16("Name"), + string16(), + ASCIIToUTF16("Clark Kent")), + &changes)); + } + for (int i = 0; i < 3; i++) { + EXPECT_TRUE(db.AddFormFieldValue( + FormField(string16(), + ASCIIToUTF16("Name"), + string16(), + ASCIIToUTF16("Clark Sutter")), + &changes)); + } + for (int i = 0; i < 2; i++) { + EXPECT_TRUE(db.AddFormFieldValue( + FormField(string16(), + ASCIIToUTF16("Favorite Color"), + string16(), + ASCIIToUTF16("Green")), + &changes)); + } + + // we should get something along the lines of: [("Name", "Superman"), + // ("Name", "Clark Kent"), ("Name", "Clark Sutter"), + // ("Favorite Color", "Green")] + std::list<AutofillEntry> expected_entries; + AutofillKey ak1(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman")); + AutofillKey ak2(ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent")); + AutofillKey ak3(ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Sutter")); + AutofillKey ak4(ASCIIToUTF16("Favorite Color"), ASCIIToUTF16("Green")); + AutofillEntry ae1(ak1); + AutofillEntry ae2(ak2); + AutofillEntry ae3(ak3); + AutofillEntry ae4(ak4); + expected_entries.push_back(ae1); + expected_entries.push_back(ae2); + expected_entries.push_back(ae3); + expected_entries.push_back(ae4); + + std::vector<AutofillEntry> entries; + EXPECT_TRUE(db.GetAllAutofillEntries(&entries)); + + for (unsigned int i = 0; i < entries.size(); i++) { + expected_entries.remove(entries[i]); + } + + EXPECT_EQ(0U, expected_entries.size()); +} |