| 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" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 &AutofillWebDataService::RemoveObserver; | 142 &AutofillWebDataService::RemoveObserver; |
| 143 BrowserThread::PostTask( | 143 BrowserThread::PostTask( |
| 144 BrowserThread::DB, | 144 BrowserThread::DB, |
| 145 FROM_HERE, | 145 FROM_HERE, |
| 146 base::Bind(remove_observer_func, wds_, &observer_)); | 146 base::Bind(remove_observer_func, wds_, &observer_)); |
| 147 WaitForDatabaseThread(); | 147 WaitForDatabaseThread(); |
| 148 | 148 |
| 149 WebDataServiceTest::TearDown(); | 149 WebDataServiceTest::TearDown(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void AppendFormField(const string16& name, | 152 void AppendFormField(const base::string16& name, |
| 153 const string16& value, | 153 const base::string16& value, |
| 154 std::vector<FormFieldData>* form_fields) { | 154 std::vector<FormFieldData>* form_fields) { |
| 155 FormFieldData field; | 155 FormFieldData field; |
| 156 field.name = name; | 156 field.name = name; |
| 157 field.value = value; | 157 field.value = value; |
| 158 form_fields->push_back(field); | 158 form_fields->push_back(field); |
| 159 } | 159 } |
| 160 | 160 |
| 161 string16 name1_; | 161 base::string16 name1_; |
| 162 string16 name2_; | 162 base::string16 name2_; |
| 163 string16 value1_; | 163 base::string16 value1_; |
| 164 string16 value2_; | 164 base::string16 value2_; |
| 165 int unique_id1_, unique_id2_; | 165 int unique_id1_, unique_id2_; |
| 166 const TimeDelta test_timeout_; | 166 const TimeDelta test_timeout_; |
| 167 testing::NiceMock<MockAutofillWebDataServiceObserver> observer_; | 167 testing::NiceMock<MockAutofillWebDataServiceObserver> observer_; |
| 168 WaitableEvent done_event_; | 168 WaitableEvent done_event_; |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 // Simple consumer for Keywords data. Stores the result data and quits UI | 171 // Simple consumer for Keywords data. Stores the result data and quits UI |
| 172 // message loop when callback is invoked. | 172 // message loop when callback is invoked. |
| 173 class KeywordsConsumer : public WebDataServiceConsumer { | 173 class KeywordsConsumer : public WebDataServiceConsumer { |
| 174 public: | 174 public: |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 .WillOnce(SignalEvent(&done_event_)); | 208 .WillOnce(SignalEvent(&done_event_)); |
| 209 | 209 |
| 210 std::vector<FormFieldData> form_fields; | 210 std::vector<FormFieldData> form_fields; |
| 211 AppendFormField(name1_, value1_, &form_fields); | 211 AppendFormField(name1_, value1_, &form_fields); |
| 212 AppendFormField(name2_, value2_, &form_fields); | 212 AppendFormField(name2_, value2_, &form_fields); |
| 213 wds_->AddFormFields(form_fields); | 213 wds_->AddFormFields(form_fields); |
| 214 | 214 |
| 215 // The event will be signaled when the mock observer is notified. | 215 // The event will be signaled when the mock observer is notified. |
| 216 done_event_.TimedWait(test_timeout_); | 216 done_event_.TimedWait(test_timeout_); |
| 217 | 217 |
| 218 AutofillWebDataServiceConsumer<std::vector<string16> > consumer; | 218 AutofillWebDataServiceConsumer<std::vector<base::string16> > consumer; |
| 219 WebDataService::Handle handle; | 219 WebDataService::Handle handle; |
| 220 static const int limit = 10; | 220 static const int limit = 10; |
| 221 handle = wds_->GetFormValuesForElementName( | 221 handle = wds_->GetFormValuesForElementName( |
| 222 name1_, string16(), limit, &consumer); | 222 name1_, base::string16(), limit, &consumer); |
| 223 | 223 |
| 224 // The message loop will exit when the consumer is called. | 224 // The message loop will exit when the consumer is called. |
| 225 MessageLoop::current()->Run(); | 225 MessageLoop::current()->Run(); |
| 226 | 226 |
| 227 EXPECT_EQ(handle, consumer.handle()); | 227 EXPECT_EQ(handle, consumer.handle()); |
| 228 ASSERT_EQ(1U, consumer.result().size()); | 228 ASSERT_EQ(1U, consumer.result().size()); |
| 229 EXPECT_EQ(value1_, consumer.result()[0]); | 229 EXPECT_EQ(value1_, consumer.result()[0]); |
| 230 } | 230 } |
| 231 | 231 |
| 232 TEST_F(WebDataServiceAutofillTest, FormFillRemoveOne) { | 232 TEST_F(WebDataServiceAutofillTest, FormFillRemoveOne) { |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 EXPECT_EQ(handle2, profile_consumer2.handle()); | 523 EXPECT_EQ(handle2, profile_consumer2.handle()); |
| 524 ASSERT_EQ(0U, profile_consumer2.result().size()); | 524 ASSERT_EQ(0U, profile_consumer2.result().size()); |
| 525 | 525 |
| 526 // Check that the credit card was removed. | 526 // Check that the credit card was removed. |
| 527 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2; | 527 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2; |
| 528 handle2 = wds_->GetCreditCards(&card_consumer2); | 528 handle2 = wds_->GetCreditCards(&card_consumer2); |
| 529 MessageLoop::current()->Run(); | 529 MessageLoop::current()->Run(); |
| 530 EXPECT_EQ(handle2, card_consumer2.handle()); | 530 EXPECT_EQ(handle2, card_consumer2.handle()); |
| 531 ASSERT_EQ(0U, card_consumer2.result().size()); | 531 ASSERT_EQ(0U, card_consumer2.result().size()); |
| 532 } | 532 } |
| OLD | NEW |