Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: components/autofill/browser/webdata/web_data_service_unittest.cc

Issue 16174013: Remove dependency of WebData on content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/strings/string16.h" 15 #include "base/strings/string16.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/synchronization/waitable_event.h" 18 #include "base/synchronization/waitable_event.h"
19 #include "base/time.h" 19 #include "base/time.h"
20 #include "chrome/browser/webdata/web_data_service.h"
20 #include "components/autofill/browser/autofill_country.h" 21 #include "components/autofill/browser/autofill_country.h"
21 #include "components/autofill/browser/autofill_profile.h" 22 #include "components/autofill/browser/autofill_profile.h"
22 #include "components/autofill/browser/credit_card.h" 23 #include "components/autofill/browser/credit_card.h"
23 #include "components/autofill/browser/webdata/autofill_change.h" 24 #include "components/autofill/browser/webdata/autofill_change.h"
24 #include "components/autofill/browser/webdata/autofill_entry.h" 25 #include "components/autofill/browser/webdata/autofill_entry.h"
25 #include "components/autofill/browser/webdata/autofill_table.h" 26 #include "components/autofill/browser/webdata/autofill_table.h"
26 #include "components/autofill/browser/webdata/autofill_webdata_service.h" 27 #include "components/autofill/browser/webdata/autofill_webdata_service.h"
27 #include "components/autofill/browser/webdata/autofill_webdata_service_observer. h" 28 #include "components/autofill/browser/webdata/autofill_webdata_service_observer. h"
28 #include "components/autofill/common/form_field_data.h" 29 #include "components/autofill/common/form_field_data.h"
29 #include "components/webdata/common/web_data_service_test_util.h"
30 #include "components/webdata/common/web_database_service.h" 30 #include "components/webdata/common/web_database_service.h"
31 #include "components/webdata/common/web_data_results.h"
32 #include "components/webdata/common/web_data_service_base.h"
33 #include "components/webdata/common/web_data_service_consumer.h"
31 #include "content/public/test/test_browser_thread.h" 34 #include "content/public/test/test_browser_thread.h"
32 #include "testing/gmock/include/gmock/gmock.h" 35 #include "testing/gmock/include/gmock/gmock.h"
33 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
34 37
35 using base::Time; 38 using base::Time;
36 using base::TimeDelta; 39 using base::TimeDelta;
37 using base::WaitableEvent; 40 using base::WaitableEvent;
38 using content::BrowserThread; 41 using content::BrowserThread;
39 using testing::_; 42 using testing::_;
40 using testing::DoDefault; 43 using testing::DoDefault;
41 using testing::ElementsAreArray; 44 using testing::ElementsAreArray;
42 using testing::Pointee; 45 using testing::Pointee;
43 using testing::Property; 46 using testing::Property;
44 47
48 namespace {
49
50 template <class T>
51 class AutofillWebDataServiceConsumer: public WebDataServiceConsumer {
52 public:
53 AutofillWebDataServiceConsumer() : handle_(0) {}
54 virtual ~AutofillWebDataServiceConsumer() {}
55
56 virtual void OnWebDataServiceRequestDone(WebDataService::Handle handle,
57 const WDTypedResult* result) {
58 using content::BrowserThread;
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
60 handle_ = handle;
61 const WDResult<T>* wrapped_result =
62 static_cast<const WDResult<T>*>(result);
63 result_ = wrapped_result->GetValue();
64
65 base::MessageLoop::current()->Quit();
66 }
67
68 WebDataService::Handle handle() { return handle_; }
69 T& result() { return result_; }
70
71 private:
72 WebDataService::Handle handle_;
73 T result_;
74 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataServiceConsumer);
75 };
76
77 } // namespace
78
45 namespace autofill { 79 namespace autofill {
46 80
47 static const int kWebDataServiceTimeoutSeconds = 8; 81 static const int kWebDataServiceTimeoutSeconds = 8;
48 82
49 ACTION_P(SignalEvent, event) { 83 ACTION_P(SignalEvent, event) {
50 event->Signal(); 84 event->Signal();
51 } 85 }
52 86
53 class MockAutofillWebDataServiceObserver 87 class MockAutofillWebDataServiceObserver
54 : public AutofillWebDataServiceObserverOnDBThread { 88 : public AutofillWebDataServiceObserverOnDBThread {
(...skipping 10 matching lines...) Expand all
65 : ui_thread_(BrowserThread::UI, &message_loop_), 99 : ui_thread_(BrowserThread::UI, &message_loop_),
66 db_thread_(BrowserThread::DB) {} 100 db_thread_(BrowserThread::DB) {}
67 101
68 protected: 102 protected:
69 virtual void SetUp() { 103 virtual void SetUp() {
70 db_thread_.Start(); 104 db_thread_.Start();
71 105
72 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 106 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
73 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB"); 107 base::FilePath path = temp_dir_.path().AppendASCII("TestWebDB");
74 108
75 wdbs_ = new WebDatabaseService(path, 109 wdbs_ = new WebDatabaseService(
76 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)); 110 path,
111 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
112 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB));
77 wdbs_->AddTable(scoped_ptr<WebDatabaseTable>(new AutofillTable("en-US"))); 113 wdbs_->AddTable(scoped_ptr<WebDatabaseTable>(new AutofillTable("en-US")));
78 wdbs_->LoadDatabase(); 114 wdbs_->LoadDatabase();
79 115
80 wds_ = new AutofillWebDataService( 116 wds_ = new AutofillWebDataService(
81 wdbs_, WebDataServiceBase::ProfileErrorCallback()); 117 wdbs_, WebDataServiceBase::ProfileErrorCallback());
82 wds_->Init(); 118 wds_->Init();
83 } 119 }
84 120
85 virtual void TearDown() { 121 virtual void TearDown() {
86 wds_->ShutdownOnUIThread(); 122 wds_->ShutdownOnUIThread();
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 565
530 // Check that the credit card was removed. 566 // Check that the credit card was removed.
531 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2; 567 AutofillWebDataServiceConsumer<std::vector<CreditCard*> > card_consumer2;
532 handle2 = wds_->GetCreditCards(&card_consumer2); 568 handle2 = wds_->GetCreditCards(&card_consumer2);
533 base::MessageLoop::current()->Run(); 569 base::MessageLoop::current()->Run();
534 EXPECT_EQ(handle2, card_consumer2.handle()); 570 EXPECT_EQ(handle2, card_consumer2.handle());
535 ASSERT_EQ(0U, card_consumer2.result().size()); 571 ASSERT_EQ(0U, card_consumer2.result().size());
536 } 572 }
537 573
538 } // namespace autofill 574 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/browser/webdata/autofill_webdata_service.cc ('k') | components/webdata/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698