OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_TEST_UTIL_H__ | |
6 #define CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_TEST_UTIL_H__ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/message_loop.h" | |
10 #include "chrome/browser/webdata/web_data_service.h" | |
11 #include "chrome/browser/webdata/web_data_service_factory.h" | |
12 #include "content/public/browser/browser_thread.h" | |
13 | |
14 template <class T> | |
15 class AutofillWebDataServiceConsumer: public WebDataServiceConsumer { | |
16 public: | |
17 AutofillWebDataServiceConsumer() : handle_(0) {} | |
18 virtual ~AutofillWebDataServiceConsumer() {} | |
19 | |
20 virtual void OnWebDataServiceRequestDone(WebDataService::Handle handle, | |
21 const WDTypedResult* result) { | |
22 using content::BrowserThread; | |
23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
24 handle_ = handle; | |
25 const WDResult<T>* wrapped_result = | |
26 static_cast<const WDResult<T>*>(result); | |
27 result_ = wrapped_result->GetValue(); | |
28 | |
29 MessageLoop::current()->Quit(); | |
30 } | |
31 | |
32 WebDataService::Handle handle() { return handle_; } | |
33 T& result() { return result_; } | |
34 | |
35 private: | |
36 WebDataService::Handle handle_; | |
37 T result_; | |
38 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataServiceConsumer); | |
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( | |
59 scoped_refptr<WebDataService> fake_service, | |
60 scoped_refptr<AutofillWebDataService> fake_autofill); | |
61 | |
62 virtual ~MockWebDataServiceWrapper(); | |
63 | |
64 virtual scoped_refptr<AutofillWebDataService> GetAutofillWebData() OVERRIDE; | |
65 | |
66 virtual scoped_refptr<WebDataService> GetWebData() OVERRIDE; | |
67 | |
68 protected: | |
69 scoped_refptr<AutofillWebDataService> fake_autofill_web_data_; | |
70 scoped_refptr<WebDataService> fake_web_data_; | |
71 | |
72 private: | |
73 DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapper); | |
74 }; | |
75 | |
76 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_TEST_UTIL_H__ | |
OLD | NEW |