OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "net/http/http_auth_handler.h" | 5 #include "net/http/http_auth_handler.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
11 #include "net/http/http_auth_challenge_tokenizer.h" | 11 #include "net/http/http_auth_challenge_tokenizer.h" |
12 #include "net/http/http_auth_handler_mock.h" | 12 #include "net/http/http_auth_handler_mock.h" |
13 #include "net/http/http_request_info.h" | 13 #include "net/http/http_request_info.h" |
| 14 #include "net/log/net_log_event_type.h" |
| 15 #include "net/log/net_log_source_type.h" |
14 #include "net/log/test_net_log.h" | 16 #include "net/log/test_net_log.h" |
15 #include "net/log/test_net_log_entry.h" | 17 #include "net/log/test_net_log_entry.h" |
16 #include "net/log/test_net_log_util.h" | 18 #include "net/log/test_net_log_util.h" |
17 #include "net/ssl/ssl_info.h" | 19 #include "net/ssl/ssl_info.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
19 | 21 |
20 namespace net { | 22 namespace net { |
21 | 23 |
22 TEST(HttpAuthHandlerTest, NetLog) { | 24 TEST(HttpAuthHandlerTest, NetLog) { |
23 GURL origin("http://www.example.com"); | 25 GURL origin("http://www.example.com"); |
24 std::string challenge = "Mock asdf"; | 26 std::string challenge = "Mock asdf"; |
25 AuthCredentials credentials(base::ASCIIToUTF16("user"), | 27 AuthCredentials credentials(base::ASCIIToUTF16("user"), |
26 base::ASCIIToUTF16("pass")); | 28 base::ASCIIToUTF16("pass")); |
27 std::string auth_token; | 29 std::string auth_token; |
28 HttpRequestInfo request; | 30 HttpRequestInfo request; |
29 | 31 |
30 for (int i = 0; i < 2; ++i) { | 32 for (int i = 0; i < 2; ++i) { |
31 bool async = (i == 0); | 33 bool async = (i == 0); |
32 for (int j = 0; j < 2; ++j) { | 34 for (int j = 0; j < 2; ++j) { |
33 int rv = (j == 0) ? OK : ERR_UNEXPECTED; | 35 int rv = (j == 0) ? OK : ERR_UNEXPECTED; |
34 for (int k = 0; k < 2; ++k) { | 36 for (int k = 0; k < 2; ++k) { |
35 TestCompletionCallback test_callback; | 37 TestCompletionCallback test_callback; |
36 HttpAuth::Target target = | 38 HttpAuth::Target target = |
37 (k == 0) ? HttpAuth::AUTH_PROXY : HttpAuth::AUTH_SERVER; | 39 (k == 0) ? HttpAuth::AUTH_PROXY : HttpAuth::AUTH_SERVER; |
38 NetLog::EventType event_type = | 40 NetLogEventType event_type = (k == 0) ? NetLogEventType::AUTH_PROXY |
39 (k == 0) ? NetLog::TYPE_AUTH_PROXY : NetLog::TYPE_AUTH_SERVER; | 41 : NetLogEventType::AUTH_SERVER; |
40 HttpAuthChallengeTokenizer tokenizer( | 42 HttpAuthChallengeTokenizer tokenizer( |
41 challenge.begin(), challenge.end()); | 43 challenge.begin(), challenge.end()); |
42 HttpAuthHandlerMock mock_handler; | 44 HttpAuthHandlerMock mock_handler; |
43 TestNetLog test_net_log; | 45 TestNetLog test_net_log; |
44 BoundNetLog bound_net_log( | 46 BoundNetLog bound_net_log( |
45 BoundNetLog::Make(&test_net_log, NetLog::SOURCE_NONE)); | 47 BoundNetLog::Make(&test_net_log, NetLogSourceType::NONE)); |
46 | 48 |
47 SSLInfo empty_ssl_info; | 49 SSLInfo empty_ssl_info; |
48 mock_handler.InitFromChallenge(&tokenizer, target, empty_ssl_info, | 50 mock_handler.InitFromChallenge(&tokenizer, target, empty_ssl_info, |
49 origin, bound_net_log); | 51 origin, bound_net_log); |
50 mock_handler.SetGenerateExpectation(async, rv); | 52 mock_handler.SetGenerateExpectation(async, rv); |
51 mock_handler.GenerateAuthToken(&credentials, &request, | 53 mock_handler.GenerateAuthToken(&credentials, &request, |
52 test_callback.callback(), &auth_token); | 54 test_callback.callback(), &auth_token); |
53 if (async) | 55 if (async) |
54 test_callback.WaitForResult(); | 56 test_callback.WaitForResult(); |
55 | 57 |
56 TestNetLogEntry::List entries; | 58 TestNetLogEntry::List entries; |
57 test_net_log.GetEntries(&entries); | 59 test_net_log.GetEntries(&entries); |
58 | 60 |
59 EXPECT_EQ(2u, entries.size()); | 61 EXPECT_EQ(2u, entries.size()); |
60 EXPECT_TRUE(LogContainsBeginEvent(entries, 0, event_type)); | 62 EXPECT_TRUE(LogContainsBeginEvent(entries, 0, event_type)); |
61 EXPECT_TRUE(LogContainsEndEvent(entries, 1, event_type)); | 63 EXPECT_TRUE(LogContainsEndEvent(entries, 1, event_type)); |
62 } | 64 } |
63 } | 65 } |
64 } | 66 } |
65 } | 67 } |
66 | 68 |
67 } // namespace net | 69 } // namespace net |
OLD | NEW |