summaryrefslogtreecommitdiffstats
path: root/chrome/browser/webdata
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-04 19:45:04 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-04 19:45:04 +0000
commite43783403ec799f226d7b6d9dde5ecd363f0b339 (patch)
treeea812df19a608f589ae53760a4ee5c63b6cdd101 /chrome/browser/webdata
parent206167f1286d23440b8fa60dfd2bf1a8e0036ce8 (diff)
downloadchromium_src-e43783403ec799f226d7b6d9dde5ecd363f0b339.zip
chromium_src-e43783403ec799f226d7b6d9dde5ecd363f0b339.tar.gz
chromium_src-e43783403ec799f226d7b6d9dde5ecd363f0b339.tar.bz2
Autofill deprecate unique_ids in favor of guids for PersonalDataManager
Final round of unique_id deprecation. These changes migrated web_database schemas for profiles and credit cards, clean up the web_dataservice interface, bring the personal_data_manager interface inline with the GUID interfaces for web_dataservice, convert remaining unit tests to be GUID-based, and some changes to platform UI code that used unique IDs for edits. BUG=58813 TEST=WebDataServiceTest.*, WebDatabaseTest.*, WebDatabaseMigrationTest.*, PersonalDataManagerTest.*, AutoFillTest.*, AutoFillDialogControllerTest.AddNewProfile, AutoFillDialogControllerTest.AddNewCreditCard, AutoFillProfileTest.MergeWith, ProfileSyncServiceAutofillTest.*, TwoClientLiveAutofillSyncTest.* Review URL: http://codereview.chromium.org/4388001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65100 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/webdata')
-rw-r--r--chrome/browser/webdata/web_data_service.cc247
-rw-r--r--chrome/browser/webdata/web_data_service.h38
-rw-r--r--chrome/browser/webdata/web_data_service_unittest.cc150
-rw-r--r--chrome/browser/webdata/web_database.cc644
-rw-r--r--chrome/browser/webdata/web_database.h22
-rw-r--r--chrome/browser/webdata/web_database_unittest.cc468
6 files changed, 685 insertions, 884 deletions
diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc
index f567995..d99fa73 100644
--- a/chrome/browser/webdata/web_data_service.cc
+++ b/chrome/browser/webdata/web_data_service.cc
@@ -391,16 +391,6 @@ void WebDataService::RemoveFormValueForElementName(
request));
}
-void WebDataService::AddAutoFillProfile(const AutoFillProfile& profile) {
- GenericRequest<AutoFillProfile>* request =
- new GenericRequest<AutoFillProfile>(
- this, GetNextRequestHandle(), NULL, profile);
- RegisterRequest(request);
- ScheduleTask(NewRunnableMethod(this,
- &WebDataService::AddAutoFillProfileImpl,
- request));
-}
-
void WebDataService::AddAutoFillProfileGUID(const AutoFillProfile& profile) {
GenericRequest<AutoFillProfile>* request =
new GenericRequest<AutoFillProfile>(
@@ -411,16 +401,6 @@ void WebDataService::AddAutoFillProfileGUID(const AutoFillProfile& profile) {
request));
}
-void WebDataService::UpdateAutoFillProfile(const AutoFillProfile& profile) {
- GenericRequest<AutoFillProfile>* request =
- new GenericRequest<AutoFillProfile>(
- this, GetNextRequestHandle(), NULL, profile);
- RegisterRequest(request);
- ScheduleTask(NewRunnableMethod(this,
- &WebDataService::UpdateAutoFillProfileImpl,
- request));
-}
-
void WebDataService::UpdateAutoFillProfileGUID(const AutoFillProfile& profile) {
GenericRequest<AutoFillProfile>* request =
new GenericRequest<AutoFillProfile>(
@@ -431,16 +411,6 @@ void WebDataService::UpdateAutoFillProfileGUID(const AutoFillProfile& profile) {
request));
}
-void WebDataService::RemoveAutoFillProfile(int profile_id) {
- GenericRequest<int>* request =
- new GenericRequest<int>(
- this, GetNextRequestHandle(), NULL, profile_id);
- RegisterRequest(request);
- ScheduleTask(NewRunnableMethod(this,
- &WebDataService::RemoveAutoFillProfileImpl,
- request));
-}
-
void WebDataService::RemoveAutoFillProfileGUID(const std::string& guid) {
GenericRequest<std::string>* request =
new GenericRequest<std::string>(
@@ -463,16 +433,6 @@ WebDataService::Handle WebDataService::GetAutoFillProfiles(
return request->GetHandle();
}
-void WebDataService::AddCreditCard(const CreditCard& credit_card) {
- GenericRequest<CreditCard>* request =
- new GenericRequest<CreditCard>(
- this, GetNextRequestHandle(), NULL, credit_card);
- RegisterRequest(request);
- ScheduleTask(NewRunnableMethod(this,
- &WebDataService::AddCreditCardImpl,
- request));
-}
-
void WebDataService::AddCreditCardGUID(const CreditCard& credit_card) {
GenericRequest<CreditCard>* request =
new GenericRequest<CreditCard>(
@@ -483,16 +443,6 @@ void WebDataService::AddCreditCardGUID(const CreditCard& credit_card) {
request));
}
-void WebDataService::UpdateCreditCard(const CreditCard& credit_card) {
- GenericRequest<CreditCard>* request =
- new GenericRequest<CreditCard>(
- this, GetNextRequestHandle(), NULL, credit_card);
- RegisterRequest(request);
- ScheduleTask(NewRunnableMethod(this,
- &WebDataService::UpdateCreditCardImpl,
- request));
-}
-
void WebDataService::UpdateCreditCardGUID(const CreditCard& credit_card) {
GenericRequest<CreditCard>* request =
new GenericRequest<CreditCard>(
@@ -503,16 +453,6 @@ void WebDataService::UpdateCreditCardGUID(const CreditCard& credit_card) {
request));
}
-void WebDataService::RemoveCreditCard(int credit_card_id) {
- GenericRequest<int>* request =
- new GenericRequest<int>(
- this, GetNextRequestHandle(), NULL, credit_card_id);
- RegisterRequest(request);
- ScheduleTask(NewRunnableMethod(this,
- &WebDataService::RemoveCreditCardImpl,
- request));
-}
-
void WebDataService::RemoveCreditCardGUID(const std::string& guid) {
GenericRequest<std::string>* request =
new GenericRequest<std::string>(
@@ -539,11 +479,11 @@ void WebDataService::RemoveAutoFillProfilesAndCreditCardsModifiedBetween(
const Time& delete_begin,
const Time& delete_end) {
GenericRequest2<Time, Time>* request =
- new GenericRequest2<Time, Time>(this,
- GetNextRequestHandle(),
- NULL,
- delete_begin,
- delete_end);
+ new GenericRequest2<Time, Time>(this,
+ GetNextRequestHandle(),
+ NULL,
+ delete_begin,
+ delete_end);
RegisterRequest(request);
ScheduleTask(NewRunnableMethod(
this,
@@ -1051,27 +991,6 @@ void WebDataService::RemoveFormValueForElementNameImpl(
request->RequestComplete();
}
-void WebDataService::AddAutoFillProfileImpl(
- GenericRequest<AutoFillProfile>* request) {
- InitializeDatabaseIfNecessary();
- if (db_ && !request->IsCancelled()) {
- const AutoFillProfile& profile = request->GetArgument();
- if (!db_->AddAutoFillProfile(profile)) {
- NOTREACHED();
- return;
- }
- ScheduleCommit();
-
- AutofillProfileChange change(AutofillProfileChange::ADD,
- profile.Label(), &profile, string16());
- NotificationService::current()->Notify(
- NotificationType::AUTOFILL_PROFILE_CHANGED,
- Source<WebDataService>(this),
- Details<AutofillProfileChange>(&change));
- }
- request->RequestComplete();
-}
-
void WebDataService::AddAutoFillProfileGUIDImpl(
GenericRequest<AutoFillProfile>* request) {
InitializeDatabaseIfNecessary();
@@ -1091,7 +1010,7 @@ void WebDataService::AddAutoFillProfileGUIDImpl(
Source<WebDataService>(this),
Details<AutofillProfileChangeGUID>(&change));
- // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813
+ // TODO(dhollowa): Remove labels. http://crbug.com/58813
// Send out old Label-based notification until sync can switch over to
// GUID-based notifications.
AutofillProfileChange deprecated_change(AutofillProfileChange::ADD,
@@ -1106,52 +1025,20 @@ void WebDataService::AddAutoFillProfileGUIDImpl(
request->RequestComplete();
}
-void WebDataService::UpdateAutoFillProfileImpl(
- GenericRequest<AutoFillProfile>* request) {
- InitializeDatabaseIfNecessary();
- if (db_ && !request->IsCancelled()) {
- const AutoFillProfile& profile = request->GetArgument();
- // The AUTOFILL_PROFILE_CHANGED contract for an update requires that we
- // send along the label of the un-updated profile, to detect label
- // changes separately. So first, we query for the existing profile.
- AutoFillProfile* old_profile_ptr = NULL;
- if (!db_->GetAutoFillProfileForID(profile.unique_id(), &old_profile_ptr)) {
- NOTREACHED();
- return;
- }
-
- if (old_profile_ptr) {
- scoped_ptr<AutoFillProfile> old_profile(old_profile_ptr);
- if (!db_->UpdateAutoFillProfile(profile)) {
- NOTREACHED();
- return;
- }
- ScheduleCommit();
-
- AutofillProfileChange change(AutofillProfileChange::UPDATE,
- profile.Label(), &profile,
- old_profile->Label());
- NotificationService::current()->Notify(
- NotificationType::AUTOFILL_PROFILE_CHANGED,
- Source<WebDataService>(this),
- Details<AutofillProfileChange>(&change));
- }
- }
- request->RequestComplete();
-}
-
void WebDataService::UpdateAutoFillProfileGUIDImpl(
GenericRequest<AutoFillProfile>* request) {
InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled()) {
const AutoFillProfile& profile = request->GetArgument();
- // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813
+ // TODO(dhollowa): Remove labels. http://crbug.com/58813
// Send out old Label-based notification until sync can switch over to
// GUID-based notifications.
+ // Only perform the update if the profile exists. It is currently
+ // valid to try to update a missing profile. We simply drop the write and
+ // the caller will detect this on the next refresh.
AutoFillProfile* original_profile = NULL;
if (!db_->GetAutoFillProfileForGUID(profile.guid(), &original_profile)) {
- NOTREACHED();
return;
}
scoped_ptr<AutoFillProfile> scoped_profile(original_profile);
@@ -1170,7 +1057,7 @@ void WebDataService::UpdateAutoFillProfileGUIDImpl(
Source<WebDataService>(this),
Details<AutofillProfileChangeGUID>(&change));
- // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813
+ // TODO(dhollowa): Remove labels. http://crbug.com/58813
// Send old Label-based notification.
AutofillProfileChange deprecated_change(AutofillProfileChange::UPDATE,
profile.Label(), &profile,
@@ -1183,44 +1070,13 @@ void WebDataService::UpdateAutoFillProfileGUIDImpl(
request->RequestComplete();
}
-void WebDataService::RemoveAutoFillProfileImpl(
- GenericRequest<int>* request) {
- InitializeDatabaseIfNecessary();
- if (db_ && !request->IsCancelled()) {
- int profile_id = request->GetArgument();
- AutoFillProfile* profile = NULL;
- if (!db_->GetAutoFillProfileForID(profile_id, &profile)) {
- NOTREACHED();
- return;
- }
-
- if (profile) {
- scoped_ptr<AutoFillProfile> dead_profile(profile);
- if (!db_->RemoveAutoFillProfile(profile_id)) {
- NOTREACHED();
- return;
- }
- ScheduleCommit();
-
- AutofillProfileChange change(AutofillProfileChange::REMOVE,
- dead_profile->Label(),
- NULL, string16());
- NotificationService::current()->Notify(
- NotificationType::AUTOFILL_PROFILE_CHANGED,
- Source<WebDataService>(this),
- Details<AutofillProfileChange>(&change));
- }
- }
- request->RequestComplete();
-}
-
void WebDataService::RemoveAutoFillProfileGUIDImpl(
GenericRequest<std::string>* request) {
InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled()) {
std::string guid = request->GetArgument();
- // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813
+ // TODO(dhollowa): Remove labels. http://crbug.com/58813
// Send out old Label-based notification until sync can switch over to
// GUID-based notifications.
AutoFillProfile* profile = NULL;
@@ -1244,7 +1100,7 @@ void WebDataService::RemoveAutoFillProfileGUIDImpl(
Source<WebDataService>(this),
Details<AutofillProfileChangeGUID>(&change));
- // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813
+ // TODO(dhollowa): Remove labels. http://crbug.com/58813
// Send old Label-based notification.
AutofillProfileChange deprecated_change(AutofillProfileChange::REMOVE,
scoped_profile->Label(),
@@ -1269,27 +1125,6 @@ void WebDataService::GetAutoFillProfilesImpl(WebDataRequest* request) {
request->RequestComplete();
}
-void WebDataService::AddCreditCardImpl(
- GenericRequest<CreditCard>* request) {
- InitializeDatabaseIfNecessary();
- if (db_ && !request->IsCancelled()) {
- const CreditCard& credit_card = request->GetArgument();
- if (!db_->AddCreditCard(credit_card)) {
- NOTREACHED();
- return;
- }
- ScheduleCommit();
-
- AutofillCreditCardChange change(AutofillCreditCardChange::ADD,
- credit_card.Label(), &credit_card);
- NotificationService::current()->Notify(
- NotificationType::AUTOFILL_CREDIT_CARD_CHANGED,
- Source<WebDataService>(this),
- Details<AutofillCreditCardChange>(&change));
- }
- request->RequestComplete();
-}
-
void WebDataService::AddCreditCardGUIDImpl(
GenericRequest<CreditCard>* request) {
InitializeDatabaseIfNecessary();
@@ -1312,32 +1147,20 @@ void WebDataService::AddCreditCardGUIDImpl(
request->RequestComplete();
}
-void WebDataService::UpdateCreditCardImpl(
+void WebDataService::UpdateCreditCardGUIDImpl(
GenericRequest<CreditCard>* request) {
InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled()) {
const CreditCard& credit_card = request->GetArgument();
- if (!db_->UpdateCreditCard(credit_card)) {
- NOTREACHED();
+
+ // It is currently valid to try to update a missing profile. We simply drop
+ // the write and the caller will detect this on the next refresh.
+ CreditCard* original_credit_card = NULL;
+ if (!db_->GetCreditCardForGUID(credit_card.guid(), &original_credit_card)) {
return;
}
- ScheduleCommit();
+ scoped_ptr<CreditCard> scoped_credit_card(original_credit_card);
- AutofillCreditCardChange change(AutofillCreditCardChange::UPDATE,
- credit_card.Label(), &credit_card);
- NotificationService::current()->Notify(
- NotificationType::AUTOFILL_CREDIT_CARD_CHANGED,
- Source<WebDataService>(this),
- Details<AutofillCreditCardChange>(&change));
- }
- request->RequestComplete();
-}
-
-void WebDataService::UpdateCreditCardGUIDImpl(
- GenericRequest<CreditCard>* request) {
- InitializeDatabaseIfNecessary();
- if (db_ && !request->IsCancelled()) {
- const CreditCard& credit_card = request->GetArgument();
if (!db_->UpdateCreditCard(credit_card)) {
NOTREACHED();
return;
@@ -1355,36 +1178,6 @@ void WebDataService::UpdateCreditCardGUIDImpl(
request->RequestComplete();
}
-void WebDataService::RemoveCreditCardImpl(
- GenericRequest<int>* request) {
- InitializeDatabaseIfNecessary();
- if (db_ && !request->IsCancelled()) {
- int credit_card_id = request->GetArgument();
- CreditCard* credit_card = NULL;
- if (!db_->GetCreditCardForID(credit_card_id, &credit_card)) {
- NOTREACHED();
- return;
- }
-
- if (credit_card) {
- scoped_ptr<CreditCard> dead_credit_card(credit_card);
- if (!db_->RemoveCreditCard(credit_card_id)) {
- NOTREACHED();
- return;
- }
- ScheduleCommit();
-
- AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE,
- dead_credit_card->Label(), NULL);
- NotificationService::current()->Notify(
- NotificationType::AUTOFILL_CREDIT_CARD_CHANGED,
- Source<WebDataService>(this),
- Details<AutofillCreditCardChange>(&change));
- }
- }
- request->RequestComplete();
-}
-
void WebDataService::RemoveCreditCardGUIDImpl(
GenericRequest<std::string>* request) {
InitializeDatabaseIfNecessary();
diff --git a/chrome/browser/webdata/web_data_service.h b/chrome/browser/webdata/web_data_service.h
index 6fe669e..42f204e 100644
--- a/chrome/browser/webdata/web_data_service.h
+++ b/chrome/browser/webdata/web_data_service.h
@@ -436,28 +436,12 @@ class WebDataService
void RemoveFormValueForElementName(const string16& name,
const string16& value);
- // DEPRECATED
- // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813
- // Schedules a task to add an AutoFill profile to the web database.
- void AddAutoFillProfile(const AutoFillProfile& profile);
-
// Schedules a task to add an AutoFill profile to the web database.
void AddAutoFillProfileGUID(const AutoFillProfile& profile);
- // DEPRECATED
- // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813
- // Schedules a task to update an AutoFill profile in the web database.
- void UpdateAutoFillProfile(const AutoFillProfile& profile);
-
// Schedules a task to update an AutoFill profile in the web database.
void UpdateAutoFillProfileGUID(const AutoFillProfile& profile);
- // DEPRECATED
- // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813
- // Schedules a task to remove an AutoFill profile from the web database.
- // |profile_id| is the unique ID of the profile to remove.
- void RemoveAutoFillProfile(int profile_id);
-
// Schedules a task to remove an AutoFill profile from the web database.
// |guid| is the identifer of the profile to remove.
void RemoveAutoFillProfileGUID(const std::string& guid);
@@ -468,28 +452,12 @@ class WebDataService
// consumer owns the profiles.
Handle GetAutoFillProfiles(WebDataServiceConsumer* consumer);
- // DEPRECATED
- // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813
- // Schedules a task to add credit card to the web database.
- void AddCreditCard(const CreditCard& credit_card);
-
// Schedules a task to add credit card to the web database.
void AddCreditCardGUID(const CreditCard& credit_card);
- // DEPRECATED
- // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813
- // Schedules a task to update credit card in the web database.
- void UpdateCreditCard(const CreditCard& credit_card);
-
// Schedules a task to update credit card in the web database.
void UpdateCreditCardGUID(const CreditCard& credit_card);
- // DEPRECATED
- // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813
- // Schedules a task to remove a credit card from the web database.
- // |credit_card_id| is the unique ID of the credit card to remove.
- void RemoveCreditCard(int credit_card_id);
-
// Schedules a task to remove a credit card from the web database.
// |guid| is identifer of the credit card to remove.
void RemoveCreditCardGUID(const std::string& guid);
@@ -630,18 +598,12 @@ class WebDataService
GenericRequest2<base::Time, base::Time>* request);
void RemoveFormValueForElementNameImpl(
GenericRequest2<string16, string16>* request);
- void AddAutoFillProfileImpl(GenericRequest<AutoFillProfile>* request);
void AddAutoFillProfileGUIDImpl(GenericRequest<AutoFillProfile>* request);
- void UpdateAutoFillProfileImpl(GenericRequest<AutoFillProfile>* request);
void UpdateAutoFillProfileGUIDImpl(GenericRequest<AutoFillProfile>* request);
- void RemoveAutoFillProfileImpl(GenericRequest<int>* request);
void RemoveAutoFillProfileGUIDImpl(GenericRequest<std::string>* request);
void GetAutoFillProfilesImpl(WebDataRequest* request);
- void AddCreditCardImpl(GenericRequest<CreditCard>* request);
void AddCreditCardGUIDImpl(GenericRequest<CreditCard>* request);
- void UpdateCreditCardImpl(GenericRequest<CreditCard>* request);
void UpdateCreditCardGUIDImpl(GenericRequest<CreditCard>* request);
- void RemoveCreditCardImpl(GenericRequest<int>* request);
void RemoveCreditCardGUIDImpl(GenericRequest<std::string>* request);
void GetCreditCardsImpl(WebDataRequest* request);
void RemoveAutoFillProfilesAndCreditCardsModifiedBetweenImpl(
diff --git a/chrome/browser/webdata/web_data_service_unittest.cc b/chrome/browser/webdata/web_data_service_unittest.cc
index 741a574..2b4401c 100644
--- a/chrome/browser/webdata/web_data_service_unittest.cc
+++ b/chrome/browser/webdata/web_data_service_unittest.cc
@@ -256,23 +256,6 @@ TEST_F(WebDataServiceAutofillTest, FormFillRemoveMany) {
done_event_.TimedWait(test_timeout_);
}
-TEST_F(WebDataServiceAutofillTest, ProfileAdd) {
- AutoFillProfile profile(name1_, unique_id1_);
- const AutofillProfileChange expected_change(
- AutofillProfileChange::ADD, name1_, &profile, string16());
-
- EXPECT_CALL(
- *observer_helper_->observer(),
- Observe(NotificationType(NotificationType::AUTOFILL_PROFILE_CHANGED),
- Source<WebDataService>(wds_.get()),
- Property(&Details<const AutofillProfileChange>::ptr,
- Pointee(expected_change)))).
- WillOnce(SignalEvent(&done_event_));
-
- wds_->AddAutoFillProfile(profile);
- done_event_.TimedWait(test_timeout_);
-}
-
TEST_F(WebDataServiceAutofillTest, ProfileAddGUID) {
AutoFillProfile profile;
@@ -314,28 +297,6 @@ TEST_F(WebDataServiceAutofillTest, ProfileAddGUID) {
STLDeleteElements(&consumer.result());
}
-TEST_F(WebDataServiceAutofillTest, ProfileRemove) {
- AutoFillProfile profile(name1_, unique_id1_);
-
- EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)).
- WillOnce(SignalEvent(&done_event_));
- wds_->AddAutoFillProfile(profile);
- done_event_.TimedWait(test_timeout_);
-
- const AutofillProfileChange expected_change(
- AutofillProfileChange::REMOVE, name1_, NULL, string16());
- EXPECT_CALL(
- *observer_helper_->observer(),
- Observe(NotificationType(NotificationType::AUTOFILL_PROFILE_CHANGED),
- Source<WebDataService>(wds_.get()),
- Property(&Details<const AutofillProfileChange>::ptr,
- Pointee(expected_change)))).
- WillOnce(SignalEvent(&done_event_));
-
- wds_->RemoveAutoFillProfile(profile.unique_id());
- done_event_.TimedWait(test_timeout_);
-}
-
TEST_F(WebDataServiceAutofillTest, ProfileRemoveGUID) {
AutoFillProfile profile;
profile.set_label(name1_);
@@ -393,50 +354,12 @@ TEST_F(WebDataServiceAutofillTest, ProfileRemoveGUID) {
ASSERT_EQ(0U, consumer2.result().size());
}
-TEST_F(WebDataServiceAutofillTest, ProfileUpdate) {
- AutoFillProfile profile1(name1_, unique_id1_);
- AutoFillProfile profile2(name2_, unique_id2_);
-
- EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)).
- Times(2).
- WillOnce(DoDefault()).
- WillOnce(SignalEvent(&done_event_));
- wds_->AddAutoFillProfile(profile1);
- wds_->AddAutoFillProfile(profile2);
-
- done_event_.TimedWait(test_timeout_);
-
- AutoFillProfile profile1_delta(profile1);
- string16 new_label(ASCIIToUTF16("new_label!"));
- profile1_delta.set_label(new_label);
- const AutofillProfileChange expected_change(
- AutofillProfileChange::UPDATE, new_label, &profile1_delta, name1_);
-
- EXPECT_CALL(
- *observer_helper_->observer(),
- Observe(NotificationType(NotificationType::AUTOFILL_PROFILE_CHANGED),
- Source<WebDataService>(wds_.get()),
- Property(&Details<const AutofillProfileChange>::ptr,
- Pointee(expected_change)))).
- WillOnce(SignalEvent(&done_event_));
-
- wds_->UpdateAutoFillProfile(profile1_delta);
- done_event_.TimedWait(test_timeout_);
-}
-
TEST_F(WebDataServiceAutofillTest, ProfileUpdateGUID) {
AutoFillProfile profile1;
profile1.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Abe"));
AutoFillProfile profile2;
profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Alice"));
- // TODO(dhollowa): Remove once unique_ids are deprecated from the db.
- // http://crbug.com/58813
- profile1.set_unique_id(unique_id1_);
- profile1.set_label(name1_);
- profile2.set_unique_id(unique_id2_);
- profile2.set_label(name2_);
-
EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)).
WillOnce(DoDefault()).
WillOnce(DoDefault()).
@@ -502,23 +425,6 @@ TEST_F(WebDataServiceAutofillTest, ProfileUpdateGUID) {
STLDeleteElements(&consumer2.result());
}
-TEST_F(WebDataServiceAutofillTest, CreditAdd) {
- CreditCard card(name1_, unique_id1_);
- const AutofillCreditCardChange expected_change(
- AutofillCreditCardChange::ADD, name1_, &card);
-
- EXPECT_CALL(
- *observer_helper_->observer(),
- Observe(NotificationType(NotificationType::AUTOFILL_CREDIT_CARD_CHANGED),
- Source<WebDataService>(wds_.get()),
- Property(&Details<const AutofillCreditCardChange>::ptr,
- Pointee(expected_change)))).
- WillOnce(SignalEvent(&done_event_));
-
- wds_->AddCreditCard(card);
- done_event_.TimedWait(test_timeout_);
-}
-
TEST_F(WebDataServiceAutofillTest, CreditAddGUID) {
CreditCard card;
const AutofillCreditCardChangeGUID expected_change(
@@ -546,28 +452,6 @@ TEST_F(WebDataServiceAutofillTest, CreditAddGUID) {
STLDeleteElements(&consumer.result());
}
-TEST_F(WebDataServiceAutofillTest, CreditRemove) {
- CreditCard card(name1_, unique_id1_);
- EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)).
- WillOnce(SignalEvent(&done_event_));
- wds_->AddCreditCard(card);
- done_event_.TimedWait(test_timeout_);
-
- const AutofillCreditCardChange expected_change(
- AutofillCreditCardChange::REMOVE, name1_, NULL);
-
- EXPECT_CALL(
- *observer_helper_->observer(),
- Observe(NotificationType(NotificationType::AUTOFILL_CREDIT_CARD_CHANGED),
- Source<WebDataService>(wds_.get()),
- Property(&Details<const AutofillCreditCardChange>::ptr,
- Pointee(expected_change)))).
- WillOnce(SignalEvent(&done_event_));
-
- wds_->RemoveCreditCard(card.unique_id());
- done_event_.TimedWait(test_timeout_);
-}
-
TEST_F(WebDataServiceAutofillTest, CreditCardRemoveGUID) {
CreditCard credit_card;
@@ -608,46 +492,12 @@ TEST_F(WebDataServiceAutofillTest, CreditCardRemoveGUID) {
ASSERT_EQ(0U, consumer2.result().size());
}
-TEST_F(WebDataServiceAutofillTest, CreditUpdate) {
- CreditCard card1(name1_, unique_id1_);
- CreditCard card2(name2_, unique_id2_);
-
- EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)).
- Times(2).
- WillOnce(DoDefault()).
- WillOnce(SignalEvent(&done_event_));
- wds_->AddCreditCard(card1);
- wds_->AddCreditCard(card2);
- done_event_.TimedWait(test_timeout_);
-
- CreditCard card1_delta(card1);
- card1_delta.set_label(ASCIIToUTF16("new_label!"));
- const AutofillCreditCardChange expected_change(
- AutofillCreditCardChange::UPDATE, name1_, &card1_delta);
-
- EXPECT_CALL(
- *observer_helper_->observer(),
- Observe(NotificationType(NotificationType::AUTOFILL_CREDIT_CARD_CHANGED),
- Source<WebDataService>(wds_.get()),
- Property(&Details<const AutofillCreditCardChange>::ptr,
- Pointee(expected_change)))).
- WillOnce(SignalEvent(&done_event_));
-
- wds_->UpdateCreditCard(card1_delta);
- done_event_.TimedWait(test_timeout_);
-}
-
TEST_F(WebDataServiceAutofillTest, CreditUpdateGUID) {
CreditCard card1;
card1.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Abe"));
CreditCard card2;
card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Alice"));
- // TODO(dhollowa): Remove once unique_ids are deprecated from the db.
- // http://crbug.com/58813
- card1.set_unique_id(unique_id1_);
- card2.set_unique_id(unique_id2_);
-
EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)).
Times(2).
WillOnce(DoDefault()).
diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc
index c40bfca..2b9c029 100644
--- a/chrome/browser/webdata/web_database.cc
+++ b/chrome/browser/webdata/web_database.cc
@@ -109,9 +109,10 @@ using webkit_glue::PasswordForm;
// user with the AutoFill dialog. Most of the columns are
// standard entries in a contact information form.
//
+// guid A guid string to uniquely identify the profile.
+// Added in version 31.
// label The label of the profile. Presented to the user when
// selecting profiles.
-// unique_id The unique ID of this profile.
// first_name
// middle_name
// last_name
@@ -127,45 +128,21 @@ using webkit_glue::PasswordForm;
// fax
// date_modified The date on which this profile was last modified.
// Added in version 30.
-// guid A guid string to uniquely identify the profile. This
-// will eventually replace the unique_id above. We need
-// to keep both during the transition.
-// Added in version 31.
-// TODO(dhollowa): Deprecate and remove unique_id.
-// http://crbug.com/58813
//
// credit_cards This table contains credit card data added by the user
// with the AutoFill dialog. Most of the columns are
// standard entries in a credit card form.
//
+// guid A guid string to uniquely identify the profile.
+// Added in version 31.
// label The label of the credit card. Presented to the user
// when selecting credit cards.
-// unique_id The unique ID of this credit card.
// name_on_card
-// type
-// card_number Before version 23 stores credit card number, 23 and
-// after stores empty string.
// expiration_month
// expiration_year
-// verification_code Before version 23 stores the CVC/CVV/CVV2 card security
-// code. After that stores the empty string.
-// billing_address A foreign key into the autofill_profiles table.
-// shipping_address A foreign key into the autofill_profiles table.
-// For the following two fields encryption is used. Currently it uses
-// Encryptor, that does encryption on windows only. As on the other
-// systems this file is readable by owner only, it is good for now.
-// For potentially going over the wire other encryption is used, see
-// chrome/browser/sync/protocol/autofill_specifics.proto
// card_number_encrypted Stores encrypted credit card number.
-// verification_code_encrypted The CVC/CVV/CVV2 card security code.
// date_modified The date on which this entry was last modified.
// Added in version 30.
-// guid A guid string to uniquely identify the profile. This
-// will eventually replace the unique_id above. We need
-// to keep both during the transition.
-// Added in version 31.
-// TODO(dhollowa): Deprecate and remove unique_id.
-// http://crbug.com/58813
//
// web_app_icons
// url URL of the web app.
@@ -188,8 +165,8 @@ typedef std::vector<Tuple3<int64, string16, string16> > AutofillElementList;
// Current version number. Note: when changing the current version number,
// corresponding changes must happen in the unit tests, and new migration test
// added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|.
-const int kCurrentVersionNumber = 31;
-const int kCompatibleVersionNumber = 31;
+const int kCurrentVersionNumber = 32;
+const int kCompatibleVersionNumber = 32;
// ID of the url column in keywords.
const int kUrlIdPosition = 16;
@@ -278,8 +255,9 @@ string16 LimitDataSize(const string16& data) {
void BindAutoFillProfileToStatement(const AutoFillProfile& profile,
sql::Statement* s) {
- s->BindString16(0, profile.Label());
- s->BindInt(1, profile.unique_id());
+ DCHECK(guid::IsValidGUID(profile.guid()));
+ s->BindString(0, profile.guid());
+ s->BindString16(1, profile.Label());
string16 text = profile.GetFieldText(AutoFillType(NAME_FIRST));
s->BindString16(2, LimitDataSize(text));
@@ -308,13 +286,14 @@ void BindAutoFillProfileToStatement(const AutoFillProfile& profile,
text = profile.GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER));
s->BindString16(14, LimitDataSize(text));
s->BindInt64(15, Time::Now().ToTimeT());
- DCHECK(guid::IsValidGUID(profile.guid()));
- s->BindString(16, profile.guid());
}
AutoFillProfile* AutoFillProfileFromStatement(const sql::Statement& s) {
- AutoFillProfile* profile = new AutoFillProfile(s.ColumnString16(0),
- s.ColumnInt(1));
+ AutoFillProfile* profile = new AutoFillProfile;
+ profile->set_guid(s.ColumnString(0));
+ DCHECK(guid::IsValidGUID(profile->guid()));
+ profile->set_label(s.ColumnString16(1));
+
profile->SetInfo(AutoFillType(NAME_FIRST),
s.ColumnString16(2));
profile->SetInfo(AutoFillType(NAME_MIDDLE),
@@ -342,80 +321,53 @@ AutoFillProfile* AutoFillProfileFromStatement(const sql::Statement& s) {
profile->SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER),
s.ColumnString16(14));
// Intentionally skip column 15, which stores the profile's modification date.
- profile->set_guid(s.ColumnString(16));
- DCHECK(guid::IsValidGUID(profile->guid()));
return profile;
}
void BindCreditCardToStatement(const CreditCard& credit_card,
sql::Statement* s) {
- s->BindString16(0, credit_card.Label());
- s->BindInt(1, credit_card.unique_id());
+ DCHECK(guid::IsValidGUID(credit_card.guid()));
+ s->BindString(0, credit_card.guid());
+ s->BindString16(1, credit_card.Label());
string16 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NAME));
s->BindString16(2, LimitDataSize(text));
- text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_TYPE));
- s->BindString16(3, LimitDataSize(text));
- text.clear(); // No unencrypted cc info.
- s->BindString16(4, LimitDataSize(text));
text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH));
- s->BindString16(5, LimitDataSize(text));
+ s->BindString16(3, LimitDataSize(text));
text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR));
- s->BindString16(6, LimitDataSize(text));
- text.clear();
- s->BindString16(7, LimitDataSize(text));
- // We don't store the billing address id anymore.
- s->BindInt(8, 0);
- // We don't store the shipping address anymore.
- text.clear();
- s->BindString16(9, LimitDataSize(text));
+ s->BindString16(4, LimitDataSize(text));
text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER));
std::string encrypted_data;
Encryptor::EncryptString16(text, &encrypted_data);
- s->BindBlob(10, encrypted_data.data(),
+ s->BindBlob(5, encrypted_data.data(),
static_cast<int>(encrypted_data.length()));
- // We don't store the CVV anymore.
- text.clear();
- s->BindBlob(11, text.data(), static_cast<int>(text.length()));
- s->BindInt64(12, Time::Now().ToTimeT());
- DCHECK(guid::IsValidGUID(credit_card.guid()));
- s->BindString(13, credit_card.guid());
+ s->BindInt64(6, Time::Now().ToTimeT());
}
CreditCard* CreditCardFromStatement(const sql::Statement& s) {
- CreditCard* credit_card = new CreditCard(s.ColumnString16(0), s.ColumnInt(1));
+ CreditCard* credit_card = new CreditCard;
+
+ credit_card->set_guid(s.ColumnString(0));
+ DCHECK(guid::IsValidGUID(credit_card->guid()));
+ credit_card->set_label(s.ColumnString16(1));
+
credit_card->SetInfo(AutoFillType(CREDIT_CARD_NAME),
s.ColumnString16(2));
- credit_card->SetInfo(AutoFillType(CREDIT_CARD_TYPE),
+ credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH),
s.ColumnString16(3));
- string16 credit_card_number = s.ColumnString16(4);
- // It could be non-empty prior to version 23. After that it encrypted in
- // the column 10.
- if (credit_card_number.empty()) {
- int encrypted_cc_len = s.ColumnByteLength(10);
- std::string encrypted_cc;
- if (encrypted_cc_len) {
- encrypted_cc.resize(encrypted_cc_len);
- memcpy(&encrypted_cc[0], s.ColumnBlob(10), encrypted_cc_len);
- Encryptor::DecryptString16(encrypted_cc, &credit_card_number);
- }
+ credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR),
+ s.ColumnString16(4));
+ int encrypted_number_len = s.ColumnByteLength(5);
+ string16 credit_card_number;
+ if (encrypted_number_len) {
+ std::string encrypted_number;
+ encrypted_number.resize(encrypted_number_len);
+ memcpy(&encrypted_number[0], s.ColumnBlob(5), encrypted_number_len);
+ Encryptor::DecryptString16(encrypted_number, &credit_card_number);
}
credit_card->SetInfo(AutoFillType(CREDIT_CARD_NUMBER), credit_card_number);
- credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH),
- s.ColumnString16(5));
- credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR),
- s.ColumnString16(6));
-
- string16 credit_card_verification_code = s.ColumnString16(7);
- // We don't store the CVV anymore.
- // We don't store the billing address anymore.
- // We don't store the shipping address anymore.
- // Column 10 is processed above.
- // We don't store the encrypted CVV anymore.
- // Intentionally skip column 12, which stores the modification date.
- credit_card->set_guid(s.ColumnString(13));
- DCHECK(guid::IsValidGUID(credit_card->guid()));
+ // Intentionally skip column 6, which stores the modification date.
return credit_card;
}
@@ -767,8 +719,8 @@ bool WebDatabase::InitAutofillDatesTable() {
bool WebDatabase::InitAutoFillProfilesTable() {
if (!db_.DoesTableExist("autofill_profiles")) {
if (!db_.Execute("CREATE TABLE autofill_profiles ( "
+ "guid VARCHAR PRIMARY KEY, "
"label VARCHAR, "
- "unique_id INTEGER PRIMARY KEY, "
"first_name VARCHAR, "
"middle_name VARCHAR, "
"last_name VARCHAR, "
@@ -782,8 +734,7 @@ bool WebDatabase::InitAutoFillProfilesTable() {
"country VARCHAR, "
"phone VARCHAR, "
"fax VARCHAR, "
- "date_modified INTEGER NOT NULL DEFAULT 0, "
- "guid VARCHAR NOT NULL DEFAULT \"\")")) {
+ "date_modified INTEGER NOT NULL DEFAULT 0)")) {
NOTREACHED();
return false;
}
@@ -799,20 +750,13 @@ bool WebDatabase::InitAutoFillProfilesTable() {
bool WebDatabase::InitCreditCardsTable() {
if (!db_.DoesTableExist("credit_cards")) {
if (!db_.Execute("CREATE TABLE credit_cards ( "
+ "guid VARCHAR PRIMARY KEY, "
"label VARCHAR, "
- "unique_id INTEGER PRIMARY KEY, "
"name_on_card VARCHAR, "
- "type VARCHAR, "
- "card_number VARCHAR, "
"expiration_month INTEGER, "
"expiration_year INTEGER, "
- "verification_code VARCHAR, "
- "billing_address VARCHAR, "
- "shipping_address VARCHAR, "
"card_number_encrypted BLOB, "
- "verification_code_encrypted BLOB, "
- "date_modified INTEGER NOT NULL DEFAULT 0, "
- "guid VARCHAR NOT NULL DEFAULT \"\")")) {
+ "date_modified INTEGER NOT NULL DEFAULT 0)")) {
NOTREACHED();
return false;
}
@@ -1660,10 +1604,10 @@ bool WebDatabase::RemoveFormElement(const string16& name,
bool WebDatabase::AddAutoFillProfile(const AutoFillProfile& profile) {
sql::Statement s(db_.GetUniqueStatement(
"INSERT INTO autofill_profiles"
- "(label, unique_id, first_name, middle_name, last_name, email,"
+ "(guid, label, first_name, middle_name, last_name, email,"
" company_name, address_line_1, address_line_2, city, state, zipcode,"
- " country, phone, fax, date_modified, guid)"
- "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"));
+ " country, phone, fax, date_modified)"
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"));
if (!s) {
NOTREACHED() << "Statement prepare failed";
return false;
@@ -1683,9 +1627,9 @@ bool WebDatabase::GetAutoFillProfileForLabel(const string16& label,
AutoFillProfile** profile) {
DCHECK(profile);
sql::Statement s(db_.GetUniqueStatement(
- "SELECT label, unique_id, first_name, middle_name, last_name, email, "
+ "SELECT guid, label, first_name, middle_name, last_name, email, "
"company_name, address_line_1, address_line_2, city, state, zipcode, "
- "country, phone, fax, date_modified, guid "
+ "country, phone, fax, date_modified "
"FROM autofill_profiles "
"WHERE label = ?"));
if (!s) {
@@ -1707,9 +1651,9 @@ bool WebDatabase::GetAutoFillProfileForGUID(const std::string& guid,
DCHECK(guid::IsValidGUID(guid));
DCHECK(profile);
sql::Statement s(db_.GetUniqueStatement(
- "SELECT label, unique_id, first_name, middle_name, last_name, email, "
+ "SELECT guid, label, first_name, middle_name, last_name, email, "
"company_name, address_line_1, address_line_2, city, state, zipcode, "
- "country, phone, fax, date_modified, guid "
+ "country, phone, fax, date_modified "
"FROM autofill_profiles "
"WHERE guid = ?"));
if (!s) {
@@ -1732,9 +1676,9 @@ bool WebDatabase::GetAutoFillProfiles(
profiles->clear();
sql::Statement s(db_.GetUniqueStatement(
- "SELECT label, unique_id, first_name, middle_name, last_name, email, "
+ "SELECT guid, label, first_name, middle_name, last_name, email, "
"company_name, address_line_1, address_line_2, city, state, zipcode, "
- "country, phone, fax, date_modified, guid "
+ "country, phone, fax, date_modified "
"FROM autofill_profiles"));
if (!s) {
NOTREACHED() << "Statement prepare failed";
@@ -1748,39 +1692,26 @@ bool WebDatabase::GetAutoFillProfiles(
}
bool WebDatabase::UpdateAutoFillProfile(const AutoFillProfile& profile) {
- DCHECK(profile.unique_id());
+ DCHECK(guid::IsValidGUID(profile.guid()));
sql::Statement s(db_.GetUniqueStatement(
"UPDATE autofill_profiles "
- "SET label=?, unique_id=?, first_name=?, middle_name=?, last_name=?, "
+ "SET guid=?, label=?, first_name=?, middle_name=?, last_name=?, "
" email=?, company_name=?, address_line_1=?, address_line_2=?, "
" city=?, state=?, zipcode=?, country=?, phone=?, fax=?, "
- " date_modified=?, guid=? "
- "WHERE unique_id=?"));
+ " date_modified=? "
+ "WHERE guid=?"));
if (!s) {
NOTREACHED() << "Statement prepare failed";
return false;
}
BindAutoFillProfileToStatement(profile, &s);
- s.BindInt(17, profile.unique_id());
+ s.BindString(16, profile.guid());
bool result = s.Run();
DCHECK_GT(db_.GetLastChangeCount(), 0);
return result;
}
-bool WebDatabase::RemoveAutoFillProfile(int profile_id) {
- DCHECK_NE(0, profile_id);
- sql::Statement s(db_.GetUniqueStatement(
- "DELETE FROM autofill_profiles WHERE unique_id = ?"));
- if (!s) {
- NOTREACHED() << "Statement prepare failed";
- return false;
- }
-
- s.BindInt(0, profile_id);
- return s.Run();
-}
-
bool WebDatabase::RemoveAutoFillProfile(const std::string& guid) {
DCHECK(guid::IsValidGUID(guid));
sql::Statement s(db_.GetUniqueStatement(
@@ -1794,34 +1725,12 @@ bool WebDatabase::RemoveAutoFillProfile(const std::string& guid) {
return s.Run();
}
-bool WebDatabase::GetAutoFillProfileForID(int profile_id,
- AutoFillProfile** profile) {
- sql::Statement s(db_.GetUniqueStatement(
- "SELECT label, unique_id, first_name, middle_name, last_name, email, "
- "company_name, address_line_1, address_line_2, city, state, zipcode, "
- "country, phone, fax, date_modified, guid "
- "FROM autofill_profiles "
- "WHERE unique_id = ?"));
- if (!s) {
- NOTREACHED() << "Statement prepare failed";
- return false;
- }
-
- s.BindInt(0, profile_id);
- if (s.Step())
- *profile = AutoFillProfileFromStatement(s);
-
- return s.Succeeded();
-}
-
bool WebDatabase::AddCreditCard(const CreditCard& credit_card) {
sql::Statement s(db_.GetUniqueStatement(
"INSERT INTO credit_cards"
- "(label, unique_id, name_on_card, type, card_number, expiration_month,"
- " expiration_year, verification_code, billing_address, shipping_address,"
- " card_number_encrypted, verification_code_encrypted, date_modified,"
- " guid)"
- "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"));
+ "(guid, label, name_on_card, expiration_month, expiration_year, "
+ "card_number_encrypted, date_modified)"
+ "VALUES (?,?,?,?,?,?,?)"));
if (!s) {
NOTREACHED() << "Statement prepare failed";
return false;
@@ -1842,10 +1751,8 @@ bool WebDatabase::GetCreditCardForLabel(const string16& label,
CreditCard** credit_card) {
DCHECK(credit_card);
sql::Statement s(db_.GetUniqueStatement(
- "SELECT label, unique_id, name_on_card, type, card_number, "
- "expiration_month, expiration_year, verification_code, billing_address, "
- "shipping_address, card_number_encrypted, verification_code_encrypted, "
- "date_modified, guid "
+ "SELECT guid, label, name_on_card, expiration_month, expiration_year, "
+ "card_number_encrypted, date_modified "
"FROM credit_cards "
"WHERE label = ?"));
if (!s) {
@@ -1862,37 +1769,12 @@ bool WebDatabase::GetCreditCardForLabel(const string16& label,
return s.Succeeded();
}
-bool WebDatabase::GetCreditCardForID(int credit_card_id,
- CreditCard** credit_card) {
- sql::Statement s(db_.GetUniqueStatement(
- "SELECT label, unique_id, name_on_card, type, card_number, "
- "expiration_month, expiration_year, verification_code, billing_address, "
- "shipping_address, card_number_encrypted, verification_code_encrypted, "
- "date_modified, guid "
- "FROM credit_cards "
- "WHERE unique_id = ?"));
- if (!s) {
- NOTREACHED() << "Statement prepare failed";
- return false;
- }
-
- s.BindInt(0, credit_card_id);
- if (!s.Step())
- return false;
-
- *credit_card = CreditCardFromStatement(s);
-
- return s.Succeeded();
-}
-
bool WebDatabase::GetCreditCardForGUID(const std::string& guid,
CreditCard** credit_card) {
DCHECK(guid::IsValidGUID(guid));
sql::Statement s(db_.GetUniqueStatement(
- "SELECT label, unique_id, name_on_card, type, card_number, "
- "expiration_month, expiration_year, verification_code, billing_address, "
- "shipping_address, card_number_encrypted, verification_code_encrypted, "
- "date_modified, guid "
+ "SELECT guid, label, name_on_card, expiration_month, expiration_year, "
+ "card_number_encrypted, date_modified "
"FROM credit_cards "
"WHERE guid = ?"));
if (!s) {
@@ -1915,10 +1797,8 @@ bool WebDatabase::GetCreditCards(
credit_cards->clear();
sql::Statement s(db_.GetUniqueStatement(
- "SELECT label, unique_id, name_on_card, type, card_number, "
- "expiration_month, expiration_year, verification_code, billing_address, "
- "shipping_address, card_number_encrypted, verification_code_encrypted, "
- "date_modified, guid "
+ "SELECT guid, label, name_on_card, expiration_month, expiration_year, "
+ "card_number_encrypted, date_modified "
"FROM credit_cards"));
if (!s) {
NOTREACHED() << "Statement prepare failed";
@@ -1932,39 +1812,24 @@ bool WebDatabase::GetCreditCards(
}
bool WebDatabase::UpdateCreditCard(const CreditCard& credit_card) {
- DCHECK(credit_card.unique_id());
+ DCHECK(guid::IsValidGUID(credit_card.guid()));
sql::Statement s(db_.GetUniqueStatement(
"UPDATE credit_cards "
- "SET label=?, unique_id=?, name_on_card=?, type=?, card_number=?, "
- " expiration_month=?, expiration_year=?, verification_code=?, "
- " billing_address=?, shipping_address=?, card_number_encrypted=?, "
- " verification_code_encrypted=?, date_modified=?, guid=?"
- "WHERE unique_id=?"));
+ "SET guid=?, label=?, name_on_card=?, expiration_month=?, "
+ " expiration_year=?, card_number_encrypted=?, date_modified=? "
+ "WHERE guid=?"));
if (!s) {
NOTREACHED() << "Statement prepare failed";
return false;
}
BindCreditCardToStatement(credit_card, &s);
- s.BindInt(14, credit_card.unique_id());
+ s.BindString(7, credit_card.guid());
bool result = s.Run();
DCHECK_GT(db_.GetLastChangeCount(), 0);
return result;
}
-bool WebDatabase::RemoveCreditCard(int credit_card_id) {
- DCHECK_NE(0, credit_card_id);
- sql::Statement s(db_.GetUniqueStatement(
- "DELETE FROM credit_cards WHERE unique_id = ?"));
- if (!s) {
- NOTREACHED() << "Statement prepare failed";
- return false;
- }
-
- s.BindInt(0, credit_card_id);
- return s.Run();
-}
-
bool WebDatabase::RemoveCreditCard(const std::string& guid) {
DCHECK(guid::IsValidGUID(guid));
sql::Statement s(db_.GetUniqueStatement(
@@ -2194,13 +2059,23 @@ sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded(){
NOTREACHED();
return sql::INIT_FAILURE;
}
- query = "DELETE FROM credit_cards WHERE (" + credit_cards_is_too_big +
- ") OR label IN (SELECT label FROM autofill_profiles WHERE " +
- autofill_profiles_is_too_big + ")";
- if (!db_.Execute(query.c_str())) {
- LOG(WARNING) << "Unable to update web database to version 24.";
- NOTREACHED();
- return sql::INIT_FAILURE;
+ // Only delete from legacy credit card tables where specific columns
+ // exist.
+ if (db_.DoesColumnExist("credit_cards", "label") &&
+ db_.DoesColumnExist("credit_cards", "name_on_card") &&
+ db_.DoesColumnExist("credit_cards", "type") &&
+ db_.DoesColumnExist("credit_cards", "expiration_month") &&
+ db_.DoesColumnExist("credit_cards", "expiration_year") &&
+ db_.DoesColumnExist("credit_cards", "billing_address") &&
+ db_.DoesColumnExist("credit_cards", "shipping_address")) {
+ query = "DELETE FROM credit_cards WHERE (" + credit_cards_is_too_big +
+ ") OR label IN (SELECT label FROM autofill_profiles WHERE " +
+ autofill_profiles_is_too_big + ")";
+ if (!db_.Execute(query.c_str())) {
+ LOG(WARNING) << "Unable to update web database to version 24.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
}
query = "DELETE FROM autofill_profiles WHERE " +
autofill_profiles_is_too_big;
@@ -2243,30 +2118,19 @@ sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded(){
// FALL THROUGH
case 26: {
- // Change the credit_cards.billing_address column from a string to an int.
- // The stored string is the label of an address, so we have to select the
- // unique ID of this address using the label as a foreign key into the
- // |autofill_profiles| table.
- std::string stmt =
- "SELECT credit_cards.unique_id, autofill_profiles.unique_id "
- "FROM autofill_profiles, credit_cards "
- "WHERE credit_cards.billing_address = autofill_profiles.label";
- sql::Statement s(db_.GetUniqueStatement(stmt.c_str()));
- if (!s) {
- LOG(WARNING) << "Statement prepare failed";
- NOTREACHED();
- return sql::INIT_FAILURE;
- }
-
- std::map<int, int> cc_billing_map;
- while (s.Step())
- cc_billing_map[s.ColumnInt(0)] = s.ColumnInt(1);
-
- // Windows already stores the IDs as strings in |billing_address|. Try to
- // convert those.
- if (cc_billing_map.empty()) {
+ // Only migrate from legacy credit card tables where specific columns
+ // exist.
+ if (db_.DoesColumnExist("credit_cards", "unique_id") &&
+ db_.DoesColumnExist("credit_cards", "billing_address") &&
+ db_.DoesColumnExist("autofill_profiles", "unique_id")) {
+ // Change the credit_cards.billing_address column from a string to an
+ // int. The stored string is the label of an address, so we have to
+ // select the unique ID of this address using the label as a foreign
+ // key into the |autofill_profiles| table.
std::string stmt =
- "SELECT unique_id,billing_address FROM credit_cards";
+ "SELECT credit_cards.unique_id, autofill_profiles.unique_id "
+ "FROM autofill_profiles, credit_cards "
+ "WHERE credit_cards.billing_address = autofill_profiles.label";
sql::Statement s(db_.GetUniqueStatement(stmt.c_str()));
if (!s) {
LOG(WARNING) << "Statement prepare failed";
@@ -2274,74 +2138,91 @@ sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded(){
return sql::INIT_FAILURE;
}
- while (s.Step()) {
- int id = 0;
- if (base::StringToInt(s.ColumnString(1), &id))
- cc_billing_map[s.ColumnInt(0)] = id;
- }
- }
-
- if (!db_.Execute("CREATE TABLE credit_cards_temp ( "
- "label VARCHAR, "
- "unique_id INTEGER PRIMARY KEY, "
- "name_on_card VARCHAR, "
- "type VARCHAR, "
- "card_number VARCHAR, "
- "expiration_month INTEGER, "
- "expiration_year INTEGER, "
- "verification_code VARCHAR, "
- "billing_address INTEGER, "
- "shipping_address VARCHAR, "
- "card_number_encrypted BLOB, "
- "verification_code_encrypted BLOB)")) {
- LOG(WARNING) << "Unable to update web database to version 27.";
- NOTREACHED();
- return sql::INIT_FAILURE;
- }
-
- if (!db_.Execute(
- "INSERT INTO credit_cards_temp "
- "SELECT label,unique_id,name_on_card,type,card_number,"
- "expiration_month,expiration_year,verification_code,0,"
- "shipping_address,card_number_encrypted,verification_code_encrypted "
- "FROM credit_cards")) {
- LOG(WARNING) << "Unable to update web database to version 27.";
- NOTREACHED();
- return sql::INIT_FAILURE;
- }
+ std::map<int, int> cc_billing_map;
+ while (s.Step())
+ cc_billing_map[s.ColumnInt(0)] = s.ColumnInt(1);
+
+ // Windows already stores the IDs as strings in |billing_address|. Try
+ // to convert those.
+ if (cc_billing_map.empty()) {
+ std::string stmt =
+ "SELECT unique_id,billing_address FROM credit_cards";
+ sql::Statement s(db_.GetUniqueStatement(stmt.c_str()));
+ if (!s) {
+ LOG(WARNING) << "Statement prepare failed";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
- if (!db_.Execute("DROP TABLE credit_cards")) {
- LOG(WARNING) << "Unable to update web database to version 27.";
- NOTREACHED();
- return sql::INIT_FAILURE;
- }
+ while (s.Step()) {
+ int id = 0;
+ if (base::StringToInt(s.ColumnString(1), &id))
+ cc_billing_map[s.ColumnInt(0)] = id;
+ }
+ }
- if (!db_.Execute(
- "ALTER TABLE credit_cards_temp RENAME TO credit_cards")) {
- LOG(WARNING) << "Unable to update web database to version 27.";
- NOTREACHED();
- return sql::INIT_FAILURE;
- }
+ if (!db_.Execute("CREATE TABLE credit_cards_temp ( "
+ "label VARCHAR, "
+ "unique_id INTEGER PRIMARY KEY, "
+ "name_on_card VARCHAR, "
+ "type VARCHAR, "
+ "card_number VARCHAR, "
+ "expiration_month INTEGER, "
+ "expiration_year INTEGER, "
+ "verification_code VARCHAR, "
+ "billing_address INTEGER, "
+ "shipping_address VARCHAR, "
+ "card_number_encrypted BLOB, "
+ "verification_code_encrypted BLOB)")) {
+ LOG(WARNING) << "Unable to update web database to version 27.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
- for (std::map<int, int>::const_iterator iter = cc_billing_map.begin();
- iter != cc_billing_map.end(); ++iter) {
- sql::Statement s(db_.GetCachedStatement(
- SQL_FROM_HERE,
- "UPDATE credit_cards SET billing_address=? WHERE unique_id=?"));
- if (!s) {
- LOG(WARNING) << "Statement prepare failed";
+ if (!db_.Execute(
+ "INSERT INTO credit_cards_temp "
+ "SELECT label,unique_id,name_on_card,type,card_number,"
+ "expiration_month,expiration_year,verification_code,0,"
+ "shipping_address,card_number_encrypted,verification_code_encrypted "
+ "FROM credit_cards")) {
+ LOG(WARNING) << "Unable to update web database to version 27.";
NOTREACHED();
return sql::INIT_FAILURE;
}
- s.BindInt(0, (*iter).second);
- s.BindInt(1, (*iter).first);
+ if (!db_.Execute("DROP TABLE credit_cards")) {
+ LOG(WARNING) << "Unable to update web database to version 27.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
- if (!s.Run()) {
+ if (!db_.Execute(
+ "ALTER TABLE credit_cards_temp RENAME TO credit_cards")) {
LOG(WARNING) << "Unable to update web database to version 27.";
NOTREACHED();
return sql::INIT_FAILURE;
}
+
+ for (std::map<int, int>::const_iterator iter = cc_billing_map.begin();
+ iter != cc_billing_map.end(); ++iter) {
+ sql::Statement s(db_.GetCachedStatement(
+ SQL_FROM_HERE,
+ "UPDATE credit_cards SET billing_address=? WHERE unique_id=?"));
+ if (!s) {
+ LOG(WARNING) << "Statement prepare failed";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+
+ s.BindInt(0, (*iter).second);
+ s.BindInt(1, (*iter).first);
+
+ if (!s.Run()) {
+ LOG(WARNING) << "Unable to update web database to version 27.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+ }
}
meta_table_.SetVersionNumber(27);
@@ -2499,35 +2380,35 @@ sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded(){
NOTREACHED();
return sql::INIT_FAILURE;
}
- }
-
- // Set all the |guid| fields to valid values.
- {
- sql::Statement s(db_.GetUniqueStatement("SELECT unique_id "
- "FROM autofill_profiles"));
- if (!s) {
- LOG(WARNING) << "Unable to update web database to version 30.";
- NOTREACHED();
- return sql::INIT_FAILURE;
- }
+ // Set all the |guid| fields to valid values.
+ {
+ sql::Statement s(db_.GetUniqueStatement("SELECT unique_id "
+ "FROM autofill_profiles"));
- while (s.Step()) {
- sql::Statement update_s(
- db_.GetUniqueStatement("UPDATE autofill_profiles "
- "SET guid=? WHERE unique_id=?"));
- if (!update_s) {
+ if (!s) {
LOG(WARNING) << "Unable to update web database to version 30.";
NOTREACHED();
return sql::INIT_FAILURE;
}
- update_s.BindString(0, guid::GenerateGUID());
- update_s.BindInt(1, s.ColumnInt(0));
- if (!update_s.Run()) {
- LOG(WARNING) << "Unable to update web database to version 30.";
- NOTREACHED();
- return sql::INIT_FAILURE;
+ while (s.Step()) {
+ sql::Statement update_s(
+ db_.GetUniqueStatement("UPDATE autofill_profiles "
+ "SET guid=? WHERE unique_id=?"));
+ if (!update_s) {
+ LOG(WARNING) << "Unable to update web database to version 30.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+ update_s.BindString(0, guid::GenerateGUID());
+ update_s.BindInt(1, s.ColumnInt(0));
+
+ if (!update_s.Run()) {
+ LOG(WARNING) << "Unable to update web database to version 30.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
}
}
}
@@ -2543,34 +2424,34 @@ sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded(){
NOTREACHED();
return sql::INIT_FAILURE;
}
- }
- // Set all the |guid| fields to valid values.
- {
- sql::Statement s(db_.GetUniqueStatement("SELECT unique_id "
- "FROM credit_cards"));
- if (!s) {
- LOG(WARNING) << "Unable to update web database to version 30.";
- NOTREACHED();
- return sql::INIT_FAILURE;
- }
-
- while (s.Step()) {
- sql::Statement update_s(
- db_.GetUniqueStatement("UPDATE credit_cards "
- "set guid=? WHERE unique_id=?"));
- if (!update_s) {
+ // Set all the |guid| fields to valid values.
+ {
+ sql::Statement s(db_.GetUniqueStatement("SELECT unique_id "
+ "FROM credit_cards"));
+ if (!s) {
LOG(WARNING) << "Unable to update web database to version 30.";
NOTREACHED();
return sql::INIT_FAILURE;
}
- update_s.BindString(0, guid::GenerateGUID());
- update_s.BindInt(1, s.ColumnInt(0));
- if (!update_s.Run()) {
- LOG(WARNING) << "Unable to update web database to version 30.";
- NOTREACHED();
- return sql::INIT_FAILURE;
+ while (s.Step()) {
+ sql::Statement update_s(
+ db_.GetUniqueStatement("UPDATE credit_cards "
+ "set guid=? WHERE unique_id=?"));
+ if (!update_s) {
+ LOG(WARNING) << "Unable to update web database to version 30.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+ update_s.BindString(0, guid::GenerateGUID());
+ update_s.BindInt(1, s.ColumnInt(0));
+
+ if (!update_s.Run()) {
+ LOG(WARNING) << "Unable to update web database to version 30.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
}
}
}
@@ -2581,6 +2462,99 @@ sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded(){
// FALL THROUGH
+ case 31:
+ if (db_.DoesColumnExist("autofill_profiles", "unique_id")) {
+ if (!db_.Execute("CREATE TABLE autofill_profiles_temp ( "
+ "guid VARCHAR PRIMARY KEY, "
+ "label VARCHAR, "
+ "first_name VARCHAR, "
+ "middle_name VARCHAR, "
+ "last_name VARCHAR, "
+ "email VARCHAR, "
+ "company_name VARCHAR, "
+ "address_line_1 VARCHAR, "
+ "address_line_2 VARCHAR, "
+ "city VARCHAR, "
+ "state VARCHAR, "
+ "zipcode VARCHAR, "
+ "country VARCHAR, "
+ "phone VARCHAR, "
+ "fax VARCHAR, "
+ "date_modified INTEGER NOT NULL DEFAULT 0)")) {
+ LOG(WARNING) << "Unable to update web database to version 32.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+
+ if (!db_.Execute(
+ "INSERT INTO autofill_profiles_temp "
+ "SELECT guid, label, first_name, middle_name, last_name, email, "
+ "company_name, address_line_1, address_line_2, city, state, zipcode, "
+ "country, phone, fax, date_modified "
+ "FROM autofill_profiles")) {
+ LOG(WARNING) << "Unable to update web database to version 32.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+
+ if (!db_.Execute("DROP TABLE autofill_profiles")) {
+ LOG(WARNING) << "Unable to update web database to version 32.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+
+ if (!db_.Execute(
+ "ALTER TABLE autofill_profiles_temp RENAME TO autofill_profiles")) {
+ LOG(WARNING) << "Unable to update web database to version 32.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+ }
+
+ if (db_.DoesColumnExist("credit_cards", "unique_id")) {
+ if (!db_.Execute("CREATE TABLE credit_cards_temp ( "
+ "guid VARCHAR PRIMARY KEY, "
+ "label VARCHAR, "
+ "name_on_card VARCHAR, "
+ "expiration_month INTEGER, "
+ "expiration_year INTEGER, "
+ "card_number_encrypted BLOB, "
+ "date_modified INTEGER NOT NULL DEFAULT 0)")) {
+ LOG(WARNING) << "Unable to update web database to version 32.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+
+ if (!db_.Execute(
+ "INSERT INTO credit_cards_temp "
+ "SELECT guid, label, name_on_card, expiration_month, "
+ "expiration_year, card_number_encrypted, date_modified "
+ "FROM credit_cards")) {
+ LOG(WARNING) << "Unable to update web database to version 32.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+
+ if (!db_.Execute("DROP TABLE credit_cards")) {
+ LOG(WARNING) << "Unable to update web database to version 32.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+
+ if (!db_.Execute(
+ "ALTER TABLE credit_cards_temp RENAME TO credit_cards")) {
+ LOG(WARNING) << "Unable to update web database to version 32.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+ }
+
+ meta_table_.SetVersionNumber(32);
+ meta_table_.SetCompatibleVersionNumber(
+ std::min(32, kCompatibleVersionNumber));
+
+ // FALL THROUGH
+
// Add successive versions here. Each should set the version number and
// compatible version number as appropriate, then fall through to the next
// case.
diff --git a/chrome/browser/webdata/web_database.h b/chrome/browser/webdata/web_database.h
index e7fd295..2d80437 100644
--- a/chrome/browser/webdata/web_database.h
+++ b/chrome/browser/webdata/web_database.h
@@ -226,21 +226,10 @@ class WebDatabase {
// Updates the database values for the specified profile.
virtual bool UpdateAutoFillProfile(const AutoFillProfile& profile);
- // Removes a row from the autofill_profiles table. |profile_id| is the
- // unique ID of the profile to remove.
- // DEPRECATED: In favor of |RemoveAutoFillProfile(const std::string& guid)|.
- // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813
- virtual bool RemoveAutoFillProfile(int profile_id);
-
// Removes a row from the autofill_profiles table. |guid| is the identifier
// of the profile to remove.
virtual bool RemoveAutoFillProfile(const std::string& guid);
- // Retrieves profile for unique id |profile_id|, owned by caller.
- // DEPRECATED: In favor of |GetAutoFillProfileForGUID(...)|.
- // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813
- bool GetAutoFillProfileForID(int profile_id, AutoFillProfile** profile);
-
// Retrieves a profile with label |label|. The caller owns |profile|.
// DEPRECATED: In favor of |GetAutoFillProfileForGUID(...)|.
// TODO(dhollowa): Remove labels. http://crbug.com/58813
@@ -260,12 +249,6 @@ class WebDatabase {
// Updates the database values for the specified credit card.
bool UpdateCreditCard(const CreditCard& credit_card);
- // Removes a row from the credit_cards table. |credit_card_id| is the
- // unique ID of the credit card to remove.
- // DEPRECATED: In favor of |RemoveCreditCard(const std::string& guid)|.
- // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813
- bool RemoveCreditCard(int credit_card_id);
-
// Removes a row from the credit_cards table. |guid| is the identifer of the
// credit card to remove.
bool RemoveCreditCard(const std::string& guid);
@@ -277,11 +260,6 @@ class WebDatabase {
bool GetCreditCardForLabel(const string16& label,
CreditCard** credit_card);
- // Retrieves credit card for a card with unique id |credit_card_id|.
- // DEPRECATED: In favor of |GetCreditCardForGUID()|.
- // TODO(dhollowa): Remove unique IDs. http://crbug.com/58813
- bool GetCreditCardForID(int credit_card_id, CreditCard** credit_card);
-
// Retrieves a credit card with guid |guid|. The caller owns
// |credit_card_id|.
bool GetCreditCardForGUID(const std::string& guid, CreditCard** credit_card);
diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc
index 89cda5a..a49b7ee 100644
--- a/chrome/browser/webdata/web_database_unittest.cc
+++ b/chrome/browser/webdata/web_database_unittest.cc
@@ -94,6 +94,115 @@ bool CompareAutofillEntries(const AutofillEntry& a, const AutofillEntry& b) {
return timestamps2.size() != 0U;
}
+void AutoFillProfile31FromStatement(const sql::Statement& s,
+ AutoFillProfile* profile,
+ string16* label,
+ int* unique_id,
+ int64* date_modified) {
+ DCHECK(profile);
+ DCHECK(label);
+ DCHECK(unique_id);
+ DCHECK(date_modified);
+ *label = s.ColumnString16(0);
+ *unique_id = s.ColumnInt(1);
+ profile->SetInfo(AutoFillType(NAME_FIRST), s.ColumnString16(2));
+ profile->SetInfo(AutoFillType(NAME_MIDDLE), s.ColumnString16(3));
+ profile->SetInfo(AutoFillType(NAME_LAST),s.ColumnString16(4));
+ profile->SetInfo(AutoFillType(EMAIL_ADDRESS), s.ColumnString16(5));
+ profile->SetInfo(AutoFillType(COMPANY_NAME), s.ColumnString16(6));
+ profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), s.ColumnString16(7));
+ profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2), s.ColumnString16(8));
+ profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY), s.ColumnString16(9));
+ profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE), s.ColumnString16(10));
+ profile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP), s.ColumnString16(11));
+ profile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), s.ColumnString16(12));
+ profile->SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), s.ColumnString16(13));
+ profile->SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), s.ColumnString16(14));
+ *date_modified = s.ColumnInt64(15);
+ profile->set_guid(s.ColumnString(16));
+ EXPECT_TRUE(guid::IsValidGUID(profile->guid()));
+}
+
+void AutoFillProfile32FromStatement(const sql::Statement& s,
+ AutoFillProfile* profile,
+ string16* label,
+ int64* date_modified) {
+ DCHECK(profile);
+ DCHECK(label);
+ DCHECK(date_modified);
+ profile->set_guid(s.ColumnString(0));
+ EXPECT_TRUE(guid::IsValidGUID(profile->guid()));
+ *label = s.ColumnString16(1);
+ profile->SetInfo(AutoFillType(NAME_FIRST), s.ColumnString16(2));
+ profile->SetInfo(AutoFillType(NAME_MIDDLE), s.ColumnString16(3));
+ profile->SetInfo(AutoFillType(NAME_LAST),s.ColumnString16(4));
+ profile->SetInfo(AutoFillType(EMAIL_ADDRESS), s.ColumnString16(5));
+ profile->SetInfo(AutoFillType(COMPANY_NAME), s.ColumnString16(6));
+ profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), s.ColumnString16(7));
+ profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2), s.ColumnString16(8));
+ profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY), s.ColumnString16(9));
+ profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE), s.ColumnString16(10));
+ profile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP), s.ColumnString16(11));
+ profile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), s.ColumnString16(12));
+ profile->SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), s.ColumnString16(13));
+ profile->SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), s.ColumnString16(14));
+ *date_modified = s.ColumnInt64(15);
+}
+
+void CreditCard31FromStatement(const sql::Statement& s,
+ CreditCard* credit_card,
+ string16* label,
+ int* unique_id,
+ std::string* encrypted_number,
+ int64* date_modified) {
+ DCHECK(credit_card);
+ DCHECK(label);
+ DCHECK(unique_id);
+ DCHECK(encrypted_number);
+ DCHECK(date_modified);
+ *label = s.ColumnString16(0);
+ *unique_id = s.ColumnInt(1);
+ credit_card->SetInfo(AutoFillType(CREDIT_CARD_NAME), s.ColumnString16(2));
+ credit_card->SetInfo(AutoFillType(CREDIT_CARD_TYPE), s.ColumnString16(3));
+ credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH),
+ s.ColumnString16(5));
+ credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR),
+ s.ColumnString16(6));
+ int encrypted_number_len = s.ColumnByteLength(10);
+ if (encrypted_number_len) {
+ encrypted_number->resize(encrypted_number_len);
+ memcpy(&(*encrypted_number)[0], s.ColumnBlob(10), encrypted_number_len);
+ }
+ *date_modified = s.ColumnInt64(12);
+ credit_card->set_guid(s.ColumnString(13));
+ EXPECT_TRUE(guid::IsValidGUID(credit_card->guid()));
+}
+
+void CreditCard32FromStatement(const sql::Statement& s,
+ CreditCard* credit_card,
+ string16* label,
+ std::string* encrypted_number,
+ int64* date_modified) {
+ DCHECK(credit_card);
+ DCHECK(label);
+ DCHECK(encrypted_number);
+ DCHECK(date_modified);
+ credit_card->set_guid(s.ColumnString(0));
+ EXPECT_TRUE(guid::IsValidGUID(credit_card->guid()));
+ *label = s.ColumnString16(1);
+ credit_card->SetInfo(AutoFillType(CREDIT_CARD_NAME), s.ColumnString16(2));
+ credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH),
+ s.ColumnString16(3));
+ credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR),
+ s.ColumnString16(4));
+ int encrypted_number_len = s.ColumnByteLength(5);
+ if (encrypted_number_len) {
+ encrypted_number->resize(encrypted_number_len);
+ memcpy(&(*encrypted_number)[0], s.ColumnBlob(5), encrypted_number_len);
+ }
+ *date_modified = s.ColumnInt64(6);
+}
+
} // namespace
class WebDatabaseTest : public testing::Test {
@@ -1258,7 +1367,8 @@ TEST_F(WebDatabaseTest, AutoFillProfile) {
ASSERT_EQ(sql::INIT_OK, db.Init(file_));
// Add a 'Home' profile.
- AutoFillProfile home_profile(ASCIIToUTF16("Home"), 17);
+ AutoFillProfile home_profile;
+ home_profile.set_label(ASCIIToUTF16("Home"));
home_profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("John"));
home_profile.SetInfo(AutoFillType(NAME_MIDDLE), ASCIIToUTF16("Q."));
home_profile.SetInfo(AutoFillType(NAME_LAST), ASCIIToUTF16("Smith"));
@@ -1288,18 +1398,18 @@ TEST_F(WebDatabaseTest, AutoFillProfile) {
ASSERT_TRUE(db.GetAutoFillProfileForLabel(ASCIIToUTF16("Home"), &db_profile));
EXPECT_EQ(home_profile, *db_profile);
sql::Statement s_home(db.db_.GetUniqueStatement(
- "SELECT * FROM autofill_profiles WHERE label='Home'"));
+ "SELECT date_modified "
+ "FROM autofill_profiles WHERE label='Home'"));
ASSERT_TRUE(s_home);
ASSERT_TRUE(s_home.Step());
- EXPECT_GE(s_home.ColumnInt64(15), pre_creation_time.ToTimeT());
- EXPECT_LE(s_home.ColumnInt64(15), post_creation_time.ToTimeT());
+ EXPECT_GE(s_home.ColumnInt64(0), pre_creation_time.ToTimeT());
+ EXPECT_LE(s_home.ColumnInt64(0), post_creation_time.ToTimeT());
EXPECT_FALSE(s_home.Step());
delete db_profile;
// Add a 'Billing' profile.
AutoFillProfile billing_profile = home_profile;
billing_profile.set_label(ASCIIToUTF16("Billing"));
- billing_profile.set_unique_id(13);
billing_profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1),
ASCIIToUTF16("5678 Bottom Street"));
billing_profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2),
@@ -1315,11 +1425,11 @@ TEST_F(WebDatabaseTest, AutoFillProfile) {
&db_profile));
EXPECT_EQ(billing_profile, *db_profile);
sql::Statement s_billing(db.db_.GetUniqueStatement(
- "SELECT * FROM autofill_profiles WHERE label='Billing'"));
+ "SELECT date_modified FROM autofill_profiles WHERE label='Billing'"));
ASSERT_TRUE(s_billing);
ASSERT_TRUE(s_billing.Step());
- EXPECT_GE(s_billing.ColumnInt64(15), pre_creation_time.ToTimeT());
- EXPECT_LE(s_billing.ColumnInt64(15), post_creation_time.ToTimeT());
+ EXPECT_GE(s_billing.ColumnInt64(0), pre_creation_time.ToTimeT());
+ EXPECT_LE(s_billing.ColumnInt64(0), post_creation_time.ToTimeT());
EXPECT_FALSE(s_billing.Step());
delete db_profile;
@@ -1332,25 +1442,24 @@ TEST_F(WebDatabaseTest, AutoFillProfile) {
&db_profile));
EXPECT_EQ(billing_profile, *db_profile);
sql::Statement s_billing_updated(db.db_.GetUniqueStatement(
- "SELECT * FROM autofill_profiles WHERE label='Billing'"));
+ "SELECT date_modified FROM autofill_profiles WHERE label='Billing'"));
ASSERT_TRUE(s_billing_updated);
ASSERT_TRUE(s_billing_updated.Step());
- EXPECT_GE(s_billing_updated.ColumnInt64(15),
+ EXPECT_GE(s_billing_updated.ColumnInt64(0),
pre_modification_time.ToTimeT());
- EXPECT_LE(s_billing_updated.ColumnInt64(15),
+ EXPECT_LE(s_billing_updated.ColumnInt64(0),
post_modification_time.ToTimeT());
EXPECT_FALSE(s_billing_updated.Step());
delete db_profile;
// Remove the 'Billing' profile.
- EXPECT_TRUE(db.RemoveAutoFillProfile(billing_profile.unique_id()));
+ EXPECT_TRUE(db.RemoveAutoFillProfile(billing_profile.guid()));
EXPECT_FALSE(db.GetAutoFillProfileForLabel(ASCIIToUTF16("Billing"),
&db_profile));
// Add a 'GUID' profile.
AutoFillProfile guid_profile = home_profile;
guid_profile.set_label(ASCIIToUTF16("GUID"));
- guid_profile.set_unique_id(14);
guid_profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1),
ASCIIToUTF16("5678 Top Street"));
guid_profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2),
@@ -1383,11 +1492,10 @@ TEST_F(WebDatabaseTest, CreditCard) {
ASSERT_EQ(sql::INIT_OK, db.Init(file_));
// Add a 'Work' credit card.
- CreditCard work_creditcard(ASCIIToUTF16("Work"), 13);
+ CreditCard work_creditcard;
+ work_creditcard.set_label(ASCIIToUTF16("Work"));
work_creditcard.SetInfo(AutoFillType(CREDIT_CARD_NAME),
ASCIIToUTF16("Jack Torrance"));
- work_creditcard.SetInfo(AutoFillType(CREDIT_CARD_TYPE),
- ASCIIToUTF16("Visa"));
work_creditcard.SetInfo(AutoFillType(CREDIT_CARD_NUMBER),
ASCIIToUTF16("1234567890123456"));
work_creditcard.SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH),
@@ -1404,20 +1512,21 @@ TEST_F(WebDatabaseTest, CreditCard) {
ASSERT_TRUE(db.GetCreditCardForLabel(ASCIIToUTF16("Work"), &db_creditcard));
EXPECT_EQ(work_creditcard, *db_creditcard);
sql::Statement s_work(db.db_.GetUniqueStatement(
- "SELECT * FROM credit_cards WHERE label='Work'"));
+ "SELECT guid, label, name_on_card, expiration_month, expiration_year, "
+ "card_number_encrypted, date_modified "
+ "FROM credit_cards WHERE label='Work'"));
ASSERT_TRUE(s_work);
ASSERT_TRUE(s_work.Step());
- EXPECT_GE(s_work.ColumnInt64(12), pre_creation_time.ToTimeT());
- EXPECT_LE(s_work.ColumnInt64(12), post_creation_time.ToTimeT());
+ EXPECT_GE(s_work.ColumnInt64(6), pre_creation_time.ToTimeT());
+ EXPECT_LE(s_work.ColumnInt64(6), post_creation_time.ToTimeT());
EXPECT_FALSE(s_work.Step());
delete db_creditcard;
// Add a 'Target' credit card.
- CreditCard target_creditcard(ASCIIToUTF16("Target"), 7);
+ CreditCard target_creditcard;
+ target_creditcard.set_label(ASCIIToUTF16("Target"));
target_creditcard.SetInfo(AutoFillType(CREDIT_CARD_NAME),
ASCIIToUTF16("Jack Torrance"));
- target_creditcard.SetInfo(AutoFillType(CREDIT_CARD_TYPE),
- ASCIIToUTF16("Mastercard"));
target_creditcard.SetInfo(AutoFillType(CREDIT_CARD_NUMBER),
ASCIIToUTF16("1111222233334444"));
target_creditcard.SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH),
@@ -1432,11 +1541,13 @@ TEST_F(WebDatabaseTest, CreditCard) {
&db_creditcard));
EXPECT_EQ(target_creditcard, *db_creditcard);
sql::Statement s_target(db.db_.GetUniqueStatement(
- "SELECT * FROM credit_cards WHERE label='Target'"));
+ "SELECT guid, label, name_on_card, expiration_month, expiration_year, "
+ "card_number_encrypted, date_modified "
+ "FROM credit_cards WHERE label='Target'"));
ASSERT_TRUE(s_target);
ASSERT_TRUE(s_target.Step());
- EXPECT_GE(s_target.ColumnInt64(12), pre_creation_time.ToTimeT());
- EXPECT_LE(s_target.ColumnInt64(12), post_creation_time.ToTimeT());
+ EXPECT_GE(s_target.ColumnInt64(6), pre_creation_time.ToTimeT());
+ EXPECT_LE(s_target.ColumnInt64(6), post_creation_time.ToTimeT());
EXPECT_FALSE(s_target.Step());
delete db_creditcard;
@@ -1449,27 +1560,28 @@ TEST_F(WebDatabaseTest, CreditCard) {
ASSERT_TRUE(db.GetCreditCardForLabel(ASCIIToUTF16("Target"), &db_creditcard));
EXPECT_EQ(target_creditcard, *db_creditcard);
sql::Statement s_target_updated(db.db_.GetUniqueStatement(
- "SELECT * FROM credit_cards WHERE label='Target'"));
+ "SELECT guid, label, name_on_card, expiration_month, expiration_year, "
+ "card_number_encrypted, date_modified "
+ "FROM credit_cards WHERE label='Target'"));
ASSERT_TRUE(s_target_updated);
ASSERT_TRUE(s_target_updated.Step());
- EXPECT_GE(s_target_updated.ColumnInt64(12),
+ EXPECT_GE(s_target_updated.ColumnInt64(6),
pre_modification_time.ToTimeT());
- EXPECT_LE(s_target_updated.ColumnInt64(12),
+ EXPECT_LE(s_target_updated.ColumnInt64(6),
post_modification_time.ToTimeT());
EXPECT_FALSE(s_target_updated.Step());
delete db_creditcard;
// Remove the 'Target' credit card.
- EXPECT_TRUE(db.RemoveCreditCard(target_creditcard.unique_id()));
+ EXPECT_TRUE(db.RemoveCreditCard(target_creditcard.guid()));
EXPECT_FALSE(db.GetCreditCardForLabel(ASCIIToUTF16("Target"),
&db_creditcard));
// Add a 'GUID' profile.
- CreditCard guid_creditcard(ASCIIToUTF16("GUID"), 7);
+ CreditCard guid_creditcard;
+ guid_creditcard.set_label(ASCIIToUTF16("GUID"));
guid_creditcard.SetInfo(AutoFillType(CREDIT_CARD_NAME),
ASCIIToUTF16("Jimmy Jones"));
- guid_creditcard.SetInfo(AutoFillType(CREDIT_CARD_TYPE),
- ASCIIToUTF16("Amex"));
guid_creditcard.SetInfo(AutoFillType(CREDIT_CARD_NUMBER),
ASCIIToUTF16("9999222233334444"));
guid_creditcard.SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH),
@@ -1503,84 +1615,84 @@ TEST_F(WebDatabaseTest, RemoveAutoFillProfilesAndCreditCardsModifiedBetween) {
// Populate the autofill_profiles and credit_cards tables.
ASSERT_TRUE(db.db_.Execute(
- "INSERT INTO \"autofill_profiles\" VALUES('P1',1,'','','','','','','','',"
- "'','','','','',11,'00000000-0000-0000-0000-000000000000');"
- "INSERT INTO \"autofill_profiles\" VALUES('P2',2,'','','','','','','','',"
- "'','','','','',21,'00000000-0000-0000-0000-000000000001');"
- "INSERT INTO \"autofill_profiles\" VALUES('P3',3,'','','','','','','','',"
- "'','','','','',31,'00000000-0000-0000-0000-000000000002');"
- "INSERT INTO \"autofill_profiles\" VALUES('P4',4,'','','','','','','','',"
- "'','','','','',41,'00000000-0000-0000-0000-000000000003');"
- "INSERT INTO \"autofill_profiles\" VALUES('P5',5,'','','','','','','','',"
- "'','','','','',51,'00000000-0000-0000-0000-000000000004');"
- "INSERT INTO \"autofill_profiles\" VALUES('P6',6,'','','','','','','','',"
- "'','','','','',61,'00000000-0000-0000-0000-000000000005');"
- "INSERT INTO \"credit_cards\" VALUES('C10',10,'','','',10,2010,'','','',"
- "X'',X'',17,'00000000-0000-0000-0000-000000000006');"
- "INSERT INTO \"credit_cards\" VALUES('C20',20,'','','',10,2010,'','','',"
- "X'',X'',27,'00000000-0000-0000-0000-000000000007');"
- "INSERT INTO \"credit_cards\" VALUES('C30',30,'','','',10,2010,'','','',"
- "X'',X'',37,'00000000-0000-0000-0000-000000000008');"
- "INSERT INTO \"credit_cards\" VALUES('C40',40,'','','',10,2010,'','','',"
- "X'',X'',47,'00000000-0000-0000-0000-000000000009');"
- "INSERT INTO \"credit_cards\" VALUES('C50',50,'','','',10,2010,'','','',"
- "X'',X'',57,'00000000-0000-0000-0000-000000000010');"
- "INSERT INTO \"credit_cards\" VALUES('C60',60,'','','',10,2010,'','','',"
- "X'',X'',67,'00000000-0000-0000-0000-000000000011');"));
+ "INSERT INTO autofill_profiles (guid, date_modified) "
+ "VALUES('00000000-0000-0000-0000-000000000000', 11);"
+ "INSERT INTO autofill_profiles (guid, date_modified) "
+ "VALUES('00000000-0000-0000-0000-000000000001', 21);"
+ "INSERT INTO autofill_profiles (guid, date_modified) "
+ "VALUES('00000000-0000-0000-0000-000000000002', 31);"
+ "INSERT INTO autofill_profiles (guid, date_modified) "
+ "VALUES('00000000-0000-0000-0000-000000000003', 41);"
+ "INSERT INTO autofill_profiles (guid, date_modified) "
+ "VALUES('00000000-0000-0000-0000-000000000004', 51);"
+ "INSERT INTO autofill_profiles (guid, date_modified) "
+ "VALUES('00000000-0000-0000-0000-000000000005', 61);"
+ "INSERT INTO credit_cards (guid, date_modified) "
+ "VALUES('00000000-0000-0000-0000-000000000006', 17);"
+ "INSERT INTO credit_cards (guid, date_modified) "
+ "VALUES('00000000-0000-0000-0000-000000000007', 27);"
+ "INSERT INTO credit_cards (guid, date_modified) "
+ "VALUES('00000000-0000-0000-0000-000000000008', 37);"
+ "INSERT INTO credit_cards (guid, date_modified) "
+ "VALUES('00000000-0000-0000-0000-000000000009', 47);"
+ "INSERT INTO credit_cards (guid, date_modified) "
+ "VALUES('00000000-0000-0000-0000-000000000010', 57);"
+ "INSERT INTO credit_cards (guid, date_modified) "
+ "VALUES('00000000-0000-0000-0000-000000000011', 67);"));
// Remove all entries modified in the bounded time range [17,41).
db.RemoveAutoFillProfilesAndCreditCardsModifiedBetween(
base::Time::FromTimeT(17), base::Time::FromTimeT(41));
sql::Statement s_autofill_profiles_bounded(db.db_.GetUniqueStatement(
- "SELECT * FROM autofill_profiles"));
+ "SELECT date_modified FROM autofill_profiles"));
ASSERT_TRUE(s_autofill_profiles_bounded);
ASSERT_TRUE(s_autofill_profiles_bounded.Step());
- EXPECT_EQ(11, s_autofill_profiles_bounded.ColumnInt64(15));
+ EXPECT_EQ(11, s_autofill_profiles_bounded.ColumnInt64(0));
ASSERT_TRUE(s_autofill_profiles_bounded.Step());
- EXPECT_EQ(41, s_autofill_profiles_bounded.ColumnInt64(15));
+ EXPECT_EQ(41, s_autofill_profiles_bounded.ColumnInt64(0));
ASSERT_TRUE(s_autofill_profiles_bounded.Step());
- EXPECT_EQ(51, s_autofill_profiles_bounded.ColumnInt64(15));
+ EXPECT_EQ(51, s_autofill_profiles_bounded.ColumnInt64(0));
ASSERT_TRUE(s_autofill_profiles_bounded.Step());
- EXPECT_EQ(61, s_autofill_profiles_bounded.ColumnInt64(15));
+ EXPECT_EQ(61, s_autofill_profiles_bounded.ColumnInt64(0));
EXPECT_FALSE(s_autofill_profiles_bounded.Step());
sql::Statement s_credit_cards_bounded(db.db_.GetUniqueStatement(
- "SELECT * FROM credit_cards"));
+ "SELECT date_modified FROM credit_cards"));
ASSERT_TRUE(s_credit_cards_bounded);
ASSERT_TRUE(s_credit_cards_bounded.Step());
- EXPECT_EQ(47, s_credit_cards_bounded.ColumnInt64(12));
+ EXPECT_EQ(47, s_credit_cards_bounded.ColumnInt64(0));
ASSERT_TRUE(s_credit_cards_bounded.Step());
- EXPECT_EQ(57, s_credit_cards_bounded.ColumnInt64(12));
+ EXPECT_EQ(57, s_credit_cards_bounded.ColumnInt64(0));
ASSERT_TRUE(s_credit_cards_bounded.Step());
- EXPECT_EQ(67, s_credit_cards_bounded.ColumnInt64(12));
+ EXPECT_EQ(67, s_credit_cards_bounded.ColumnInt64(0));
EXPECT_FALSE(s_credit_cards_bounded.Step());
// Remove all entries modified on or after time 51 (unbounded range).
db.RemoveAutoFillProfilesAndCreditCardsModifiedBetween(
base::Time::FromTimeT(51), base::Time());
sql::Statement s_autofill_profiles_unbounded(db.db_.GetUniqueStatement(
- "SELECT * FROM autofill_profiles"));
+ "SELECT date_modified FROM autofill_profiles"));
ASSERT_TRUE(s_autofill_profiles_unbounded);
ASSERT_TRUE(s_autofill_profiles_unbounded.Step());
- EXPECT_EQ(11, s_autofill_profiles_unbounded.ColumnInt64(15));
+ EXPECT_EQ(11, s_autofill_profiles_unbounded.ColumnInt64(0));
ASSERT_TRUE(s_autofill_profiles_unbounded.Step());
- EXPECT_EQ(41, s_autofill_profiles_unbounded.ColumnInt64(15));
+ EXPECT_EQ(41, s_autofill_profiles_unbounded.ColumnInt64(0));
EXPECT_FALSE(s_autofill_profiles_unbounded.Step());
sql::Statement s_credit_cards_unbounded(db.db_.GetUniqueStatement(
- "SELECT * FROM credit_cards"));
+ "SELECT date_modified FROM credit_cards"));
ASSERT_TRUE(s_credit_cards_unbounded);
ASSERT_TRUE(s_credit_cards_unbounded.Step());
- EXPECT_EQ(47, s_credit_cards_unbounded.ColumnInt64(12));
+ EXPECT_EQ(47, s_credit_cards_unbounded.ColumnInt64(0));
EXPECT_FALSE(s_credit_cards_unbounded.Step());
// Remove all remaining entries.
db.RemoveAutoFillProfilesAndCreditCardsModifiedBetween(base::Time(),
base::Time());
sql::Statement s_autofill_profiles_empty(db.db_.GetUniqueStatement(
- "SELECT * FROM autofill_profiles"));
+ "SELECT date_modified FROM autofill_profiles"));
ASSERT_TRUE(s_autofill_profiles_empty);
EXPECT_FALSE(s_autofill_profiles_empty.Step());
sql::Statement s_credit_cards_empty(db.db_.GetUniqueStatement(
- "SELECT * FROM credit_cards"));
+ "SELECT date_modified FROM credit_cards"));
ASSERT_TRUE(s_credit_cards_empty);
EXPECT_FALSE(s_credit_cards_empty.Step());
}
@@ -1813,7 +1925,7 @@ class WebDatabaseMigrationTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest);
};
-const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 31;
+const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 32;
void WebDatabaseMigrationTest::LoadDatabase(const FilePath& file) {
std::string contents;
@@ -1931,7 +2043,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion22ToCurrent) {
ASSERT_TRUE(connection.Open(GetDatabasePath()));
// No |credit_card| table prior to version 23.
- ASSERT_FALSE(connection.DoesColumnExist("credit_cards", "unique_id"));
+ ASSERT_FALSE(connection.DoesColumnExist("credit_cards", "guid"));
ASSERT_FALSE(
connection.DoesColumnExist("credit_cards", "card_number_encrypted"));
}
@@ -1953,7 +2065,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion22ToCurrent) {
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
// |credit_card| table now exists.
- EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "unique_id"));
+ EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "guid"));
EXPECT_TRUE(
connection.DoesColumnExist("credit_cards", "card_number_encrypted"));
}
@@ -2003,7 +2115,8 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion22CorruptedToCurrent) {
// Columns existing and not existing before version 25.
- EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "unique_id"));
+ EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "unique_id"));
+ EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "guid"));
EXPECT_TRUE(
connection.DoesColumnExist("credit_cards", "card_number_encrypted"));
EXPECT_TRUE(connection.DoesColumnExist("keywords", "id"));
@@ -2146,24 +2259,20 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringLabels) {
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
- EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "billing_address"));
+ EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "billing_address"));
- // |billing_address| is an integer. Also Verify the credit card data is
- // converted.
- std::string stmt = "SELECT * FROM credit_cards";
- sql::Statement s(connection.GetUniqueStatement(stmt.c_str()));
+ // Verify the credit card data is converted.
+ sql::Statement s(connection.GetUniqueStatement(
+ "SELECT guid, label, name_on_card, expiration_month, expiration_year, "
+ "card_number_encrypted, date_modified "
+ "FROM credit_cards"));
ASSERT_TRUE(s.Step());
- EXPECT_EQ(s.ColumnType(8), sql::COLUMN_TYPE_INTEGER);
- EXPECT_EQ("label", s.ColumnString(0));
- EXPECT_EQ(2, s.ColumnInt(1));
+ EXPECT_EQ("label", s.ColumnString(1));
EXPECT_EQ("Jack", s.ColumnString(2));
- EXPECT_EQ("Visa", s.ColumnString(3));
- EXPECT_EQ("1234", s.ColumnString(4));
- EXPECT_EQ(2, s.ColumnInt(5));
- EXPECT_EQ(2012, s.ColumnInt(6));
- EXPECT_EQ(std::string(), s.ColumnString(7));
- EXPECT_EQ(1, s.ColumnInt(8));
- // The remaining columns are unused or blobs.
+ EXPECT_EQ(2, s.ColumnInt(3));
+ EXPECT_EQ(2012, s.ColumnInt(4));
+ // Column 5 is encrypted number blob.
+ // Column 6 is date_modified.
}
}
@@ -2226,24 +2335,20 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringIDs) {
// |keywords| |logo_id| column should have been added.
EXPECT_TRUE(connection.DoesColumnExist("keywords", "id"));
EXPECT_TRUE(connection.DoesColumnExist("keywords", "created_by_policy"));
- EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "billing_address"));
+ EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "billing_address"));
- // |billing_address| is an integer. Also Verify the credit card data is
- // converted.
- std::string stmt = "SELECT * FROM credit_cards";
- sql::Statement s(connection.GetUniqueStatement(stmt.c_str()));
+ // Verify the credit card data is converted.
+ sql::Statement s(connection.GetUniqueStatement(
+ "SELECT guid, label, name_on_card, expiration_month, expiration_year, "
+ "card_number_encrypted, date_modified "
+ "FROM credit_cards"));
ASSERT_TRUE(s.Step());
- EXPECT_EQ(s.ColumnType(8), sql::COLUMN_TYPE_INTEGER);
- EXPECT_EQ("label", s.ColumnString(0));
- EXPECT_EQ(2, s.ColumnInt(1));
+ EXPECT_EQ("label", s.ColumnString(1));
EXPECT_EQ("Jack", s.ColumnString(2));
- EXPECT_EQ("Visa", s.ColumnString(3));
- EXPECT_EQ("1234", s.ColumnString(4));
- EXPECT_EQ(2, s.ColumnInt(5));
- EXPECT_EQ(2012, s.ColumnInt(6));
- EXPECT_EQ(std::string(), s.ColumnString(7));
- EXPECT_EQ(1, s.ColumnInt(8));
- // The remaining columns are unused or blobs.
+ EXPECT_EQ(2, s.ColumnInt(3));
+ EXPECT_EQ(2012, s.ColumnInt(4));
+ // Column 5 is encrypted credit card number blob.
+ // Column 6 is date_modified.
}
}
@@ -2330,23 +2435,23 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion29ToCurrent) {
"date_modified"));
sql::Statement s_profiles(connection.GetUniqueStatement(
- "SELECT * FROM autofill_profiles "));
+ "SELECT date_modified FROM autofill_profiles "));
ASSERT_TRUE(s_profiles);
while (s_profiles.Step()) {
- EXPECT_GE(s_profiles.ColumnInt64(15),
+ EXPECT_GE(s_profiles.ColumnInt64(0),
pre_creation_time.ToTimeT());
- EXPECT_LE(s_profiles.ColumnInt64(15),
+ EXPECT_LE(s_profiles.ColumnInt64(0),
post_creation_time.ToTimeT());
}
EXPECT_TRUE(s_profiles.Succeeded());
sql::Statement s_credit_cards(connection.GetUniqueStatement(
- "SELECT * FROM credit_cards "));
+ "SELECT date_modified FROM credit_cards "));
ASSERT_TRUE(s_credit_cards);
while (s_credit_cards.Step()) {
- EXPECT_GE(s_credit_cards.ColumnInt64(12),
+ EXPECT_GE(s_credit_cards.ColumnInt64(0),
pre_creation_time.ToTimeT());
- EXPECT_LE(s_credit_cards.ColumnInt64(12),
+ EXPECT_LE(s_credit_cards.ColumnInt64(0),
post_creation_time.ToTimeT());
}
EXPECT_TRUE(s_credit_cards.Succeeded());
@@ -2404,3 +2509,142 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion30ToCurrent) {
EXPECT_NE(guid1, guid2);
}
}
+
+// Removes unique IDs and make GUIDs the primary key. Also removes unused
+// columns.
+TEST_F(WebDatabaseMigrationTest, MigrateVersion31ToCurrent) {
+ // Initialize the database.
+ ASSERT_NO_FATAL_FAILURE(
+ LoadDatabase(FilePath(FILE_PATH_LITERAL("version_31.sql"))));
+
+ // Verify pre-conditions. These are expectations for version 30 of the
+ // database.
+ AutoFillProfile profile;
+ string16 profile_label;
+ int profile_unique_id = 0;
+ int64 profile_date_modified = 0;
+ CreditCard credit_card;
+ string16 cc_label;
+ int cc_unique_id = 0;
+ std::string cc_number_encrypted;
+ int64 cc_date_modified = 0;
+ {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+
+ // Verify existence of columns we'll be changing.
+ EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "guid"));
+ EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "unique_id"));
+ EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "guid"));
+ EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "unique_id"));
+ EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "type"));
+ EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "card_number"));
+ EXPECT_TRUE(connection.DoesColumnExist("credit_cards",
+ "verification_code"));
+ EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "billing_address"));
+ EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "shipping_address"));
+ EXPECT_TRUE(connection.DoesColumnExist("credit_cards",
+ "verification_code_encrypted"));
+
+ // Fetch data in the database prior to migration.
+ sql::Statement s1(
+ connection.GetUniqueStatement(
+ "SELECT label, unique_id, first_name, middle_name, last_name, "
+ "email, company_name, address_line_1, address_line_2, city, state, "
+ "zipcode, country, phone, fax, date_modified, guid "
+ "FROM autofill_profiles"));
+ ASSERT_TRUE(s1.Step());
+ EXPECT_NO_FATAL_FAILURE(AutoFillProfile31FromStatement(
+ s1, &profile, &profile_label, &profile_unique_id,
+ &profile_date_modified));
+
+ sql::Statement s2(
+ connection.GetUniqueStatement(
+ "SELECT label, unique_id, name_on_card, type, card_number, "
+ "expiration_month, expiration_year, verification_code, "
+ "billing_address, shipping_address, card_number_encrypted, "
+ "verification_code_encrypted, date_modified, guid "
+ "FROM credit_cards"));
+ ASSERT_TRUE(s2.Step());
+ EXPECT_NO_FATAL_FAILURE(CreditCard31FromStatement(s2,
+ &credit_card,
+ &cc_label,
+ &cc_unique_id,
+ &cc_number_encrypted,
+ &cc_date_modified));
+
+ EXPECT_NE(profile_unique_id, cc_unique_id);
+ EXPECT_NE(profile.guid(), credit_card.guid());
+ }
+
+ // Load the database via the WebDatabase class and migrate the database to
+ // the current version.
+ {
+ WebDatabase db;
+ ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath()));
+ }
+
+ // Verify post-conditions. These are expectations for current version of the
+ // database.
+ {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+
+ // Check version.
+ EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
+
+ // Verify existence of columns we'll be changing.
+ EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "guid"));
+ EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", "unique_id"));
+ EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "guid"));
+ EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "unique_id"));
+ EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "type"));
+ EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "card_number"));
+ EXPECT_FALSE(connection.DoesColumnExist("credit_cards",
+ "verification_code"));
+ EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "billing_address"));
+ EXPECT_FALSE(connection.DoesColumnExist("credit_cards",
+ "shipping_address"));
+ EXPECT_FALSE(connection.DoesColumnExist("credit_cards",
+ "verification_code_encrypted"));
+
+ // Verify data in the database after the migration.
+ sql::Statement s1(
+ connection.GetUniqueStatement(
+ "SELECT guid, label, first_name, middle_name, last_name, "
+ "email, company_name, address_line_1, address_line_2, city, state, "
+ "zipcode, country, phone, fax, date_modified "
+ "FROM autofill_profiles"));
+ ASSERT_TRUE(s1.Step());
+
+ AutoFillProfile profile_a;
+ string16 profile_label_a;
+ int64 profile_date_modified_a = 0;
+ EXPECT_NO_FATAL_FAILURE(AutoFillProfile32FromStatement(
+ s1, &profile_a, &profile_label_a, &profile_date_modified_a));
+ EXPECT_EQ(profile, profile_a);
+ EXPECT_EQ(profile_label, profile_label_a);
+ EXPECT_EQ(profile_date_modified, profile_date_modified_a);
+
+ sql::Statement s2(
+ connection.GetUniqueStatement(
+ "SELECT guid, label, name_on_card, expiration_month, "
+ "expiration_year, card_number_encrypted, date_modified "
+ "FROM credit_cards"));
+ ASSERT_TRUE(s2.Step());
+
+ CreditCard credit_card_a;
+ string16 cc_label_a;
+ std::string cc_number_encrypted_a;
+ int64 cc_date_modified_a = 0;
+ EXPECT_NO_FATAL_FAILURE(CreditCard32FromStatement(s2,
+ &credit_card_a,
+ &cc_label_a,
+ &cc_number_encrypted_a,
+ &cc_date_modified_a));
+ EXPECT_EQ(credit_card, credit_card_a);
+ EXPECT_EQ(cc_label, cc_label_a);
+ EXPECT_EQ(cc_number_encrypted, cc_number_encrypted_a);
+ EXPECT_EQ(cc_date_modified, cc_date_modified_a);
+ }
+}