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/autofill_table.h" |
22 #include "chrome/browser/webdata/web_data_service.h" | 23 #include "chrome/browser/webdata/web_data_service.h" |
23 #include "chrome/browser/webdata/web_data_service_test_util.h" | 24 #include "chrome/browser/webdata/web_data_service_test_util.h" |
| 25 #include "chrome/browser/webdata/web_database_service.h" |
24 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
25 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
26 #include "chrome/test/base/thread_observer_helper.h" | 28 #include "chrome/test/base/thread_observer_helper.h" |
27 #include "components/autofill/browser/autofill_profile.h" | 29 #include "components/autofill/browser/autofill_profile.h" |
28 #include "components/autofill/browser/credit_card.h" | 30 #include "components/autofill/browser/credit_card.h" |
29 #include "components/autofill/common/form_field_data.h" | 31 #include "components/autofill/common/form_field_data.h" |
30 #include "content/public/browser/notification_details.h" | 32 #include "content/public/browser/notification_details.h" |
31 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
32 #include "content/public/test/test_browser_thread.h" | 34 #include "content/public/test/test_browser_thread.h" |
33 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 public: | 71 public: |
70 WebDataServiceTest() | 72 WebDataServiceTest() |
71 : ui_thread_(BrowserThread::UI, &message_loop_), | 73 : ui_thread_(BrowserThread::UI, &message_loop_), |
72 db_thread_(BrowserThread::DB) {} | 74 db_thread_(BrowserThread::DB) {} |
73 | 75 |
74 protected: | 76 protected: |
75 virtual void SetUp() { | 77 virtual void SetUp() { |
76 db_thread_.Start(); | 78 db_thread_.Start(); |
77 | 79 |
78 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 80 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
79 wds_ = new WebDataService(WebDataServiceBase::ProfileErrorCallback()); | 81 |
80 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB"); | 82 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB"); |
81 wds_->Init(path); | 83 |
| 84 wdbs_ = new WebDatabaseService(path); |
| 85 wdbs_->AddTable(scoped_ptr<WebDatabaseTable>(new AutofillTable())); |
| 86 wdbs_->LoadDatabase(WebDatabaseService::InitCallback()); |
| 87 |
| 88 wds_ = new WebDataService(wdbs_, |
| 89 WebDataServiceBase::ProfileErrorCallback()); |
| 90 wds_->Init(); |
82 } | 91 } |
83 | 92 |
84 virtual void TearDown() { | 93 virtual void TearDown() { |
85 wds_->ShutdownOnUIThread(); | 94 wds_->ShutdownOnUIThread(); |
| 95 wdbs_->ShutdownDatabase(); |
86 wds_ = NULL; | 96 wds_ = NULL; |
| 97 wdbs_ = NULL; |
87 WaitForDatabaseThread(); | 98 WaitForDatabaseThread(); |
88 | 99 |
89 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 100 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
90 MessageLoop::current()->Run(); | 101 MessageLoop::current()->Run(); |
91 db_thread_.Stop(); | 102 db_thread_.Stop(); |
92 } | 103 } |
93 | 104 |
94 void WaitForDatabaseThread() { | 105 void WaitForDatabaseThread() { |
95 base::WaitableEvent done(false, false); | 106 base::WaitableEvent done(false, false); |
96 BrowserThread::PostTask( | 107 BrowserThread::PostTask( |
97 BrowserThread::DB, | 108 BrowserThread::DB, |
98 FROM_HERE, | 109 FROM_HERE, |
99 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | 110 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
100 done.Wait(); | 111 done.Wait(); |
101 } | 112 } |
102 | 113 |
103 MessageLoopForUI message_loop_; | 114 MessageLoopForUI message_loop_; |
104 content::TestBrowserThread ui_thread_; | 115 content::TestBrowserThread ui_thread_; |
105 content::TestBrowserThread db_thread_; | 116 content::TestBrowserThread db_thread_; |
106 base::FilePath profile_dir_; | 117 base::FilePath profile_dir_; |
107 scoped_refptr<WebDataService> wds_; | 118 scoped_refptr<WebDataService> wds_; |
| 119 scoped_refptr<WebDatabaseService> wdbs_; |
108 base::ScopedTempDir temp_dir_; | 120 base::ScopedTempDir temp_dir_; |
109 }; | 121 }; |
110 | 122 |
111 class WebDataServiceAutofillTest : public WebDataServiceTest { | 123 class WebDataServiceAutofillTest : public WebDataServiceTest { |
112 public: | 124 public: |
113 WebDataServiceAutofillTest() | 125 WebDataServiceAutofillTest() |
114 : WebDataServiceTest(), | 126 : WebDataServiceTest(), |
115 unique_id1_(1), | 127 unique_id1_(1), |
116 unique_id2_(2), | 128 unique_id2_(2), |
117 test_timeout_(TimeDelta::FromSeconds(kWebDataServiceTimeoutSeconds)), | 129 test_timeout_(TimeDelta::FromSeconds(kWebDataServiceTimeoutSeconds)), |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 EXPECT_EQ(handle2, profile_consumer2.handle()); | 552 EXPECT_EQ(handle2, profile_consumer2.handle()); |
541 ASSERT_EQ(0U, profile_consumer2.result().size()); | 553 ASSERT_EQ(0U, profile_consumer2.result().size()); |
542 | 554 |
543 // Check that the credit card was removed. | 555 // Check that the credit card was removed. |
544 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2; | 556 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2; |
545 handle2 = wds_->GetCreditCards(&card_consumer2); | 557 handle2 = wds_->GetCreditCards(&card_consumer2); |
546 MessageLoop::current()->Run(); | 558 MessageLoop::current()->Run(); |
547 EXPECT_EQ(handle2, card_consumer2.handle()); | 559 EXPECT_EQ(handle2, card_consumer2.handle()); |
548 ASSERT_EQ(0U, card_consumer2.result().size()); | 560 ASSERT_EQ(0U, card_consumer2.result().size()); |
549 } | 561 } |
OLD | NEW |