| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/location.h" |
| 11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 14 #include "base/message_loop/message_loop.h" | 15 #include "base/single_thread_task_runner.h" |
| 15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 16 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/synchronization/waitable_event.h" | 20 #include "base/synchronization/waitable_event.h" |
| 21 #include "base/thread_task_runner_handle.h" |
| 20 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
| 21 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 22 #include "components/autofill/core/browser/autofill_country.h" | 24 #include "components/autofill/core/browser/autofill_country.h" |
| 23 #include "components/autofill/core/browser/autofill_profile.h" | 25 #include "components/autofill/core/browser/autofill_profile.h" |
| 24 #include "components/autofill/core/browser/credit_card.h" | 26 #include "components/autofill/core/browser/credit_card.h" |
| 25 #include "components/autofill/core/browser/webdata/autofill_change.h" | 27 #include "components/autofill/core/browser/webdata/autofill_change.h" |
| 26 #include "components/autofill/core/browser/webdata/autofill_entry.h" | 28 #include "components/autofill/core/browser/webdata/autofill_entry.h" |
| 27 #include "components/autofill/core/browser/webdata/autofill_table.h" | 29 #include "components/autofill/core/browser/webdata/autofill_table.h" |
| 28 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 30 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
| 29 #include "components/autofill/core/browser/webdata/autofill_webdata_service_obse
rver.h" | 31 #include "components/autofill/core/browser/webdata/autofill_webdata_service_obse
rver.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 public: | 95 public: |
| 94 WebDataServiceTest() : db_thread_("DBThread") {} | 96 WebDataServiceTest() : db_thread_("DBThread") {} |
| 95 | 97 |
| 96 protected: | 98 protected: |
| 97 void SetUp() override { | 99 void SetUp() override { |
| 98 db_thread_.Start(); | 100 db_thread_.Start(); |
| 99 | 101 |
| 100 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 102 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 101 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB"); | 103 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB"); |
| 102 | 104 |
| 103 wdbs_ = new WebDatabaseService(path, | 105 wdbs_ = new WebDatabaseService(path, base::ThreadTaskRunnerHandle::Get(), |
| 104 base::MessageLoopProxy::current(), | 106 db_thread_.task_runner()); |
| 105 db_thread_.message_loop_proxy()); | |
| 106 wdbs_->AddTable(scoped_ptr<WebDatabaseTable>(new AutofillTable("en-US"))); | 107 wdbs_->AddTable(scoped_ptr<WebDatabaseTable>(new AutofillTable("en-US"))); |
| 107 wdbs_->LoadDatabase(); | 108 wdbs_->LoadDatabase(); |
| 108 | 109 |
| 109 wds_ = | 110 wds_ = new AutofillWebDataService( |
| 110 new AutofillWebDataService(wdbs_, | 111 wdbs_, base::ThreadTaskRunnerHandle::Get(), db_thread_.task_runner(), |
| 111 base::MessageLoopProxy::current(), | 112 WebDataServiceBase::ProfileErrorCallback()); |
| 112 db_thread_.message_loop_proxy(), | |
| 113 WebDataServiceBase::ProfileErrorCallback()); | |
| 114 wds_->Init(); | 113 wds_->Init(); |
| 115 } | 114 } |
| 116 | 115 |
| 117 void TearDown() override { | 116 void TearDown() override { |
| 118 wds_->ShutdownOnUIThread(); | 117 wds_->ShutdownOnUIThread(); |
| 119 wdbs_->ShutdownDatabase(); | 118 wdbs_->ShutdownDatabase(); |
| 120 wds_ = NULL; | 119 wds_ = NULL; |
| 121 wdbs_ = NULL; | 120 wdbs_ = NULL; |
| 122 WaitForDatabaseThread(); | 121 WaitForDatabaseThread(); |
| 123 | 122 |
| 124 base::MessageLoop::current()->PostTask(FROM_HERE, | 123 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 125 base::MessageLoop::QuitClosure()); | 124 FROM_HERE, base::MessageLoop::QuitClosure()); |
| 126 base::MessageLoop::current()->Run(); | 125 base::MessageLoop::current()->Run(); |
| 127 db_thread_.Stop(); | 126 db_thread_.Stop(); |
| 128 } | 127 } |
| 129 | 128 |
| 130 void WaitForDatabaseThread() { | 129 void WaitForDatabaseThread() { |
| 131 base::WaitableEvent done(false, false); | 130 base::WaitableEvent done(false, false); |
| 132 db_thread_.message_loop()->PostTask( | 131 db_thread_.task_runner()->PostTask( |
| 133 FROM_HERE, | 132 FROM_HERE, |
| 134 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | 133 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 135 done.Wait(); | 134 done.Wait(); |
| 136 } | 135 } |
| 137 | 136 |
| 138 base::MessageLoopForUI message_loop_; | 137 base::MessageLoopForUI message_loop_; |
| 139 base::Thread db_thread_; | 138 base::Thread db_thread_; |
| 140 base::FilePath profile_dir_; | 139 base::FilePath profile_dir_; |
| 141 scoped_refptr<AutofillWebDataService> wds_; | 140 scoped_refptr<AutofillWebDataService> wds_; |
| 142 scoped_refptr<WebDatabaseService> wdbs_; | 141 scoped_refptr<WebDatabaseService> wdbs_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 156 virtual void SetUp() { | 155 virtual void SetUp() { |
| 157 WebDataServiceTest::SetUp(); | 156 WebDataServiceTest::SetUp(); |
| 158 name1_ = ASCIIToUTF16("name1"); | 157 name1_ = ASCIIToUTF16("name1"); |
| 159 name2_ = ASCIIToUTF16("name2"); | 158 name2_ = ASCIIToUTF16("name2"); |
| 160 value1_ = ASCIIToUTF16("value1"); | 159 value1_ = ASCIIToUTF16("value1"); |
| 161 value2_ = ASCIIToUTF16("value2"); | 160 value2_ = ASCIIToUTF16("value2"); |
| 162 | 161 |
| 163 void(AutofillWebDataService::*add_observer_func)( | 162 void(AutofillWebDataService::*add_observer_func)( |
| 164 AutofillWebDataServiceObserverOnDBThread*) = | 163 AutofillWebDataServiceObserverOnDBThread*) = |
| 165 &AutofillWebDataService::AddObserver; | 164 &AutofillWebDataService::AddObserver; |
| 166 db_thread_.message_loop()->PostTask( | 165 db_thread_.task_runner()->PostTask( |
| 167 FROM_HERE, base::Bind(add_observer_func, wds_, &observer_)); | 166 FROM_HERE, base::Bind(add_observer_func, wds_, &observer_)); |
| 168 WaitForDatabaseThread(); | 167 WaitForDatabaseThread(); |
| 169 } | 168 } |
| 170 | 169 |
| 171 virtual void TearDown() { | 170 virtual void TearDown() { |
| 172 void(AutofillWebDataService::*remove_observer_func)( | 171 void(AutofillWebDataService::*remove_observer_func)( |
| 173 AutofillWebDataServiceObserverOnDBThread*) = | 172 AutofillWebDataServiceObserverOnDBThread*) = |
| 174 &AutofillWebDataService::RemoveObserver; | 173 &AutofillWebDataService::RemoveObserver; |
| 175 db_thread_.message_loop()->PostTask( | 174 db_thread_.task_runner()->PostTask( |
| 176 FROM_HERE, base::Bind(remove_observer_func, wds_, &observer_)); | 175 FROM_HERE, base::Bind(remove_observer_func, wds_, &observer_)); |
| 177 WaitForDatabaseThread(); | 176 WaitForDatabaseThread(); |
| 178 | 177 |
| 179 WebDataServiceTest::TearDown(); | 178 WebDataServiceTest::TearDown(); |
| 180 } | 179 } |
| 181 | 180 |
| 182 void AppendFormField(const base::string16& name, | 181 void AppendFormField(const base::string16& name, |
| 183 const base::string16& value, | 182 const base::string16& value, |
| 184 std::vector<FormFieldData>* form_fields) { | 183 std::vector<FormFieldData>* form_fields) { |
| 185 FormFieldData field; | 184 FormFieldData field; |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 | 533 |
| 535 // Check that the credit card was removed. | 534 // Check that the credit card was removed. |
| 536 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2; | 535 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2; |
| 537 handle2 = wds_->GetCreditCards(&card_consumer2); | 536 handle2 = wds_->GetCreditCards(&card_consumer2); |
| 538 base::MessageLoop::current()->Run(); | 537 base::MessageLoop::current()->Run(); |
| 539 EXPECT_EQ(handle2, card_consumer2.handle()); | 538 EXPECT_EQ(handle2, card_consumer2.handle()); |
| 540 ASSERT_EQ(0U, card_consumer2.result().size()); | 539 ASSERT_EQ(0U, card_consumer2.result().size()); |
| 541 } | 540 } |
| 542 | 541 |
| 543 } // namespace autofill | 542 } // namespace autofill |
| OLD | NEW |