| 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 <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 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/location.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/synchronization/waitable_event.h" | 20 #include "base/synchronization/waitable_event.h" |
| 21 #include "base/test/scoped_task_environment.h" |
| 21 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
| 22 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
| 23 #include "base/time/time.h" | 24 #include "base/time/time.h" |
| 24 #include "components/autofill/core/browser/autofill_country.h" | 25 #include "components/autofill/core/browser/autofill_country.h" |
| 25 #include "components/autofill/core/browser/autofill_profile.h" | 26 #include "components/autofill/core/browser/autofill_profile.h" |
| 26 #include "components/autofill/core/browser/credit_card.h" | 27 #include "components/autofill/core/browser/credit_card.h" |
| 27 #include "components/autofill/core/browser/webdata/autofill_change.h" | 28 #include "components/autofill/core/browser/webdata/autofill_change.h" |
| 28 #include "components/autofill/core/browser/webdata/autofill_entry.h" | 29 #include "components/autofill/core/browser/webdata/autofill_entry.h" |
| 29 #include "components/autofill/core/browser/webdata/autofill_table.h" | 30 #include "components/autofill/core/browser/webdata/autofill_table.h" |
| 30 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 31 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 : public AutofillWebDataServiceObserverOnDBThread { | 86 : public AutofillWebDataServiceObserverOnDBThread { |
| 86 public: | 87 public: |
| 87 MOCK_METHOD1(AutofillEntriesChanged, | 88 MOCK_METHOD1(AutofillEntriesChanged, |
| 88 void(const AutofillChangeList& changes)); | 89 void(const AutofillChangeList& changes)); |
| 89 MOCK_METHOD1(AutofillProfileChanged, | 90 MOCK_METHOD1(AutofillProfileChanged, |
| 90 void(const AutofillProfileChange& change)); | 91 void(const AutofillProfileChange& change)); |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 class WebDataServiceTest : public testing::Test { | 94 class WebDataServiceTest : public testing::Test { |
| 94 public: | 95 public: |
| 95 WebDataServiceTest() : db_thread_("DBThread") {} | 96 WebDataServiceTest() |
| 97 : scoped_task_environment_( |
| 98 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 99 db_thread_("DBThread") {} |
| 96 | 100 |
| 97 protected: | 101 protected: |
| 98 void SetUp() override { | 102 void SetUp() override { |
| 99 db_thread_.Start(); | 103 db_thread_.Start(); |
| 100 | 104 |
| 101 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 105 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 102 base::FilePath path = temp_dir_.GetPath().AppendASCII("TestWebDB"); | 106 base::FilePath path = temp_dir_.GetPath().AppendASCII("TestWebDB"); |
| 103 | 107 |
| 104 wdbs_ = new WebDatabaseService(path, base::ThreadTaskRunnerHandle::Get(), | 108 wdbs_ = new WebDatabaseService(path, base::ThreadTaskRunnerHandle::Get(), |
| 105 db_thread_.task_runner()); | 109 db_thread_.task_runner()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 127 | 131 |
| 128 void WaitForDatabaseThread() { | 132 void WaitForDatabaseThread() { |
| 129 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 133 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 130 base::WaitableEvent::InitialState::NOT_SIGNALED); | 134 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 131 db_thread_.task_runner()->PostTask( | 135 db_thread_.task_runner()->PostTask( |
| 132 FROM_HERE, | 136 FROM_HERE, |
| 133 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | 137 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 134 done.Wait(); | 138 done.Wait(); |
| 135 } | 139 } |
| 136 | 140 |
| 137 base::MessageLoopForUI message_loop_; | 141 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 138 base::Thread db_thread_; | 142 base::Thread db_thread_; |
| 139 base::FilePath profile_dir_; | 143 base::FilePath profile_dir_; |
| 140 scoped_refptr<AutofillWebDataService> wds_; | 144 scoped_refptr<AutofillWebDataService> wds_; |
| 141 scoped_refptr<WebDatabaseService> wdbs_; | 145 scoped_refptr<WebDatabaseService> wdbs_; |
| 142 base::ScopedTempDir temp_dir_; | 146 base::ScopedTempDir temp_dir_; |
| 143 }; | 147 }; |
| 144 | 148 |
| 145 class WebDataServiceAutofillTest : public WebDataServiceTest { | 149 class WebDataServiceAutofillTest : public WebDataServiceTest { |
| 146 public: | 150 public: |
| 147 WebDataServiceAutofillTest() | 151 WebDataServiceAutofillTest() |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 // Check that the credit card was removed. | 540 // Check that the credit card was removed. |
| 537 AutofillWebDataServiceConsumer<std::vector<std::unique_ptr<CreditCard>>> | 541 AutofillWebDataServiceConsumer<std::vector<std::unique_ptr<CreditCard>>> |
| 538 card_consumer2; | 542 card_consumer2; |
| 539 handle2 = wds_->GetCreditCards(&card_consumer2); | 543 handle2 = wds_->GetCreditCards(&card_consumer2); |
| 540 base::RunLoop().Run(); | 544 base::RunLoop().Run(); |
| 541 EXPECT_EQ(handle2, card_consumer2.handle()); | 545 EXPECT_EQ(handle2, card_consumer2.handle()); |
| 542 ASSERT_EQ(0U, card_consumer2.result().size()); | 546 ASSERT_EQ(0U, card_consumer2.result().size()); |
| 543 } | 547 } |
| 544 | 548 |
| 545 } // namespace autofill | 549 } // namespace autofill |
| OLD | NEW |