OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_TEST_UTIL_H__ | 5 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_TEST_UTIL_H__ |
6 #define COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_TEST_UTIL_H__ | 6 #define COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_TEST_UTIL_H__ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "chrome/browser/webdata/token_web_data.h" | 10 #include "chrome/browser/webdata/token_web_data.h" |
11 #include "chrome/browser/webdata/web_data_service.h" | 11 #include "chrome/browser/webdata/web_data_service.h" |
12 #include "chrome/browser/webdata/web_data_service_factory.h" | 12 #include "chrome/browser/webdata/web_data_service_factory.h" |
13 #include "content/public/browser/browser_thread.h" | |
14 | |
15 template <class T> | |
16 class AutofillWebDataServiceConsumer: public WebDataServiceConsumer { | |
17 public: | |
18 AutofillWebDataServiceConsumer() : handle_(0) {} | |
19 virtual ~AutofillWebDataServiceConsumer() {} | |
20 | |
21 virtual void OnWebDataServiceRequestDone(WebDataService::Handle handle, | |
22 const WDTypedResult* result) { | |
23 using content::BrowserThread; | |
24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
25 handle_ = handle; | |
26 const WDResult<T>* wrapped_result = | |
27 static_cast<const WDResult<T>*>(result); | |
28 result_ = wrapped_result->GetValue(); | |
29 | |
30 base::MessageLoop::current()->Quit(); | |
31 } | |
32 | |
33 WebDataService::Handle handle() { return handle_; } | |
34 T& result() { return result_; } | |
35 | |
36 private: | |
37 WebDataService::Handle handle_; | |
38 T result_; | |
39 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataServiceConsumer); | |
40 }; | |
41 | 13 |
42 // Base class for mocks of WebDataService, that does nothing in | 14 // Base class for mocks of WebDataService, that does nothing in |
43 // Shutdown(). | 15 // Shutdown(). |
44 class MockWebDataServiceWrapperBase : public WebDataServiceWrapper { | 16 class MockWebDataServiceWrapperBase : public WebDataServiceWrapper { |
45 public: | 17 public: |
46 MockWebDataServiceWrapperBase(); | 18 MockWebDataServiceWrapperBase(); |
47 virtual ~MockWebDataServiceWrapperBase(); | 19 virtual ~MockWebDataServiceWrapperBase(); |
48 | 20 |
49 virtual void Shutdown() OVERRIDE; | 21 virtual void Shutdown() OVERRIDE; |
50 | 22 |
(...skipping 22 matching lines...) Expand all Loading... |
73 protected: | 45 protected: |
74 scoped_refptr<autofill::AutofillWebDataService> fake_autofill_web_data_; | 46 scoped_refptr<autofill::AutofillWebDataService> fake_autofill_web_data_; |
75 scoped_refptr<TokenWebData> fake_token_web_data_; | 47 scoped_refptr<TokenWebData> fake_token_web_data_; |
76 scoped_refptr<WebDataService> fake_web_data_; | 48 scoped_refptr<WebDataService> fake_web_data_; |
77 | 49 |
78 private: | 50 private: |
79 DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapper); | 51 DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapper); |
80 }; | 52 }; |
81 | 53 |
82 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_TEST_UTIL_H__ | 54 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_TEST_UTIL_H__ |
OLD | NEW |