diff options
author | caitkp@chromium.org <caitkp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-05 18:41:22 +0000 |
---|---|---|
committer | caitkp@chromium.org <caitkp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-05 18:41:22 +0000 |
commit | c8e56bd49ed2a92cc51164aa2f06c5d7e1ed0a60 (patch) | |
tree | c6d621de3b1164c0752d76e7cc4f8b1c39c55bd4 /components/webdata/common/web_data_service_test_util.h | |
parent | b1babd99ec7a05a76f0b93f6fa17519b661a07b5 (diff) | |
download | chromium_src-c8e56bd49ed2a92cc51164aa2f06c5d7e1ed0a60.zip chromium_src-c8e56bd49ed2a92cc51164aa2f06c5d7e1ed0a60.tar.gz chromium_src-c8e56bd49ed2a92cc51164aa2f06c5d7e1ed0a60.tar.bz2 |
Move WebData component unittests to //components/webdata.
TBR=ben@chromium.org
BUG=181277
Review URL: https://chromiumcodereview.appspot.com/13650007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192608 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/webdata/common/web_data_service_test_util.h')
-rw-r--r-- | components/webdata/common/web_data_service_test_util.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/components/webdata/common/web_data_service_test_util.h b/components/webdata/common/web_data_service_test_util.h new file mode 100644 index 0000000..e037a15 --- /dev/null +++ b/components/webdata/common/web_data_service_test_util.h @@ -0,0 +1,76 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_TEST_UTIL_H__ +#define COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_TEST_UTIL_H__ + +#include "base/basictypes.h" +#include "base/message_loop.h" +#include "chrome/browser/webdata/web_data_service.h" +#include "chrome/browser/webdata/web_data_service_factory.h" +#include "content/public/browser/browser_thread.h" + +template <class T> +class AutofillWebDataServiceConsumer: public WebDataServiceConsumer { + public: + AutofillWebDataServiceConsumer() : handle_(0) {} + virtual ~AutofillWebDataServiceConsumer() {} + + virtual void OnWebDataServiceRequestDone(WebDataService::Handle handle, + const WDTypedResult* result) { + using content::BrowserThread; + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + handle_ = handle; + const WDResult<T>* wrapped_result = + static_cast<const WDResult<T>*>(result); + result_ = wrapped_result->GetValue(); + + MessageLoop::current()->Quit(); + } + + WebDataService::Handle handle() { return handle_; } + T& result() { return result_; } + + private: + WebDataService::Handle handle_; + T result_; + DISALLOW_COPY_AND_ASSIGN(AutofillWebDataServiceConsumer); +}; + +// Base class for mocks of WebDataService, that does nothing in +// Shutdown(). +class MockWebDataServiceWrapperBase : public WebDataServiceWrapper { + public: + MockWebDataServiceWrapperBase(); + virtual ~MockWebDataServiceWrapperBase(); + + virtual void Shutdown() OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapperBase); +}; + +// Pass your fake WebDataService in the constructor and this will +// serve it up via GetWebData(). +class MockWebDataServiceWrapper : public MockWebDataServiceWrapperBase { + public: + MockWebDataServiceWrapper( + scoped_refptr<WebDataService> fake_service, + scoped_refptr<AutofillWebDataService> fake_autofill); + + virtual ~MockWebDataServiceWrapper(); + + virtual scoped_refptr<AutofillWebDataService> GetAutofillWebData() OVERRIDE; + + virtual scoped_refptr<WebDataService> GetWebData() OVERRIDE; + + protected: + scoped_refptr<AutofillWebDataService> fake_autofill_web_data_; + scoped_refptr<WebDataService> fake_web_data_; + + private: + DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapper); +}; + +#endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_TEST_UTIL_H__ |