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