| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/string16.h" | 15 #include "base/string16.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
| 18 #include "base/time.h" | 18 #include "base/time.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "chrome/browser/webdata/autofill_change.h" | 20 #include "chrome/browser/webdata/autofill_change.h" |
| 21 #include "chrome/browser/webdata/autofill_entry.h" | 21 #include "chrome/browser/webdata/autofill_entry.h" |
| 22 #include "chrome/browser/webdata/web_data_service.h" | 22 #include "chrome/browser/webdata/web_data_service.h" |
| 23 #include "chrome/browser/webdata/web_data_service_observer.h" |
| 23 #include "chrome/browser/webdata/web_data_service_test_util.h" | 24 #include "chrome/browser/webdata/web_data_service_test_util.h" |
| 24 #include "chrome/browser/webdata/web_database_service_impl.h" | 25 #include "chrome/browser/webdata/web_database_service_impl.h" |
| 25 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
| 26 #include "chrome/common/chrome_notification_types.h" | 27 #include "chrome/common/chrome_notification_types.h" |
| 27 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
| 28 #include "chrome/test/base/thread_observer_helper.h" | 29 #include "chrome/test/base/thread_observer_helper.h" |
| 29 #include "components/autofill/browser/autofill_profile.h" | 30 #include "components/autofill/browser/autofill_profile.h" |
| 30 #include "components/autofill/browser/credit_card.h" | 31 #include "components/autofill/browser/credit_card.h" |
| 31 #include "components/autofill/common/form_field_data.h" | 32 #include "components/autofill/common/form_field_data.h" |
| 32 #include "content/public/browser/notification_details.h" | 33 #include "content/public/browser/notification_details.h" |
| 33 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
| 34 #include "content/public/test/test_browser_thread.h" | 35 #include "content/public/test/test_browser_thread.h" |
| 35 #include "testing/gmock/include/gmock/gmock.h" | 36 #include "testing/gmock/include/gmock/gmock.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 37 | 38 |
| 38 using base::Time; | 39 using base::Time; |
| 39 using base::TimeDelta; | 40 using base::TimeDelta; |
| 40 using base::WaitableEvent; | 41 using base::WaitableEvent; |
| 41 using content::BrowserThread; | 42 using content::BrowserThread; |
| 42 using testing::_; | 43 using testing::_; |
| 43 using testing::DoDefault; | 44 using testing::DoDefault; |
| 44 using testing::ElementsAreArray; | 45 using testing::ElementsAreArray; |
| 45 using testing::Pointee; | 46 using testing::Pointee; |
| 46 using testing::Property; | 47 using testing::Property; |
| 47 | 48 |
| 48 typedef std::vector<AutofillChange> AutofillChangeList; | |
| 49 | |
| 50 static const int kWebDataServiceTimeoutSeconds = 8; | 49 static const int kWebDataServiceTimeoutSeconds = 8; |
| 51 | 50 |
| 52 ACTION_P(SignalEvent, event) { | 51 ACTION_P(SignalEvent, event) { |
| 53 event->Signal(); | 52 event->Signal(); |
| 54 } | 53 } |
| 55 | 54 |
| 56 class AutofillDBThreadObserverHelper : public DBThreadObserverHelper { | 55 class MockWebDataServiceObserver : public WebDataServiceObserver { |
| 57 protected: | 56 public: |
| 58 virtual ~AutofillDBThreadObserverHelper() {} | 57 MOCK_METHOD1(AutofillEntriesChanged, |
| 59 | 58 void(const AutofillChangeList& changes)); |
| 60 virtual void RegisterObservers() OVERRIDE { | 59 MOCK_METHOD1(AutofillProfileChanged, |
| 61 registrar_.Add(&observer_, | 60 void(const AutofillProfileChange& change)); |
| 62 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | |
| 63 content::NotificationService::AllSources()); | |
| 64 registrar_.Add(&observer_, | |
| 65 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | |
| 66 content::NotificationService::AllSources()); | |
| 67 } | |
| 68 }; | 61 }; |
| 69 | 62 |
| 70 class WebDataServiceTest : public testing::Test { | 63 class WebDataServiceTest : public testing::Test { |
| 71 public: | 64 public: |
| 72 WebDataServiceTest() | 65 WebDataServiceTest() |
| 73 : ui_thread_(BrowserThread::UI, &message_loop_), | 66 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 74 db_thread_(BrowserThread::DB) {} | 67 db_thread_(BrowserThread::DB) {} |
| 75 | 68 |
| 76 protected: | 69 protected: |
| 77 virtual void SetUp() { | 70 virtual void SetUp() { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 test_timeout_(TimeDelta::FromSeconds(kWebDataServiceTimeoutSeconds)), | 118 test_timeout_(TimeDelta::FromSeconds(kWebDataServiceTimeoutSeconds)), |
| 126 done_event_(false, false) {} | 119 done_event_(false, false) {} |
| 127 | 120 |
| 128 protected: | 121 protected: |
| 129 virtual void SetUp() { | 122 virtual void SetUp() { |
| 130 WebDataServiceTest::SetUp(); | 123 WebDataServiceTest::SetUp(); |
| 131 name1_ = ASCIIToUTF16("name1"); | 124 name1_ = ASCIIToUTF16("name1"); |
| 132 name2_ = ASCIIToUTF16("name2"); | 125 name2_ = ASCIIToUTF16("name2"); |
| 133 value1_ = ASCIIToUTF16("value1"); | 126 value1_ = ASCIIToUTF16("value1"); |
| 134 value2_ = ASCIIToUTF16("value2"); | 127 value2_ = ASCIIToUTF16("value2"); |
| 135 observer_helper_ = new AutofillDBThreadObserverHelper(); | 128 wds_->AddObserver(&observer_); |
| 136 observer_helper_->Init(); | |
| 137 } | 129 } |
| 138 | 130 |
| 139 virtual void TearDown() { | 131 virtual void TearDown() { |
| 140 // Release this first so it can get destructed on the db thread. | 132 wds_->RemoveObserver(&observer_); |
| 141 observer_helper_ = NULL; | |
| 142 WebDataServiceTest::TearDown(); | 133 WebDataServiceTest::TearDown(); |
| 143 } | 134 } |
| 144 | 135 |
| 145 void AppendFormField(const string16& name, | 136 void AppendFormField(const string16& name, |
| 146 const string16& value, | 137 const string16& value, |
| 147 std::vector<FormFieldData>* form_fields) { | 138 std::vector<FormFieldData>* form_fields) { |
| 148 FormFieldData field; | 139 FormFieldData field; |
| 149 field.name = name; | 140 field.name = name; |
| 150 field.value = value; | 141 field.value = value; |
| 151 form_fields->push_back(field); | 142 form_fields->push_back(field); |
| 152 } | 143 } |
| 153 | 144 |
| 154 string16 name1_; | 145 string16 name1_; |
| 155 string16 name2_; | 146 string16 name2_; |
| 156 string16 value1_; | 147 string16 value1_; |
| 157 string16 value2_; | 148 string16 value2_; |
| 158 int unique_id1_, unique_id2_; | 149 int unique_id1_, unique_id2_; |
| 159 const TimeDelta test_timeout_; | 150 const TimeDelta test_timeout_; |
| 160 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper_; | 151 testing::NiceMock<MockWebDataServiceObserver> observer_; |
| 161 WaitableEvent done_event_; | 152 WaitableEvent done_event_; |
| 162 }; | 153 }; |
| 163 | 154 |
| 164 // Simple consumer for Keywords data. Stores the result data and quits UI | 155 // Simple consumer for Keywords data. Stores the result data and quits UI |
| 165 // message loop when callback is invoked. | 156 // message loop when callback is invoked. |
| 166 class KeywordsConsumer : public WebDataServiceConsumer { | 157 class KeywordsConsumer : public WebDataServiceConsumer { |
| 167 public: | 158 public: |
| 168 KeywordsConsumer() : load_succeeded(false) {} | 159 KeywordsConsumer() : load_succeeded(false) {} |
| 169 | 160 |
| 170 virtual void OnWebDataServiceRequestDone( | 161 virtual void OnWebDataServiceRequestDone( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 189 }; | 180 }; |
| 190 | 181 |
| 191 TEST_F(WebDataServiceAutofillTest, FormFillAdd) { | 182 TEST_F(WebDataServiceAutofillTest, FormFillAdd) { |
| 192 const AutofillChange expected_changes[] = { | 183 const AutofillChange expected_changes[] = { |
| 193 AutofillChange(AutofillChange::ADD, AutofillKey(name1_, value1_)), | 184 AutofillChange(AutofillChange::ADD, AutofillKey(name1_, value1_)), |
| 194 AutofillChange(AutofillChange::ADD, AutofillKey(name2_, value2_)) | 185 AutofillChange(AutofillChange::ADD, AutofillKey(name2_, value2_)) |
| 195 }; | 186 }; |
| 196 | 187 |
| 197 // This will verify that the correct notification is triggered, | 188 // This will verify that the correct notification is triggered, |
| 198 // passing the correct list of autofill keys in the details. | 189 // passing the correct list of autofill keys in the details. |
| 199 EXPECT_CALL( | 190 EXPECT_CALL(observer_, |
| 200 *observer_helper_->observer(), | 191 AutofillEntriesChanged(ElementsAreArray(expected_changes))) |
| 201 Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED), | 192 .WillOnce(SignalEvent(&done_event_)); |
| 202 content::Source<WebDataService>(wds_.get()), | |
| 203 Property(&content::Details<const AutofillChangeList>::ptr, | |
| 204 Pointee(ElementsAreArray(expected_changes))))). | |
| 205 WillOnce(SignalEvent(&done_event_)); | |
| 206 | 193 |
| 207 std::vector<FormFieldData> form_fields; | 194 std::vector<FormFieldData> form_fields; |
| 208 AppendFormField(name1_, value1_, &form_fields); | 195 AppendFormField(name1_, value1_, &form_fields); |
| 209 AppendFormField(name2_, value2_, &form_fields); | 196 AppendFormField(name2_, value2_, &form_fields); |
| 210 wds_->AddFormFields(form_fields); | 197 wds_->AddFormFields(form_fields); |
| 211 | 198 |
| 212 // The event will be signaled when the mock observer is notified. | 199 // The event will be signaled when the mock observer is notified. |
| 213 done_event_.TimedWait(test_timeout_); | 200 done_event_.TimedWait(test_timeout_); |
| 214 | 201 |
| 215 AutofillWebDataServiceConsumer<std::vector<string16> > consumer; | 202 AutofillWebDataServiceConsumer<std::vector<string16> > consumer; |
| 216 WebDataService::Handle handle; | 203 WebDataService::Handle handle; |
| 217 static const int limit = 10; | 204 static const int limit = 10; |
| 218 handle = wds_->GetFormValuesForElementName( | 205 handle = wds_->GetFormValuesForElementName( |
| 219 name1_, string16(), limit, &consumer); | 206 name1_, string16(), limit, &consumer); |
| 220 | 207 |
| 221 // The message loop will exit when the consumer is called. | 208 // The message loop will exit when the consumer is called. |
| 222 MessageLoop::current()->Run(); | 209 MessageLoop::current()->Run(); |
| 223 | 210 |
| 224 EXPECT_EQ(handle, consumer.handle()); | 211 EXPECT_EQ(handle, consumer.handle()); |
| 225 ASSERT_EQ(1U, consumer.result().size()); | 212 ASSERT_EQ(1U, consumer.result().size()); |
| 226 EXPECT_EQ(value1_, consumer.result()[0]); | 213 EXPECT_EQ(value1_, consumer.result()[0]); |
| 227 } | 214 } |
| 228 | 215 |
| 229 TEST_F(WebDataServiceAutofillTest, FormFillRemoveOne) { | 216 TEST_F(WebDataServiceAutofillTest, FormFillRemoveOne) { |
| 230 // First add some values to autofill. | 217 // First add some values to autofill. |
| 231 EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). | 218 EXPECT_CALL(observer_, AutofillEntriesChanged(_)) |
| 232 WillOnce(SignalEvent(&done_event_)); | 219 .WillOnce(SignalEvent(&done_event_)); |
| 220 |
| 233 std::vector<FormFieldData> form_fields; | 221 std::vector<FormFieldData> form_fields; |
| 234 AppendFormField(name1_, value1_, &form_fields); | 222 AppendFormField(name1_, value1_, &form_fields); |
| 235 wds_->AddFormFields(form_fields); | 223 wds_->AddFormFields(form_fields); |
| 236 | 224 |
| 237 // The event will be signaled when the mock observer is notified. | 225 // The event will be signaled when the mock observer is notified. |
| 238 done_event_.TimedWait(test_timeout_); | 226 done_event_.TimedWait(test_timeout_); |
| 239 | 227 |
| 240 // This will verify that the correct notification is triggered, | 228 // This will verify that the correct notification is triggered, |
| 241 // passing the correct list of autofill keys in the details. | 229 // passing the correct list of autofill keys in the details. |
| 242 const AutofillChange expected_changes[] = { | 230 const AutofillChange expected_changes[] = { |
| 243 AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)) | 231 AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)) |
| 244 }; | 232 }; |
| 245 EXPECT_CALL( | 233 EXPECT_CALL(observer_, |
| 246 *observer_helper_->observer(), | 234 AutofillEntriesChanged(ElementsAreArray(expected_changes))) |
| 247 Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED), | 235 .WillOnce(SignalEvent(&done_event_)); |
| 248 content::Source<WebDataService>(wds_.get()), | 236 |
| 249 Property(&content::Details<const AutofillChangeList>::ptr, | |
| 250 Pointee(ElementsAreArray(expected_changes))))). | |
| 251 WillOnce(SignalEvent(&done_event_)); | |
| 252 wds_->RemoveFormValueForElementName(name1_, value1_); | 237 wds_->RemoveFormValueForElementName(name1_, value1_); |
| 253 | 238 |
| 254 // The event will be signaled when the mock observer is notified. | 239 // The event will be signaled when the mock observer is notified. |
| 255 done_event_.TimedWait(test_timeout_); | 240 done_event_.TimedWait(test_timeout_); |
| 256 } | 241 } |
| 257 | 242 |
| 258 TEST_F(WebDataServiceAutofillTest, FormFillRemoveMany) { | 243 TEST_F(WebDataServiceAutofillTest, FormFillRemoveMany) { |
| 259 TimeDelta one_day(TimeDelta::FromDays(1)); | 244 TimeDelta one_day(TimeDelta::FromDays(1)); |
| 260 Time t = Time::Now(); | 245 Time t = Time::Now(); |
| 261 | 246 |
| 262 EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). | 247 EXPECT_CALL(observer_, AutofillEntriesChanged(_)) |
| 263 WillOnce(SignalEvent(&done_event_)); | 248 .WillOnce(SignalEvent(&done_event_)); |
| 249 |
| 264 std::vector<FormFieldData> form_fields; | 250 std::vector<FormFieldData> form_fields; |
| 265 AppendFormField(name1_, value1_, &form_fields); | 251 AppendFormField(name1_, value1_, &form_fields); |
| 266 AppendFormField(name2_, value2_, &form_fields); | 252 AppendFormField(name2_, value2_, &form_fields); |
| 267 wds_->AddFormFields(form_fields); | 253 wds_->AddFormFields(form_fields); |
| 268 | 254 |
| 269 // The event will be signaled when the mock observer is notified. | 255 // The event will be signaled when the mock observer is notified. |
| 270 done_event_.TimedWait(test_timeout_); | 256 done_event_.TimedWait(test_timeout_); |
| 271 | 257 |
| 272 // This will verify that the correct notification is triggered, | 258 // This will verify that the correct notification is triggered, |
| 273 // passing the correct list of autofill keys in the details. | 259 // passing the correct list of autofill keys in the details. |
| 274 const AutofillChange expected_changes[] = { | 260 const AutofillChange expected_changes[] = { |
| 275 AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)), | 261 AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)), |
| 276 AutofillChange(AutofillChange::REMOVE, AutofillKey(name2_, value2_)) | 262 AutofillChange(AutofillChange::REMOVE, AutofillKey(name2_, value2_)) |
| 277 }; | 263 }; |
| 278 EXPECT_CALL( | 264 EXPECT_CALL(observer_, |
| 279 *observer_helper_->observer(), | 265 AutofillEntriesChanged(ElementsAreArray(expected_changes))) |
| 280 Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED), | 266 .WillOnce(SignalEvent(&done_event_)); |
| 281 content::Source<WebDataService>(wds_.get()), | |
| 282 Property(&content::Details<const AutofillChangeList>::ptr, | |
| 283 Pointee(ElementsAreArray(expected_changes))))). | |
| 284 WillOnce(SignalEvent(&done_event_)); | |
| 285 wds_->RemoveFormElementsAddedBetween(t, t + one_day); | 267 wds_->RemoveFormElementsAddedBetween(t, t + one_day); |
| 286 | 268 |
| 287 // The event will be signaled when the mock observer is notified. | 269 // The event will be signaled when the mock observer is notified. |
| 288 done_event_.TimedWait(test_timeout_); | 270 done_event_.TimedWait(test_timeout_); |
| 289 } | 271 } |
| 290 | 272 |
| 291 TEST_F(WebDataServiceAutofillTest, ProfileAdd) { | 273 TEST_F(WebDataServiceAutofillTest, ProfileAdd) { |
| 292 AutofillProfile profile; | 274 AutofillProfile profile; |
| 293 | 275 |
| 294 // Check that GUID-based notification was sent. | 276 // Check that GUID-based notification was sent. |
| 295 const AutofillProfileChange expected_change( | 277 const AutofillProfileChange expected_change( |
| 296 AutofillProfileChange::ADD, profile.guid(), &profile); | 278 AutofillProfileChange::ADD, profile.guid(), &profile); |
| 297 EXPECT_CALL( | 279 EXPECT_CALL(observer_, AutofillProfileChanged(expected_change)) |
| 298 *observer_helper_->observer(), | 280 .WillOnce(SignalEvent(&done_event_)); |
| 299 Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED), | |
| 300 content::Source<WebDataService>(wds_.get()), | |
| 301 Property(&content::Details<const AutofillProfileChange>::ptr, | |
| 302 Pointee(expected_change)))). | |
| 303 WillOnce(SignalEvent(&done_event_)); | |
| 304 | 281 |
| 305 wds_->AddAutofillProfile(profile); | 282 wds_->AddAutofillProfile(profile); |
| 306 done_event_.TimedWait(test_timeout_); | 283 done_event_.TimedWait(test_timeout_); |
| 307 | 284 |
| 308 // Check that it was added. | 285 // Check that it was added. |
| 309 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer; | 286 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer; |
| 310 WebDataService::Handle handle = wds_->GetAutofillProfiles(&consumer); | 287 WebDataService::Handle handle = wds_->GetAutofillProfiles(&consumer); |
| 311 MessageLoop::current()->Run(); | 288 MessageLoop::current()->Run(); |
| 312 EXPECT_EQ(handle, consumer.handle()); | 289 EXPECT_EQ(handle, consumer.handle()); |
| 313 ASSERT_EQ(1U, consumer.result().size()); | 290 ASSERT_EQ(1U, consumer.result().size()); |
| 314 EXPECT_EQ(profile, *consumer.result()[0]); | 291 EXPECT_EQ(profile, *consumer.result()[0]); |
| 315 STLDeleteElements(&consumer.result()); | 292 STLDeleteElements(&consumer.result()); |
| 316 } | 293 } |
| 317 | 294 |
| 318 TEST_F(WebDataServiceAutofillTest, ProfileRemove) { | 295 TEST_F(WebDataServiceAutofillTest, ProfileRemove) { |
| 319 AutofillProfile profile; | 296 AutofillProfile profile; |
| 320 | 297 |
| 321 // Add a profile. | 298 // Add a profile. |
| 322 EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). | 299 EXPECT_CALL(observer_, AutofillProfileChanged(_)) |
| 323 Times(1). | 300 .WillOnce(SignalEvent(&done_event_)); |
| 324 WillOnce(SignalEvent(&done_event_)); | |
| 325 wds_->AddAutofillProfile(profile); | 301 wds_->AddAutofillProfile(profile); |
| 326 done_event_.TimedWait(test_timeout_); | 302 done_event_.TimedWait(test_timeout_); |
| 327 | 303 |
| 328 // Check that it was added. | 304 // Check that it was added. |
| 329 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer; | 305 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer; |
| 330 WebDataService::Handle handle = wds_->GetAutofillProfiles(&consumer); | 306 WebDataService::Handle handle = wds_->GetAutofillProfiles(&consumer); |
| 331 MessageLoop::current()->Run(); | 307 MessageLoop::current()->Run(); |
| 332 EXPECT_EQ(handle, consumer.handle()); | 308 EXPECT_EQ(handle, consumer.handle()); |
| 333 ASSERT_EQ(1U, consumer.result().size()); | 309 ASSERT_EQ(1U, consumer.result().size()); |
| 334 EXPECT_EQ(profile, *consumer.result()[0]); | 310 EXPECT_EQ(profile, *consumer.result()[0]); |
| 335 STLDeleteElements(&consumer.result()); | 311 STLDeleteElements(&consumer.result()); |
| 336 | 312 |
| 337 // Check that GUID-based notification was sent. | 313 // Check that GUID-based notification was sent. |
| 338 const AutofillProfileChange expected_change( | 314 const AutofillProfileChange expected_change( |
| 339 AutofillProfileChange::REMOVE, profile.guid(), NULL); | 315 AutofillProfileChange::REMOVE, profile.guid(), NULL); |
| 340 EXPECT_CALL( | 316 EXPECT_CALL(observer_, AutofillProfileChanged(expected_change)) |
| 341 *observer_helper_->observer(), | 317 .WillOnce(SignalEvent(&done_event_)); |
| 342 Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED), | |
| 343 content::Source<WebDataService>(wds_.get()), | |
| 344 Property(&content::Details<const AutofillProfileChange>::ptr, | |
| 345 Pointee(expected_change)))). | |
| 346 WillOnce(SignalEvent(&done_event_)); | |
| 347 | 318 |
| 348 // Remove the profile. | 319 // Remove the profile. |
| 349 wds_->RemoveAutofillProfile(profile.guid()); | 320 wds_->RemoveAutofillProfile(profile.guid()); |
| 350 done_event_.TimedWait(test_timeout_); | 321 done_event_.TimedWait(test_timeout_); |
| 351 | 322 |
| 352 // Check that it was removed. | 323 // Check that it was removed. |
| 353 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer2; | 324 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer2; |
| 354 WebDataService::Handle handle2 = wds_->GetAutofillProfiles(&consumer2); | 325 WebDataService::Handle handle2 = wds_->GetAutofillProfiles(&consumer2); |
| 355 MessageLoop::current()->Run(); | 326 MessageLoop::current()->Run(); |
| 356 EXPECT_EQ(handle2, consumer2.handle()); | 327 EXPECT_EQ(handle2, consumer2.handle()); |
| 357 ASSERT_EQ(0U, consumer2.result().size()); | 328 ASSERT_EQ(0U, consumer2.result().size()); |
| 358 } | 329 } |
| 359 | 330 |
| 360 TEST_F(WebDataServiceAutofillTest, ProfileUpdate) { | 331 TEST_F(WebDataServiceAutofillTest, ProfileUpdate) { |
| 361 AutofillProfile profile1; | 332 AutofillProfile profile1; |
| 362 profile1.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Abe")); | 333 profile1.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Abe")); |
| 363 AutofillProfile profile2; | 334 AutofillProfile profile2; |
| 364 profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Alice")); | 335 profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Alice")); |
| 365 | 336 |
| 366 EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). | 337 EXPECT_CALL(observer_, AutofillProfileChanged(_)) |
| 367 WillOnce(DoDefault()). | 338 .WillOnce(DoDefault()) |
| 368 WillOnce(SignalEvent(&done_event_)); | 339 .WillOnce(SignalEvent(&done_event_)); |
| 340 |
| 369 wds_->AddAutofillProfile(profile1); | 341 wds_->AddAutofillProfile(profile1); |
| 370 wds_->AddAutofillProfile(profile2); | 342 wds_->AddAutofillProfile(profile2); |
| 371 done_event_.TimedWait(test_timeout_); | 343 done_event_.TimedWait(test_timeout_); |
| 372 | 344 |
| 373 // Check that they were added. | 345 // Check that they were added. |
| 374 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer; | 346 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer; |
| 375 WebDataService::Handle handle = wds_->GetAutofillProfiles(&consumer); | 347 WebDataService::Handle handle = wds_->GetAutofillProfiles(&consumer); |
| 376 MessageLoop::current()->Run(); | 348 MessageLoop::current()->Run(); |
| 377 EXPECT_EQ(handle, consumer.handle()); | 349 EXPECT_EQ(handle, consumer.handle()); |
| 378 ASSERT_EQ(2U, consumer.result().size()); | 350 ASSERT_EQ(2U, consumer.result().size()); |
| 379 EXPECT_EQ(profile1, *consumer.result()[0]); | 351 EXPECT_EQ(profile1, *consumer.result()[0]); |
| 380 EXPECT_EQ(profile2, *consumer.result()[1]); | 352 EXPECT_EQ(profile2, *consumer.result()[1]); |
| 381 STLDeleteElements(&consumer.result()); | 353 STLDeleteElements(&consumer.result()); |
| 382 | 354 |
| 383 AutofillProfile profile1_changed(profile1); | 355 AutofillProfile profile1_changed(profile1); |
| 384 profile1_changed.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Bill")); | 356 profile1_changed.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Bill")); |
| 385 const AutofillProfileChange expected_change( | 357 const AutofillProfileChange expected_change( |
| 386 AutofillProfileChange::UPDATE, profile1.guid(), &profile1_changed); | 358 AutofillProfileChange::UPDATE, profile1.guid(), &profile1_changed); |
| 387 | 359 |
| 388 EXPECT_CALL( | 360 EXPECT_CALL(observer_, AutofillProfileChanged(expected_change)) |
| 389 *observer_helper_->observer(), | 361 .WillOnce(SignalEvent(&done_event_)); |
| 390 Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED), | |
| 391 content::Source<WebDataService>(wds_.get()), | |
| 392 Property(&content::Details<const AutofillProfileChange>::ptr, | |
| 393 Pointee(expected_change)))). | |
| 394 WillOnce(SignalEvent(&done_event_)); | |
| 395 | 362 |
| 396 // Update the profile. | 363 // Update the profile. |
| 397 wds_->UpdateAutofillProfile(profile1_changed); | 364 wds_->UpdateAutofillProfile(profile1_changed); |
| 398 done_event_.TimedWait(test_timeout_); | 365 done_event_.TimedWait(test_timeout_); |
| 399 | 366 |
| 400 // Check that the updates were made. | 367 // Check that the updates were made. |
| 401 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer2; | 368 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer2; |
| 402 WebDataService::Handle handle2 = wds_->GetAutofillProfiles(&consumer2); | 369 WebDataService::Handle handle2 = wds_->GetAutofillProfiles(&consumer2); |
| 403 MessageLoop::current()->Run(); | 370 MessageLoop::current()->Run(); |
| 404 EXPECT_EQ(handle2, consumer2.handle()); | 371 EXPECT_EQ(handle2, consumer2.handle()); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 EXPECT_EQ(handle2, consumer2.handle()); | 452 EXPECT_EQ(handle2, consumer2.handle()); |
| 486 ASSERT_EQ(2U, consumer2.result().size()); | 453 ASSERT_EQ(2U, consumer2.result().size()); |
| 487 EXPECT_NE(card1, *consumer2.result()[0]); | 454 EXPECT_NE(card1, *consumer2.result()[0]); |
| 488 EXPECT_EQ(card1_changed, *consumer2.result()[0]); | 455 EXPECT_EQ(card1_changed, *consumer2.result()[0]); |
| 489 EXPECT_EQ(card2, *consumer2.result()[1]); | 456 EXPECT_EQ(card2, *consumer2.result()[1]); |
| 490 STLDeleteElements(&consumer2.result()); | 457 STLDeleteElements(&consumer2.result()); |
| 491 } | 458 } |
| 492 | 459 |
| 493 TEST_F(WebDataServiceAutofillTest, AutofillRemoveModifiedBetween) { | 460 TEST_F(WebDataServiceAutofillTest, AutofillRemoveModifiedBetween) { |
| 494 // Add a profile. | 461 // Add a profile. |
| 495 EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). | 462 EXPECT_CALL(observer_, AutofillProfileChanged(_)) |
| 496 Times(1). | 463 .WillOnce(SignalEvent(&done_event_)); |
| 497 WillOnce(SignalEvent(&done_event_)); | |
| 498 AutofillProfile profile; | 464 AutofillProfile profile; |
| 499 wds_->AddAutofillProfile(profile); | 465 wds_->AddAutofillProfile(profile); |
| 500 done_event_.TimedWait(test_timeout_); | 466 done_event_.TimedWait(test_timeout_); |
| 501 | 467 |
| 502 // Check that it was added. | 468 // Check that it was added. |
| 503 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > | 469 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > |
| 504 profile_consumer; | 470 profile_consumer; |
| 505 WebDataService::Handle handle = wds_->GetAutofillProfiles(&profile_consumer); | 471 WebDataService::Handle handle = wds_->GetAutofillProfiles(&profile_consumer); |
| 506 MessageLoop::current()->Run(); | 472 MessageLoop::current()->Run(); |
| 507 EXPECT_EQ(handle, profile_consumer.handle()); | 473 EXPECT_EQ(handle, profile_consumer.handle()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 519 handle = wds_->GetCreditCards(&card_consumer); | 485 handle = wds_->GetCreditCards(&card_consumer); |
| 520 MessageLoop::current()->Run(); | 486 MessageLoop::current()->Run(); |
| 521 EXPECT_EQ(handle, card_consumer.handle()); | 487 EXPECT_EQ(handle, card_consumer.handle()); |
| 522 ASSERT_EQ(1U, card_consumer.result().size()); | 488 ASSERT_EQ(1U, card_consumer.result().size()); |
| 523 EXPECT_EQ(credit_card, *card_consumer.result()[0]); | 489 EXPECT_EQ(credit_card, *card_consumer.result()[0]); |
| 524 STLDeleteElements(&card_consumer.result()); | 490 STLDeleteElements(&card_consumer.result()); |
| 525 | 491 |
| 526 // Check that GUID-based notification was sent for the profile. | 492 // Check that GUID-based notification was sent for the profile. |
| 527 const AutofillProfileChange expected_profile_change( | 493 const AutofillProfileChange expected_profile_change( |
| 528 AutofillProfileChange::REMOVE, profile.guid(), NULL); | 494 AutofillProfileChange::REMOVE, profile.guid(), NULL); |
| 529 EXPECT_CALL( | 495 EXPECT_CALL(observer_, AutofillProfileChanged(expected_profile_change)) |
| 530 *observer_helper_->observer(), | 496 .WillOnce(SignalEvent(&done_event_)); |
| 531 Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED), | |
| 532 content::Source<WebDataService>(wds_.get()), | |
| 533 Property(&content::Details<const AutofillProfileChange>::ptr, | |
| 534 Pointee(expected_profile_change)))). | |
| 535 WillOnce(SignalEvent(&done_event_)); | |
| 536 | 497 |
| 537 // Remove the profile using time range of "all time". | 498 // Remove the profile using time range of "all time". |
| 538 wds_->RemoveAutofillProfilesAndCreditCardsModifiedBetween(Time(), Time()); | 499 wds_->RemoveAutofillProfilesAndCreditCardsModifiedBetween(Time(), Time()); |
| 539 done_event_.TimedWait(test_timeout_); | 500 done_event_.TimedWait(test_timeout_); |
| 540 WaitForDatabaseThread(); | 501 WaitForDatabaseThread(); |
| 541 | 502 |
| 542 // Check that the profile was removed. | 503 // Check that the profile was removed. |
| 543 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > | 504 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > |
| 544 profile_consumer2; | 505 profile_consumer2; |
| 545 WebDataService::Handle handle2 = | 506 WebDataService::Handle handle2 = |
| 546 wds_->GetAutofillProfiles(&profile_consumer2); | 507 wds_->GetAutofillProfiles(&profile_consumer2); |
| 547 MessageLoop::current()->Run(); | 508 MessageLoop::current()->Run(); |
| 548 EXPECT_EQ(handle2, profile_consumer2.handle()); | 509 EXPECT_EQ(handle2, profile_consumer2.handle()); |
| 549 ASSERT_EQ(0U, profile_consumer2.result().size()); | 510 ASSERT_EQ(0U, profile_consumer2.result().size()); |
| 550 | 511 |
| 551 // Check that the credit card was removed. | 512 // Check that the credit card was removed. |
| 552 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2; | 513 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2; |
| 553 handle2 = wds_->GetCreditCards(&card_consumer2); | 514 handle2 = wds_->GetCreditCards(&card_consumer2); |
| 554 MessageLoop::current()->Run(); | 515 MessageLoop::current()->Run(); |
| 555 EXPECT_EQ(handle2, card_consumer2.handle()); | 516 EXPECT_EQ(handle2, card_consumer2.handle()); |
| 556 ASSERT_EQ(0U, card_consumer2.result().size()); | 517 ASSERT_EQ(0U, card_consumer2.result().size()); |
| 557 } | 518 } |
| OLD | NEW |