| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_util.h" | 9 #include "base/file_util.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/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/stl_util-inl.h" | 15 #include "base/stl_util-inl.h" |
| 16 #include "base/string16.h" | 16 #include "base/string16.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
| 19 #include "base/time.h" | 19 #include "base/time.h" |
| 20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 21 #include "chrome/browser/autofill/autofill_profile.h" | 21 #include "chrome/browser/autofill/autofill_profile.h" |
| 22 #include "chrome/browser/autofill/credit_card.h" | 22 #include "chrome/browser/autofill/credit_card.h" |
| 23 #include "chrome/browser/webdata/autofill_change.h" | 23 #include "chrome/browser/webdata/autofill_change.h" |
| 24 #include "chrome/browser/webdata/autofill_entry.h" | 24 #include "chrome/browser/webdata/autofill_entry.h" |
| 25 #include "chrome/browser/webdata/web_data_service.h" | 25 #include "chrome/browser/webdata/web_data_service.h" |
| 26 #include "chrome/browser/webdata/web_data_service_test_util.h" | 26 #include "chrome/browser/webdata/web_data_service_test_util.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/common/guid.h" | 29 #include "chrome/common/guid.h" |
| 29 #include "chrome/test/thread_observer_helper.h" | 30 #include "chrome/test/thread_observer_helper.h" |
| 30 #include "content/browser/browser_thread.h" | 31 #include "content/browser/browser_thread.h" |
| 31 #include "content/common/notification_details.h" | 32 #include "content/common/notification_details.h" |
| 32 #include "content/common/notification_service.h" | 33 #include "content/common/notification_service.h" |
| 33 #include "content/common/notification_type.h" | |
| 34 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 36 #include "webkit/glue/form_field.h" | 36 #include "webkit/glue/form_field.h" |
| 37 | 37 |
| 38 using base::Time; | 38 using base::Time; |
| 39 using base::TimeDelta; | 39 using base::TimeDelta; |
| 40 using base::WaitableEvent; | 40 using base::WaitableEvent; |
| 41 using testing::_; | 41 using testing::_; |
| 42 using testing::DoDefault; | 42 using testing::DoDefault; |
| 43 using testing::ElementsAreArray; | 43 using testing::ElementsAreArray; |
| 44 using testing::Pointee; | 44 using testing::Pointee; |
| 45 using testing::Property; | 45 using testing::Property; |
| 46 | 46 |
| 47 typedef std::vector<AutofillChange> AutofillChangeList; | 47 typedef std::vector<AutofillChange> AutofillChangeList; |
| 48 | 48 |
| 49 static const int kWebDataServiceTimeoutSeconds = 8; | 49 static const int kWebDataServiceTimeoutSeconds = 8; |
| 50 | 50 |
| 51 ACTION_P(SignalEvent, event) { | 51 ACTION_P(SignalEvent, event) { |
| 52 event->Signal(); | 52 event->Signal(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 class AutofillDBThreadObserverHelper : public DBThreadObserverHelper { | 55 class AutofillDBThreadObserverHelper : public DBThreadObserverHelper { |
| 56 protected: | 56 protected: |
| 57 virtual void RegisterObservers() { | 57 virtual void RegisterObservers() { |
| 58 registrar_.Add(&observer_, | 58 registrar_.Add(&observer_, |
| 59 NotificationType::AUTOFILL_ENTRIES_CHANGED, | 59 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 60 NotificationService::AllSources()); | 60 NotificationService::AllSources()); |
| 61 registrar_.Add(&observer_, | 61 registrar_.Add(&observer_, |
| 62 NotificationType::AUTOFILL_PROFILE_CHANGED, | 62 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 63 NotificationService::AllSources()); | 63 NotificationService::AllSources()); |
| 64 registrar_.Add(&observer_, | 64 registrar_.Add(&observer_, |
| 65 NotificationType::AUTOFILL_CREDIT_CARD_CHANGED, | 65 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| 66 NotificationService::AllSources()); | 66 NotificationService::AllSources()); |
| 67 } | 67 } |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 class WebDataServiceTest : public testing::Test { | 70 class WebDataServiceTest : public testing::Test { |
| 71 public: | 71 public: |
| 72 WebDataServiceTest() | 72 WebDataServiceTest() |
| 73 : ui_thread_(BrowserThread::UI, &message_loop_), | 73 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 74 db_thread_(BrowserThread::DB) {} | 74 db_thread_(BrowserThread::DB) {} |
| 75 | 75 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 TEST_F(WebDataServiceAutofillTest, FormFillAdd) { | 154 TEST_F(WebDataServiceAutofillTest, FormFillAdd) { |
| 155 const AutofillChange expected_changes[] = { | 155 const AutofillChange expected_changes[] = { |
| 156 AutofillChange(AutofillChange::ADD, AutofillKey(name1_, value1_)), | 156 AutofillChange(AutofillChange::ADD, AutofillKey(name1_, value1_)), |
| 157 AutofillChange(AutofillChange::ADD, AutofillKey(name2_, value2_)) | 157 AutofillChange(AutofillChange::ADD, AutofillKey(name2_, value2_)) |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 // This will verify that the correct notification is triggered, | 160 // This will verify that the correct notification is triggered, |
| 161 // passing the correct list of autofill keys in the details. | 161 // passing the correct list of autofill keys in the details. |
| 162 EXPECT_CALL( | 162 EXPECT_CALL( |
| 163 *observer_helper_->observer(), | 163 *observer_helper_->observer(), |
| 164 Observe(NotificationType(NotificationType::AUTOFILL_ENTRIES_CHANGED), | 164 Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED), |
| 165 Source<WebDataService>(wds_.get()), | 165 Source<WebDataService>(wds_.get()), |
| 166 Property(&Details<const AutofillChangeList>::ptr, | 166 Property(&Details<const AutofillChangeList>::ptr, |
| 167 Pointee(ElementsAreArray(expected_changes))))). | 167 Pointee(ElementsAreArray(expected_changes))))). |
| 168 WillOnce(SignalEvent(&done_event_)); | 168 WillOnce(SignalEvent(&done_event_)); |
| 169 | 169 |
| 170 std::vector<webkit_glue::FormField> form_fields; | 170 std::vector<webkit_glue::FormField> form_fields; |
| 171 AppendFormField(name1_, value1_, &form_fields); | 171 AppendFormField(name1_, value1_, &form_fields); |
| 172 AppendFormField(name2_, value2_, &form_fields); | 172 AppendFormField(name2_, value2_, &form_fields); |
| 173 wds_->AddFormFields(form_fields); | 173 wds_->AddFormFields(form_fields); |
| 174 | 174 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 200 // The event will be signaled when the mock observer is notified. | 200 // The event will be signaled when the mock observer is notified. |
| 201 done_event_.TimedWait(test_timeout_); | 201 done_event_.TimedWait(test_timeout_); |
| 202 | 202 |
| 203 // This will verify that the correct notification is triggered, | 203 // This will verify that the correct notification is triggered, |
| 204 // passing the correct list of autofill keys in the details. | 204 // passing the correct list of autofill keys in the details. |
| 205 const AutofillChange expected_changes[] = { | 205 const AutofillChange expected_changes[] = { |
| 206 AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)) | 206 AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)) |
| 207 }; | 207 }; |
| 208 EXPECT_CALL( | 208 EXPECT_CALL( |
| 209 *observer_helper_->observer(), | 209 *observer_helper_->observer(), |
| 210 Observe(NotificationType(NotificationType::AUTOFILL_ENTRIES_CHANGED), | 210 Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED), |
| 211 Source<WebDataService>(wds_.get()), | 211 Source<WebDataService>(wds_.get()), |
| 212 Property(&Details<const AutofillChangeList>::ptr, | 212 Property(&Details<const AutofillChangeList>::ptr, |
| 213 Pointee(ElementsAreArray(expected_changes))))). | 213 Pointee(ElementsAreArray(expected_changes))))). |
| 214 WillOnce(SignalEvent(&done_event_)); | 214 WillOnce(SignalEvent(&done_event_)); |
| 215 wds_->RemoveFormValueForElementName(name1_, value1_); | 215 wds_->RemoveFormValueForElementName(name1_, value1_); |
| 216 | 216 |
| 217 // The event will be signaled when the mock observer is notified. | 217 // The event will be signaled when the mock observer is notified. |
| 218 done_event_.TimedWait(test_timeout_); | 218 done_event_.TimedWait(test_timeout_); |
| 219 } | 219 } |
| 220 | 220 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 233 done_event_.TimedWait(test_timeout_); | 233 done_event_.TimedWait(test_timeout_); |
| 234 | 234 |
| 235 // This will verify that the correct notification is triggered, | 235 // This will verify that the correct notification is triggered, |
| 236 // passing the correct list of autofill keys in the details. | 236 // passing the correct list of autofill keys in the details. |
| 237 const AutofillChange expected_changes[] = { | 237 const AutofillChange expected_changes[] = { |
| 238 AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)), | 238 AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)), |
| 239 AutofillChange(AutofillChange::REMOVE, AutofillKey(name2_, value2_)) | 239 AutofillChange(AutofillChange::REMOVE, AutofillKey(name2_, value2_)) |
| 240 }; | 240 }; |
| 241 EXPECT_CALL( | 241 EXPECT_CALL( |
| 242 *observer_helper_->observer(), | 242 *observer_helper_->observer(), |
| 243 Observe(NotificationType(NotificationType::AUTOFILL_ENTRIES_CHANGED), | 243 Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED), |
| 244 Source<WebDataService>(wds_.get()), | 244 Source<WebDataService>(wds_.get()), |
| 245 Property(&Details<const AutofillChangeList>::ptr, | 245 Property(&Details<const AutofillChangeList>::ptr, |
| 246 Pointee(ElementsAreArray(expected_changes))))). | 246 Pointee(ElementsAreArray(expected_changes))))). |
| 247 WillOnce(SignalEvent(&done_event_)); | 247 WillOnce(SignalEvent(&done_event_)); |
| 248 wds_->RemoveFormElementsAddedBetween(t, t + one_day); | 248 wds_->RemoveFormElementsAddedBetween(t, t + one_day); |
| 249 | 249 |
| 250 // The event will be signaled when the mock observer is notified. | 250 // The event will be signaled when the mock observer is notified. |
| 251 done_event_.TimedWait(test_timeout_); | 251 done_event_.TimedWait(test_timeout_); |
| 252 } | 252 } |
| 253 | 253 |
| 254 TEST_F(WebDataServiceAutofillTest, ProfileAdd) { | 254 TEST_F(WebDataServiceAutofillTest, ProfileAdd) { |
| 255 AutofillProfile profile; | 255 AutofillProfile profile; |
| 256 | 256 |
| 257 // Check that GUID-based notification was sent. | 257 // Check that GUID-based notification was sent. |
| 258 const AutofillProfileChange expected_change( | 258 const AutofillProfileChange expected_change( |
| 259 AutofillProfileChange::ADD, profile.guid(), &profile); | 259 AutofillProfileChange::ADD, profile.guid(), &profile); |
| 260 EXPECT_CALL( | 260 EXPECT_CALL( |
| 261 *observer_helper_->observer(), | 261 *observer_helper_->observer(), |
| 262 Observe(NotificationType(NotificationType::AUTOFILL_PROFILE_CHANGED), | 262 Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED), |
| 263 Source<WebDataService>(wds_.get()), | 263 Source<WebDataService>(wds_.get()), |
| 264 Property(&Details<const AutofillProfileChange>::ptr, | 264 Property(&Details<const AutofillProfileChange>::ptr, |
| 265 Pointee(expected_change)))). | 265 Pointee(expected_change)))). |
| 266 WillOnce(SignalEvent(&done_event_)); | 266 WillOnce(SignalEvent(&done_event_)); |
| 267 | 267 |
| 268 wds_->AddAutofillProfile(profile); | 268 wds_->AddAutofillProfile(profile); |
| 269 done_event_.TimedWait(test_timeout_); | 269 done_event_.TimedWait(test_timeout_); |
| 270 | 270 |
| 271 // Check that it was added. | 271 // Check that it was added. |
| 272 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer; | 272 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 295 EXPECT_EQ(handle, consumer.handle()); | 295 EXPECT_EQ(handle, consumer.handle()); |
| 296 ASSERT_EQ(1U, consumer.result().size()); | 296 ASSERT_EQ(1U, consumer.result().size()); |
| 297 EXPECT_EQ(profile, *consumer.result()[0]); | 297 EXPECT_EQ(profile, *consumer.result()[0]); |
| 298 STLDeleteElements(&consumer.result()); | 298 STLDeleteElements(&consumer.result()); |
| 299 | 299 |
| 300 // Check that GUID-based notification was sent. | 300 // Check that GUID-based notification was sent. |
| 301 const AutofillProfileChange expected_change( | 301 const AutofillProfileChange expected_change( |
| 302 AutofillProfileChange::REMOVE, profile.guid(), NULL); | 302 AutofillProfileChange::REMOVE, profile.guid(), NULL); |
| 303 EXPECT_CALL( | 303 EXPECT_CALL( |
| 304 *observer_helper_->observer(), | 304 *observer_helper_->observer(), |
| 305 Observe(NotificationType(NotificationType::AUTOFILL_PROFILE_CHANGED), | 305 Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED), |
| 306 Source<WebDataService>(wds_.get()), | 306 Source<WebDataService>(wds_.get()), |
| 307 Property(&Details<const AutofillProfileChange>::ptr, | 307 Property(&Details<const AutofillProfileChange>::ptr, |
| 308 Pointee(expected_change)))). | 308 Pointee(expected_change)))). |
| 309 WillOnce(SignalEvent(&done_event_)); | 309 WillOnce(SignalEvent(&done_event_)); |
| 310 | 310 |
| 311 // Remove the profile. | 311 // Remove the profile. |
| 312 wds_->RemoveAutofillProfile(profile.guid()); | 312 wds_->RemoveAutofillProfile(profile.guid()); |
| 313 done_event_.TimedWait(test_timeout_); | 313 done_event_.TimedWait(test_timeout_); |
| 314 | 314 |
| 315 // Check that it was removed. | 315 // Check that it was removed. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 343 EXPECT_EQ(profile2, *consumer.result()[1]); | 343 EXPECT_EQ(profile2, *consumer.result()[1]); |
| 344 STLDeleteElements(&consumer.result()); | 344 STLDeleteElements(&consumer.result()); |
| 345 | 345 |
| 346 AutofillProfile profile1_changed(profile1); | 346 AutofillProfile profile1_changed(profile1); |
| 347 profile1_changed.SetInfo(NAME_FIRST, ASCIIToUTF16("Bill")); | 347 profile1_changed.SetInfo(NAME_FIRST, ASCIIToUTF16("Bill")); |
| 348 const AutofillProfileChange expected_change( | 348 const AutofillProfileChange expected_change( |
| 349 AutofillProfileChange::UPDATE, profile1.guid(), &profile1_changed); | 349 AutofillProfileChange::UPDATE, profile1.guid(), &profile1_changed); |
| 350 | 350 |
| 351 EXPECT_CALL( | 351 EXPECT_CALL( |
| 352 *observer_helper_->observer(), | 352 *observer_helper_->observer(), |
| 353 Observe(NotificationType(NotificationType::AUTOFILL_PROFILE_CHANGED), | 353 Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED), |
| 354 Source<WebDataService>(wds_.get()), | 354 Source<WebDataService>(wds_.get()), |
| 355 Property(&Details<const AutofillProfileChange>::ptr, | 355 Property(&Details<const AutofillProfileChange>::ptr, |
| 356 Pointee(expected_change)))). | 356 Pointee(expected_change)))). |
| 357 WillOnce(SignalEvent(&done_event_)); | 357 WillOnce(SignalEvent(&done_event_)); |
| 358 | 358 |
| 359 // Update the profile. | 359 // Update the profile. |
| 360 wds_->UpdateAutofillProfile(profile1_changed); | 360 wds_->UpdateAutofillProfile(profile1_changed); |
| 361 done_event_.TimedWait(test_timeout_); | 361 done_event_.TimedWait(test_timeout_); |
| 362 | 362 |
| 363 // Check that the updates were made. | 363 // Check that the updates were made. |
| 364 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer2; | 364 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > consumer2; |
| 365 WebDataService::Handle handle2 = wds_->GetAutofillProfiles(&consumer2); | 365 WebDataService::Handle handle2 = wds_->GetAutofillProfiles(&consumer2); |
| 366 MessageLoop::current()->Run(); | 366 MessageLoop::current()->Run(); |
| 367 EXPECT_EQ(handle2, consumer2.handle()); | 367 EXPECT_EQ(handle2, consumer2.handle()); |
| 368 ASSERT_EQ(2U, consumer2.result().size()); | 368 ASSERT_EQ(2U, consumer2.result().size()); |
| 369 EXPECT_NE(profile1, *consumer2.result()[0]); | 369 EXPECT_NE(profile1, *consumer2.result()[0]); |
| 370 EXPECT_EQ(profile1_changed, *consumer2.result()[0]); | 370 EXPECT_EQ(profile1_changed, *consumer2.result()[0]); |
| 371 EXPECT_EQ(profile2, *consumer2.result()[1]); | 371 EXPECT_EQ(profile2, *consumer2.result()[1]); |
| 372 STLDeleteElements(&consumer2.result()); | 372 STLDeleteElements(&consumer2.result()); |
| 373 } | 373 } |
| 374 | 374 |
| 375 TEST_F(WebDataServiceAutofillTest, CreditAdd) { | 375 TEST_F(WebDataServiceAutofillTest, CreditAdd) { |
| 376 CreditCard card; | 376 CreditCard card; |
| 377 const AutofillCreditCardChange expected_change( | 377 const AutofillCreditCardChange expected_change( |
| 378 AutofillCreditCardChange::ADD, card.guid(), &card); | 378 AutofillCreditCardChange::ADD, card.guid(), &card); |
| 379 | 379 |
| 380 EXPECT_CALL( | 380 EXPECT_CALL( |
| 381 *observer_helper_->observer(), | 381 *observer_helper_->observer(), |
| 382 Observe( | 382 Observe( |
| 383 NotificationType(NotificationType::AUTOFILL_CREDIT_CARD_CHANGED), | 383 int(chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED), |
| 384 Source<WebDataService>(wds_.get()), | 384 Source<WebDataService>(wds_.get()), |
| 385 Property(&Details<const AutofillCreditCardChange>::ptr, | 385 Property(&Details<const AutofillCreditCardChange>::ptr, |
| 386 Pointee(expected_change)))). | 386 Pointee(expected_change)))). |
| 387 WillOnce(SignalEvent(&done_event_)); | 387 WillOnce(SignalEvent(&done_event_)); |
| 388 | 388 |
| 389 wds_->AddCreditCard(card); | 389 wds_->AddCreditCard(card); |
| 390 done_event_.TimedWait(test_timeout_); | 390 done_event_.TimedWait(test_timeout_); |
| 391 | 391 |
| 392 // Check that it was added. | 392 // Check that it was added. |
| 393 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer; | 393 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 416 ASSERT_EQ(1U, consumer.result().size()); | 416 ASSERT_EQ(1U, consumer.result().size()); |
| 417 EXPECT_EQ(credit_card, *consumer.result()[0]); | 417 EXPECT_EQ(credit_card, *consumer.result()[0]); |
| 418 STLDeleteElements(&consumer.result()); | 418 STLDeleteElements(&consumer.result()); |
| 419 | 419 |
| 420 // Remove the credit card. | 420 // Remove the credit card. |
| 421 const AutofillCreditCardChange expected_change( | 421 const AutofillCreditCardChange expected_change( |
| 422 AutofillCreditCardChange::REMOVE, credit_card.guid(), NULL); | 422 AutofillCreditCardChange::REMOVE, credit_card.guid(), NULL); |
| 423 EXPECT_CALL( | 423 EXPECT_CALL( |
| 424 *observer_helper_->observer(), | 424 *observer_helper_->observer(), |
| 425 Observe( | 425 Observe( |
| 426 NotificationType(NotificationType::AUTOFILL_CREDIT_CARD_CHANGED), | 426 int(chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED), |
| 427 Source<WebDataService>(wds_.get()), | 427 Source<WebDataService>(wds_.get()), |
| 428 Property(&Details<const AutofillCreditCardChange>::ptr, | 428 Property(&Details<const AutofillCreditCardChange>::ptr, |
| 429 Pointee(expected_change)))). | 429 Pointee(expected_change)))). |
| 430 WillOnce(SignalEvent(&done_event_)); | 430 WillOnce(SignalEvent(&done_event_)); |
| 431 wds_->RemoveCreditCard(credit_card.guid()); | 431 wds_->RemoveCreditCard(credit_card.guid()); |
| 432 done_event_.TimedWait(test_timeout_); | 432 done_event_.TimedWait(test_timeout_); |
| 433 | 433 |
| 434 // Check that it was removed. | 434 // Check that it was removed. |
| 435 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer2; | 435 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer2; |
| 436 WebDataService::Handle handle2 = wds_->GetCreditCards(&consumer2); | 436 WebDataService::Handle handle2 = wds_->GetCreditCards(&consumer2); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 464 STLDeleteElements(&consumer.result()); | 464 STLDeleteElements(&consumer.result()); |
| 465 | 465 |
| 466 CreditCard card1_changed(card1); | 466 CreditCard card1_changed(card1); |
| 467 card1_changed.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill")); | 467 card1_changed.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill")); |
| 468 const AutofillCreditCardChange expected_change( | 468 const AutofillCreditCardChange expected_change( |
| 469 AutofillCreditCardChange::UPDATE, card1.guid(), &card1_changed); | 469 AutofillCreditCardChange::UPDATE, card1.guid(), &card1_changed); |
| 470 | 470 |
| 471 EXPECT_CALL( | 471 EXPECT_CALL( |
| 472 *observer_helper_->observer(), | 472 *observer_helper_->observer(), |
| 473 Observe( | 473 Observe( |
| 474 NotificationType(NotificationType::AUTOFILL_CREDIT_CARD_CHANGED), | 474 int(chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED), |
| 475 Source<WebDataService>(wds_.get()), | 475 Source<WebDataService>(wds_.get()), |
| 476 Property(&Details<const AutofillCreditCardChange>::ptr, | 476 Property(&Details<const AutofillCreditCardChange>::ptr, |
| 477 Pointee(expected_change)))). | 477 Pointee(expected_change)))). |
| 478 WillOnce(SignalEvent(&done_event_)); | 478 WillOnce(SignalEvent(&done_event_)); |
| 479 | 479 |
| 480 wds_->UpdateCreditCard(card1_changed); | 480 wds_->UpdateCreditCard(card1_changed); |
| 481 done_event_.TimedWait(test_timeout_); | 481 done_event_.TimedWait(test_timeout_); |
| 482 | 482 |
| 483 // Check that the updates were made. | 483 // Check that the updates were made. |
| 484 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer2; | 484 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > consumer2; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 EXPECT_EQ(handle, card_consumer.handle()); | 526 EXPECT_EQ(handle, card_consumer.handle()); |
| 527 ASSERT_EQ(1U, card_consumer.result().size()); | 527 ASSERT_EQ(1U, card_consumer.result().size()); |
| 528 EXPECT_EQ(credit_card, *card_consumer.result()[0]); | 528 EXPECT_EQ(credit_card, *card_consumer.result()[0]); |
| 529 STLDeleteElements(&card_consumer.result()); | 529 STLDeleteElements(&card_consumer.result()); |
| 530 | 530 |
| 531 // Check that GUID-based notification was sent for the profile. | 531 // Check that GUID-based notification was sent for the profile. |
| 532 const AutofillProfileChange expected_profile_change( | 532 const AutofillProfileChange expected_profile_change( |
| 533 AutofillProfileChange::REMOVE, profile.guid(), NULL); | 533 AutofillProfileChange::REMOVE, profile.guid(), NULL); |
| 534 EXPECT_CALL( | 534 EXPECT_CALL( |
| 535 *observer_helper_->observer(), | 535 *observer_helper_->observer(), |
| 536 Observe(NotificationType(NotificationType::AUTOFILL_PROFILE_CHANGED), | 536 Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED), |
| 537 Source<WebDataService>(wds_.get()), | 537 Source<WebDataService>(wds_.get()), |
| 538 Property(&Details<const AutofillProfileChange>::ptr, | 538 Property(&Details<const AutofillProfileChange>::ptr, |
| 539 Pointee(expected_profile_change)))). | 539 Pointee(expected_profile_change)))). |
| 540 WillOnce(SignalEvent(&done_event_)); | 540 WillOnce(SignalEvent(&done_event_)); |
| 541 | 541 |
| 542 // Check that GUID-based notification was sent for the credit card. | 542 // Check that GUID-based notification was sent for the credit card. |
| 543 const AutofillCreditCardChange expected_card_change( | 543 const AutofillCreditCardChange expected_card_change( |
| 544 AutofillCreditCardChange::REMOVE, credit_card.guid(), NULL); | 544 AutofillCreditCardChange::REMOVE, credit_card.guid(), NULL); |
| 545 EXPECT_CALL( | 545 EXPECT_CALL( |
| 546 *observer_helper_->observer(), | 546 *observer_helper_->observer(), |
| 547 Observe( | 547 Observe( |
| 548 NotificationType(NotificationType::AUTOFILL_CREDIT_CARD_CHANGED), | 548 int(chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED), |
| 549 Source<WebDataService>(wds_.get()), | 549 Source<WebDataService>(wds_.get()), |
| 550 Property(&Details<const AutofillCreditCardChange>::ptr, | 550 Property(&Details<const AutofillCreditCardChange>::ptr, |
| 551 Pointee(expected_card_change)))). | 551 Pointee(expected_card_change)))). |
| 552 WillOnce(SignalEvent(&done_event_)); | 552 WillOnce(SignalEvent(&done_event_)); |
| 553 | 553 |
| 554 // Remove the profile using time range of "all time". | 554 // Remove the profile using time range of "all time". |
| 555 wds_->RemoveAutofillProfilesAndCreditCardsModifiedBetween(Time(), Time()); | 555 wds_->RemoveAutofillProfilesAndCreditCardsModifiedBetween(Time(), Time()); |
| 556 done_event_.TimedWait(test_timeout_); | 556 done_event_.TimedWait(test_timeout_); |
| 557 done_event_.TimedWait(test_timeout_); | 557 done_event_.TimedWait(test_timeout_); |
| 558 | 558 |
| 559 // Check that the profile was removed. | 559 // Check that the profile was removed. |
| 560 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > | 560 AutofillWebDataServiceConsumer<std::vector<AutofillProfile*> > |
| 561 profile_consumer2; | 561 profile_consumer2; |
| 562 WebDataService::Handle handle2 = | 562 WebDataService::Handle handle2 = |
| 563 wds_->GetAutofillProfiles(&profile_consumer2); | 563 wds_->GetAutofillProfiles(&profile_consumer2); |
| 564 MessageLoop::current()->Run(); | 564 MessageLoop::current()->Run(); |
| 565 EXPECT_EQ(handle2, profile_consumer2.handle()); | 565 EXPECT_EQ(handle2, profile_consumer2.handle()); |
| 566 ASSERT_EQ(0U, profile_consumer2.result().size()); | 566 ASSERT_EQ(0U, profile_consumer2.result().size()); |
| 567 | 567 |
| 568 // Check that the credit card was removed. | 568 // Check that the credit card was removed. |
| 569 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > | 569 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > |
| 570 card_consumer2; | 570 card_consumer2; |
| 571 handle2 = wds_->GetCreditCards(&card_consumer2); | 571 handle2 = wds_->GetCreditCards(&card_consumer2); |
| 572 MessageLoop::current()->Run(); | 572 MessageLoop::current()->Run(); |
| 573 EXPECT_EQ(handle2, card_consumer2.handle()); | 573 EXPECT_EQ(handle2, card_consumer2.handle()); |
| 574 ASSERT_EQ(0U, card_consumer2.result().size()); | 574 ASSERT_EQ(0U, card_consumer2.result().size()); |
| 575 } | 575 } |
| OLD | NEW |