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/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/scoped_temp_dir.h" | 13 #include "base/scoped_temp_dir.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/autofill/autofill_profile.h" | 20 #include "chrome/browser/autofill/autofill_profile.h" |
21 #include "chrome/browser/autofill/credit_card.h" | 21 #include "chrome/browser/autofill/credit_card.h" |
22 #include "chrome/browser/intents/default_web_intent_service.h" | 22 #include "chrome/browser/intents/default_web_intent_service.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/browser/webdata/web_intents_table.h" | 27 #include "chrome/browser/webdata/web_intents_table.h" |
28 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
| 30 #include "chrome/common/form_field_data.h" |
30 #include "chrome/test/base/thread_observer_helper.h" | 31 #include "chrome/test/base/thread_observer_helper.h" |
31 #include "content/public/browser/notification_details.h" | 32 #include "content/public/browser/notification_details.h" |
32 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
33 #include "content/public/test/test_browser_thread.h" | 34 #include "content/public/test/test_browser_thread.h" |
34 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
36 #include "webkit/forms/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 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; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 128 } |
129 | 129 |
130 virtual void TearDown() { | 130 virtual void TearDown() { |
131 // Release this first so it can get destructed on the db thread. | 131 // Release this first so it can get destructed on the db thread. |
132 observer_helper_ = NULL; | 132 observer_helper_ = NULL; |
133 WebDataServiceTest::TearDown(); | 133 WebDataServiceTest::TearDown(); |
134 } | 134 } |
135 | 135 |
136 void AppendFormField(const string16& name, | 136 void AppendFormField(const string16& name, |
137 const string16& value, | 137 const string16& value, |
138 std::vector<webkit::forms::FormField>* form_fields) { | 138 std::vector<FormFieldData>* form_fields) { |
139 webkit::forms::FormField field; | 139 FormFieldData field; |
140 field.name = name; | 140 field.name = name; |
141 field.value = value; | 141 field.value = value; |
142 form_fields->push_back(field); | 142 form_fields->push_back(field); |
143 } | 143 } |
144 | 144 |
145 string16 name1_; | 145 string16 name1_; |
146 string16 name2_; | 146 string16 name2_; |
147 string16 value1_; | 147 string16 value1_; |
148 string16 value2_; | 148 string16 value2_; |
149 int unique_id1_, unique_id2_; | 149 int unique_id1_, unique_id2_; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 // This will verify that the correct notification is triggered, | 238 // This will verify that the correct notification is triggered, |
239 // passing the correct list of autofill keys in the details. | 239 // passing the correct list of autofill keys in the details. |
240 EXPECT_CALL( | 240 EXPECT_CALL( |
241 *observer_helper_->observer(), | 241 *observer_helper_->observer(), |
242 Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED), | 242 Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED), |
243 content::Source<WebDataService>(wds_.get()), | 243 content::Source<WebDataService>(wds_.get()), |
244 Property(&content::Details<const AutofillChangeList>::ptr, | 244 Property(&content::Details<const AutofillChangeList>::ptr, |
245 Pointee(ElementsAreArray(expected_changes))))). | 245 Pointee(ElementsAreArray(expected_changes))))). |
246 WillOnce(SignalEvent(&done_event_)); | 246 WillOnce(SignalEvent(&done_event_)); |
247 | 247 |
248 std::vector<webkit::forms::FormField> form_fields; | 248 std::vector<FormFieldData> form_fields; |
249 AppendFormField(name1_, value1_, &form_fields); | 249 AppendFormField(name1_, value1_, &form_fields); |
250 AppendFormField(name2_, value2_, &form_fields); | 250 AppendFormField(name2_, value2_, &form_fields); |
251 wds_->AddFormFields(form_fields); | 251 wds_->AddFormFields(form_fields); |
252 | 252 |
253 // The event will be signaled when the mock observer is notified. | 253 // The event will be signaled when the mock observer is notified. |
254 done_event_.TimedWait(test_timeout_); | 254 done_event_.TimedWait(test_timeout_); |
255 | 255 |
256 AutofillWebDataServiceConsumer<std::vector<string16> > consumer; | 256 AutofillWebDataServiceConsumer<std::vector<string16> > consumer; |
257 WebDataService::Handle handle; | 257 WebDataService::Handle handle; |
258 static const int limit = 10; | 258 static const int limit = 10; |
259 handle = wds_->GetFormValuesForElementName( | 259 handle = wds_->GetFormValuesForElementName( |
260 name1_, string16(), limit, &consumer); | 260 name1_, string16(), limit, &consumer); |
261 | 261 |
262 // The message loop will exit when the consumer is called. | 262 // The message loop will exit when the consumer is called. |
263 MessageLoop::current()->Run(); | 263 MessageLoop::current()->Run(); |
264 | 264 |
265 EXPECT_EQ(handle, consumer.handle()); | 265 EXPECT_EQ(handle, consumer.handle()); |
266 ASSERT_EQ(1U, consumer.result().size()); | 266 ASSERT_EQ(1U, consumer.result().size()); |
267 EXPECT_EQ(value1_, consumer.result()[0]); | 267 EXPECT_EQ(value1_, consumer.result()[0]); |
268 } | 268 } |
269 | 269 |
270 TEST_F(WebDataServiceAutofillTest, FormFillRemoveOne) { | 270 TEST_F(WebDataServiceAutofillTest, FormFillRemoveOne) { |
271 // First add some values to autofill. | 271 // First add some values to autofill. |
272 EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). | 272 EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). |
273 WillOnce(SignalEvent(&done_event_)); | 273 WillOnce(SignalEvent(&done_event_)); |
274 std::vector<webkit::forms::FormField> form_fields; | 274 std::vector<FormFieldData> form_fields; |
275 AppendFormField(name1_, value1_, &form_fields); | 275 AppendFormField(name1_, value1_, &form_fields); |
276 wds_->AddFormFields(form_fields); | 276 wds_->AddFormFields(form_fields); |
277 | 277 |
278 // The event will be signaled when the mock observer is notified. | 278 // The event will be signaled when the mock observer is notified. |
279 done_event_.TimedWait(test_timeout_); | 279 done_event_.TimedWait(test_timeout_); |
280 | 280 |
281 // This will verify that the correct notification is triggered, | 281 // This will verify that the correct notification is triggered, |
282 // passing the correct list of autofill keys in the details. | 282 // passing the correct list of autofill keys in the details. |
283 const AutofillChange expected_changes[] = { | 283 const AutofillChange expected_changes[] = { |
284 AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)) | 284 AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)) |
(...skipping 10 matching lines...) Expand all Loading... |
295 // The event will be signaled when the mock observer is notified. | 295 // The event will be signaled when the mock observer is notified. |
296 done_event_.TimedWait(test_timeout_); | 296 done_event_.TimedWait(test_timeout_); |
297 } | 297 } |
298 | 298 |
299 TEST_F(WebDataServiceAutofillTest, FormFillRemoveMany) { | 299 TEST_F(WebDataServiceAutofillTest, FormFillRemoveMany) { |
300 TimeDelta one_day(TimeDelta::FromDays(1)); | 300 TimeDelta one_day(TimeDelta::FromDays(1)); |
301 Time t = Time::Now(); | 301 Time t = Time::Now(); |
302 | 302 |
303 EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). | 303 EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)). |
304 WillOnce(SignalEvent(&done_event_)); | 304 WillOnce(SignalEvent(&done_event_)); |
305 std::vector<webkit::forms::FormField> form_fields; | 305 std::vector<FormFieldData> form_fields; |
306 AppendFormField(name1_, value1_, &form_fields); | 306 AppendFormField(name1_, value1_, &form_fields); |
307 AppendFormField(name2_, value2_, &form_fields); | 307 AppendFormField(name2_, value2_, &form_fields); |
308 wds_->AddFormFields(form_fields); | 308 wds_->AddFormFields(form_fields); |
309 | 309 |
310 // The event will be signaled when the mock observer is notified. | 310 // The event will be signaled when the mock observer is notified. |
311 done_event_.TimedWait(test_timeout_); | 311 done_event_.TimedWait(test_timeout_); |
312 | 312 |
313 // This will verify that the correct notification is triggered, | 313 // This will verify that the correct notification is triggered, |
314 // passing the correct list of autofill keys in the details. | 314 // passing the correct list of autofill keys in the details. |
315 const AutofillChange expected_changes[] = { | 315 const AutofillChange expected_changes[] = { |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 } | 828 } |
829 | 829 |
830 TEST_F(WebDataServiceTest, DidDefaultSearchProviderChangeOnNewProfile) { | 830 TEST_F(WebDataServiceTest, DidDefaultSearchProviderChangeOnNewProfile) { |
831 KeywordsConsumer consumer; | 831 KeywordsConsumer consumer; |
832 wds_->GetKeywords(&consumer); | 832 wds_->GetKeywords(&consumer); |
833 WaitUntilCalled(); | 833 WaitUntilCalled(); |
834 ASSERT_TRUE(consumer.load_succeeded); | 834 ASSERT_TRUE(consumer.load_succeeded); |
835 EXPECT_FALSE(consumer.keywords_result.did_default_search_provider_change); | 835 EXPECT_FALSE(consumer.keywords_result.did_default_search_provider_change); |
836 EXPECT_FALSE(consumer.keywords_result.backup_valid); | 836 EXPECT_FALSE(consumer.keywords_result.backup_valid); |
837 } | 837 } |
OLD | NEW |