diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-23 16:52:20 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-23 16:52:20 +0000 |
commit | fe2bc6a1b75b08a866f6c9ee33272eee72dfdc25 (patch) | |
tree | e12b53330014fbd6ab0aab857d373c2b7e65a1c6 /net/http/http_network_transaction_unittest.cc | |
parent | 16868d3c01d84271ec55efde52b2ed82c430a454 (diff) | |
download | chromium_src-fe2bc6a1b75b08a866f6c9ee33272eee72dfdc25.zip chromium_src-fe2bc6a1b75b08a866f6c9ee33272eee72dfdc25.tar.gz chromium_src-fe2bc6a1b75b08a866f6c9ee33272eee72dfdc25.tar.bz2 |
Make GetHostNameProc return a std::string.
Add the ScopedProcSetter helper class so that unit tests
restore the original GenerateRandom and GetHostName
functions on completion.
Merge NTLMAuthModule into HttpAuthHandlerNTLM. The data
members domain_, username_, and password_ are moved. The
Init method is inlined at its only call site. The
GetNextToken method is moved.
Make generate_random_proc_ and get_host_name_proc_ static
members of the HttpAuthHandlerNTLM class.
R=eroman
BUG=6567,6824
Review URL: http://codereview.chromium.org/43113
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12290 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_network_transaction_unittest.cc')
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index 340dfe4..20e845e 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -302,7 +302,7 @@ void FillLargeHeadersString(std::string* str, int size) { // Alternative functions that eliminate randomness and dependency on the local // host name so that the generated NTLM messages are reproducible. -void MyGenerateRandom1(uint8* output, size_t n) { +void MockGenerateRandom1(uint8* output, size_t n) { static const uint8 bytes[] = { 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 }; @@ -313,7 +313,7 @@ void MyGenerateRandom1(uint8* output, size_t n) { } } -void MyGenerateRandom2(uint8* output, size_t n) { +void MockGenerateRandom2(uint8* output, size_t n) { static const uint8 bytes[] = { 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f @@ -325,13 +325,8 @@ void MyGenerateRandom2(uint8* output, size_t n) { } } -void MyGetHostName(char* name, size_t namelen) { - static const char hostname[] = "WTC-WIN7"; - if (namelen >= arraysize(hostname)) { - memcpy(name, hostname, arraysize(hostname)); - } else { - name[0] = '\0'; - } +std::string MockGetHostName() { + return "WTC-WIN7"; } //----------------------------------------------------------------------------- @@ -1580,8 +1575,8 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { // Enter the correct password and authenticate successfully. TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { - net::HttpAuthHandlerNTLM::SetGenerateRandomProc(MyGenerateRandom1); - net::HttpAuthHandlerNTLM::SetHostNameProc(MyGetHostName); + net::HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, + MockGetHostName); scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( @@ -1702,8 +1697,8 @@ TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { // Enter a wrong password, and then the correct one. TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { - net::HttpAuthHandlerNTLM::SetGenerateRandomProc(MyGenerateRandom2); - net::HttpAuthHandlerNTLM::SetHostNameProc(MyGetHostName); + net::HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, + MockGetHostName); scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( |