diff options
author | skrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-18 21:08:43 +0000 |
---|---|---|
committer | skrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-18 21:08:43 +0000 |
commit | 14579802089edf81277a95d5ac71e59aaf9d9943 (patch) | |
tree | 02d958cc7a1b38defed994b6e594bc573e9d58c2 /chrome/browser/webdata | |
parent | 7de487c60478205f8f4396d2b77dd4e0fd65f583 (diff) | |
download | chromium_src-14579802089edf81277a95d5ac71e59aaf9d9943.zip chromium_src-14579802089edf81277a95d5ac71e59aaf9d9943.tar.gz chromium_src-14579802089edf81277a95d5ac71e59aaf9d9943.tar.bz2 |
Bring the remove notifications up from the WebDatabase to the WebDataService.
Review URL: http://codereview.chromium.org/505046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34986 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/webdata')
-rw-r--r-- | chrome/browser/webdata/web_data_service.cc | 7 | ||||
-rw-r--r-- | chrome/browser/webdata/web_data_service_unittest.cc | 99 |
2 files changed, 75 insertions, 31 deletions
diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc index 5ca9c31..36d8834 100644 --- a/chrome/browser/webdata/web_data_service.cc +++ b/chrome/browser/webdata/web_data_service.cc @@ -672,8 +672,13 @@ void WebDataService::RemoveFormElementsAddedBetweenImpl( AutofillChangeList changes; if (db_->RemoveFormElementsAddedBetween(request->GetArgument1(), request->GetArgument2(), - &changes)) + &changes)) { + if (changes.size() > 0) { + request->SetResult( + new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes)); + } ScheduleCommit(); + } } request->RequestComplete(); } diff --git a/chrome/browser/webdata/web_data_service_unittest.cc b/chrome/browser/webdata/web_data_service_unittest.cc index 917abd2..1e26539 100644 --- a/chrome/browser/webdata/web_data_service_unittest.cc +++ b/chrome/browser/webdata/web_data_service_unittest.cc @@ -11,6 +11,7 @@ #include "base/scoped_ptr.h" #include "base/string16.h" #include "base/string_util.h" +#include "base/time.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/webdata/autofill_change.h" #include "chrome/browser/webdata/autofill_entry.h" @@ -25,6 +26,8 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webkit/glue/form_field.h" +using base::Time; +using base::TimeDelta; using testing::_; using testing::ElementsAreArray; using testing::Pointee; @@ -67,9 +70,16 @@ class AutofillWebDataServiceConsumer: public WebDataServiceConsumer { class WebDataServiceTest : public testing::Test { public: - WebDataServiceTest() : ui_thread_(ChromeThread::UI, &message_loop_) {} + WebDataServiceTest() + : ui_thread_(ChromeThread::UI, &message_loop_) {} + protected: virtual void SetUp() { + name1_ = ASCIIToUTF16("name1"); + name2_ = ASCIIToUTF16("name2"); + value1_ = ASCIIToUTF16("value1"); + value2_ = ASCIIToUTF16("value2"); + PathService::Get(chrome::DIR_TEST_DATA, &profile_dir_); const std::string test_profile = "WebDataServiceTest"; profile_dir_ = profile_dir_.AppendASCII(test_profile); @@ -88,8 +98,22 @@ class WebDataServiceTest : public testing::Test { MessageLoop::current()->Run(); } + void AppendFormField(const string16& name, + const string16& value, + std::vector<webkit_glue::FormField>* form_fields) { + form_fields->push_back( + webkit_glue::FormField(EmptyString16(), + name, + EmptyString16(), + value)); + } + MessageLoopForUI message_loop_; ChromeThread ui_thread_; + string16 name1_; + string16 name2_; + string16 value1_; + string16 value2_; FilePath profile_dir_; scoped_refptr<WebDataService> wds_; NotificationRegistrar registrar_; @@ -97,14 +121,9 @@ class WebDataServiceTest : public testing::Test { }; TEST_F(WebDataServiceTest, AutofillAdd) { - const string16 kName1 = ASCIIToUTF16("name1"); - const string16 kValue1 = ASCIIToUTF16("value1"); - const string16 kName2 = ASCIIToUTF16("name2"); - const string16 kValue2 = ASCIIToUTF16("value2"); - const AutofillChange expected_changes[] = { - AutofillChange(AutofillChange::ADD, AutofillKey(kName1, kValue1)), - AutofillChange(AutofillChange::ADD, AutofillKey(kName2, kValue2)) + AutofillChange(AutofillChange::ADD, AutofillKey(name1_, value1_)), + AutofillChange(AutofillChange::ADD, AutofillKey(name2_, value2_)) }; // This will verify that the correct notification is triggered, @@ -122,16 +141,8 @@ TEST_F(WebDataServiceTest, AutofillAdd) { NotificationService::AllSources()); std::vector<webkit_glue::FormField> form_fields; - form_fields.push_back( - webkit_glue::FormField(EmptyString16(), - kName1, - EmptyString16(), - kValue1)); - form_fields.push_back( - webkit_glue::FormField(EmptyString16(), - kName2, - EmptyString16(), - kValue2)); + AppendFormField(name1_, value1_, &form_fields); + AppendFormField(name2_, value2_, &form_fields); wds_->AddFormFieldValues(form_fields); // The message loop will exit when the mock observer is notified. @@ -141,31 +152,58 @@ TEST_F(WebDataServiceTest, AutofillAdd) { WebDataService::Handle handle; static const int limit = 10; handle = wds_->GetFormValuesForElementName( - kName1, EmptyString16(), limit, &consumer); + name1_, EmptyString16(), limit, &consumer); // The message loop will exit when the consumer is called. MessageLoop::current()->Run(); EXPECT_EQ(handle, consumer.handle()); ASSERT_EQ(1U, consumer.values().size()); - EXPECT_EQ(kValue1, consumer.values()[0]); + EXPECT_EQ(value1_, consumer.values()[0]); } TEST_F(WebDataServiceTest, AutofillRemoveOne) { - const string16 kName1 = ASCIIToUTF16("name1"); - const string16 kValue1 = ASCIIToUTF16("value1"); - // First add some values to autofill. EXPECT_CALL(observer_, Observe(_, _, _)).WillOnce(QuitUIMessageLoop()); registrar_.Add(&observer_, NotificationType::AUTOFILL_ENTRIES_CHANGED, NotificationService::AllSources()); std::vector<webkit_glue::FormField> form_fields; - form_fields.push_back( - webkit_glue::FormField(EmptyString16(), - kName1, - EmptyString16(), - kValue1)); + AppendFormField(name1_, value1_, &form_fields); + wds_->AddFormFieldValues(form_fields); + + // The message loop will exit when the mock observer is notified. + MessageLoop::current()->Run(); + + // This will verify that the correct notification is triggered, + // passing the correct list of autofill keys in the details. + const AutofillChange expected_changes[] = { + AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)) + }; + EXPECT_CALL( + observer_, + Observe(NotificationType(NotificationType::AUTOFILL_ENTRIES_CHANGED), + NotificationService::AllSources(), + Property(&Details<const AutofillChangeList>::ptr, + Pointee(ElementsAreArray(expected_changes))))). + WillOnce(QuitUIMessageLoop()); + wds_->RemoveFormValueForElementName(name1_, value1_); + + // The message loop will exit when the mock observer is notified. + MessageLoop::current()->Run(); +} + +TEST_F(WebDataServiceTest, AutofillRemoveMany) { + TimeDelta one_day(TimeDelta::FromDays(1)); + Time t = Time::Now(); + + EXPECT_CALL(observer_, Observe(_, _, _)).WillOnce(QuitUIMessageLoop()); + registrar_.Add(&observer_, + NotificationType::AUTOFILL_ENTRIES_CHANGED, + NotificationService::AllSources()); + std::vector<webkit_glue::FormField> form_fields; + AppendFormField(name1_, value1_, &form_fields); + AppendFormField(name2_, value2_, &form_fields); wds_->AddFormFieldValues(form_fields); // The message loop will exit when the mock observer is notified. @@ -174,7 +212,8 @@ TEST_F(WebDataServiceTest, AutofillRemoveOne) { // This will verify that the correct notification is triggered, // passing the correct list of autofill keys in the details. const AutofillChange expected_changes[] = { - AutofillChange(AutofillChange::REMOVE, AutofillKey(kName1, kValue1)) + AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)), + AutofillChange(AutofillChange::REMOVE, AutofillKey(name2_, value2_)) }; EXPECT_CALL( observer_, @@ -183,7 +222,7 @@ TEST_F(WebDataServiceTest, AutofillRemoveOne) { Property(&Details<const AutofillChangeList>::ptr, Pointee(ElementsAreArray(expected_changes))))). WillOnce(QuitUIMessageLoop()); - wds_->RemoveFormValueForElementName(kName1, kValue1); + wds_->RemoveFormElementsAddedBetween(t, t + one_day); // The message loop will exit when the mock observer is notified. MessageLoop::current()->Run(); |