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 CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_TEST_UTIL_H__ | 5 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_TEST_UTIL_H__ |
6 #define CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_TEST_UTIL_H__ | 6 #define CHROME_BROWSER_WEBDATA_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/web_data_service.h" | 10 #include "chrome/browser/webdata/web_data_service.h" |
| 11 #include "chrome/browser/webdata/web_data_service_factory.h" |
11 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
12 | 13 |
13 template <class T> | 14 template <class T> |
14 class AutofillWebDataServiceConsumer: public WebDataServiceConsumer { | 15 class AutofillWebDataServiceConsumer: public WebDataServiceConsumer { |
15 public: | 16 public: |
16 AutofillWebDataServiceConsumer() : handle_(0) {} | 17 AutofillWebDataServiceConsumer() : handle_(0) {} |
17 virtual ~AutofillWebDataServiceConsumer() {} | 18 virtual ~AutofillWebDataServiceConsumer() {} |
18 | 19 |
19 virtual void OnWebDataServiceRequestDone(WebDataService::Handle handle, | 20 virtual void OnWebDataServiceRequestDone(WebDataService::Handle handle, |
20 const WDTypedResult* result) { | 21 const WDTypedResult* result) { |
21 using content::BrowserThread; | 22 using content::BrowserThread; |
22 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
23 handle_ = handle; | 24 handle_ = handle; |
24 const WDResult<T>* wrapped_result = | 25 const WDResult<T>* wrapped_result = |
25 static_cast<const WDResult<T>*>(result); | 26 static_cast<const WDResult<T>*>(result); |
26 result_ = wrapped_result->GetValue(); | 27 result_ = wrapped_result->GetValue(); |
27 | 28 |
28 MessageLoop::current()->Quit(); | 29 MessageLoop::current()->Quit(); |
29 } | 30 } |
30 | 31 |
31 WebDataService::Handle handle() { return handle_; } | 32 WebDataService::Handle handle() { return handle_; } |
32 T& result() { return result_; } | 33 T& result() { return result_; } |
33 | 34 |
34 private: | 35 private: |
35 WebDataService::Handle handle_; | 36 WebDataService::Handle handle_; |
36 T result_; | 37 T result_; |
37 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataServiceConsumer); | 38 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataServiceConsumer); |
38 }; | 39 }; |
39 | 40 |
| 41 // Base class for mocks of WebDataService, that does nothing in |
| 42 // Shutdown(). |
| 43 class MockWebDataServiceWrapperBase : public WebDataServiceWrapper { |
| 44 public: |
| 45 MockWebDataServiceWrapperBase(); |
| 46 virtual ~MockWebDataServiceWrapperBase(); |
| 47 |
| 48 virtual void Shutdown() OVERRIDE; |
| 49 |
| 50 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapperBase); |
| 52 }; |
| 53 |
| 54 // Pass your fake WebDataService in the constructor and this will |
| 55 // serve it up via GetWebData(). |
| 56 class MockWebDataServiceWrapper : public MockWebDataServiceWrapperBase { |
| 57 public: |
| 58 MockWebDataServiceWrapper(scoped_refptr<WebDataService> fake_service); |
| 59 virtual ~MockWebDataServiceWrapper(); |
| 60 |
| 61 virtual scoped_refptr<WebDataService> GetWebData() OVERRIDE; |
| 62 |
| 63 protected: |
| 64 scoped_refptr<WebDataService> fake_web_data_service_; |
| 65 |
| 66 private: |
| 67 DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapper); |
| 68 }; |
| 69 |
40 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_TEST_UTIL_H__ | 70 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_TEST_UTIL_H__ |
OLD | NEW |