diff options
author | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-21 11:39:00 +0000 |
---|---|---|
committer | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-21 11:39:00 +0000 |
commit | 3fd9dae0d14e2a5ec30f738defb1811825740755 (patch) | |
tree | be0fded47fec9e5bde1d2bccf16878ba47d14ae3 /net/http/http_auth_handler_mock.h | |
parent | 1cb177b459c5c8b807aba5c83f2e6a8133c38514 (diff) | |
download | chromium_src-3fd9dae0d14e2a5ec30f738defb1811825740755.zip chromium_src-3fd9dae0d14e2a5ec30f738defb1811825740755.tar.gz chromium_src-3fd9dae0d14e2a5ec30f738defb1811825740755.tar.bz2 |
Refactor: Rename MockAuthHandler and move to a separate file.
BUG=None
TEST=net_unittests --gtest_filter="HttpNetworkTransactionTest.GenerateAuthToken"
Review URL: http://codereview.chromium.org/2823011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50344 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_auth_handler_mock.h')
-rw-r--r-- | net/http/http_auth_handler_mock.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/net/http/http_auth_handler_mock.h b/net/http/http_auth_handler_mock.h new file mode 100644 index 0000000..4a7fa22 --- /dev/null +++ b/net/http/http_auth_handler_mock.h @@ -0,0 +1,83 @@ +// Copyright (c) 2010 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 NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ +#define NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ + +#include "base/task.h" +#include "net/http/http_auth_handler.h" +#include "net/http/http_auth_handler_factory.h" + +namespace net { + +// MockAuthHandler is used in tests to reliably trigger edge cases. +class HttpAuthHandlerMock : public HttpAuthHandler { + public: + enum Resolve { + RESOLVE_INIT, + RESOLVE_SKIP, + RESOLVE_SYNC, + RESOLVE_ASYNC, + RESOLVE_TESTED, + }; + + HttpAuthHandlerMock(); + + virtual ~HttpAuthHandlerMock(); + + void SetResolveExpectation(Resolve resolve); + + virtual bool NeedsCanonicalName(); + + virtual int ResolveCanonicalName(HostResolver* host_resolver, + CompletionCallback* callback); + + void SetGenerateExpectation(bool async, int rv); + + // The Factory class simply returns the same handler each time + // CreateAuthHandler is called. + class Factory : public HttpAuthHandlerFactory { + public: + Factory() {} + virtual ~Factory() {} + + void set_mock_handler(HttpAuthHandler* handler, HttpAuth::Target target); + + virtual int CreateAuthHandler(HttpAuth::ChallengeTokenizer* challenge, + HttpAuth::Target target, + const GURL& origin, + CreateReason reason, + int nonce_count, + const BoundNetLog& net_log, + scoped_ptr<HttpAuthHandler>* handler); + + private: + scoped_ptr<HttpAuthHandler> handlers_[HttpAuth::AUTH_NUM_TARGETS]; + }; + + protected: + virtual bool Init(HttpAuth::ChallengeTokenizer* challenge); + + virtual int GenerateAuthTokenImpl(const std::wstring* username, + const std::wstring* password, + const HttpRequestInfo* request, + CompletionCallback* callback, + std::string* auth_token); + + private: + void OnResolveCanonicalName(); + + void OnGenerateAuthToken(); + + Resolve resolve_; + CompletionCallback* user_callback_; + ScopedRunnableMethodFactory<HttpAuthHandlerMock> method_factory_; + bool generate_async_; + int generate_rv_; + std::string* auth_token_; +}; + +} // namespace net + +#endif // NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ |