blob: 89ddf2b250119e903bbd8de9100744611da9f81b [file] [log] [blame]
[email protected]fba65f7b2012-03-15 05:22:131// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7775c7d2010-06-21 17:50:212// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "net/http/http_auth_handler.h"
6
[email protected]13c8a092010-07-29 06:15:447#include "base/string_util.h"
[email protected]750b2f3c2013-06-07 18:41:058#include "base/strings/utf_string_conversions.h"
[email protected]7775c7d2010-06-21 17:50:219#include "net/base/capturing_net_log.h"
10#include "net/base/net_errors.h"
11#include "net/base/net_log_unittest.h"
12#include "net/base/test_completion_callback.h"
13#include "net/http/http_auth_handler_mock.h"
14#include "net/http/http_request_info.h"
15#include "testing/gtest/include/gtest/gtest.h"
16
17namespace net {
18
19TEST(HttpAuthHandlerTest, NetLog) {
[email protected]7775c7d2010-06-21 17:50:2120 GURL origin("http://www.example.com");
21 std::string challenge = "Mock asdf";
[email protected]f3cf9802011-10-28 18:44:5822 AuthCredentials credentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass"));
[email protected]7775c7d2010-06-21 17:50:2123 std::string auth_token;
24 HttpRequestInfo request;
25
26 for (int i = 0; i < 2; ++i) {
27 bool async = (i == 0);
28 for (int j = 0; j < 2; ++j) {
29 int rv = (j == 0) ? OK : ERR_UNEXPECTED;
30 for (int k = 0; k < 2; ++k) {
[email protected]49639fa2011-12-20 23:22:4131 TestCompletionCallback test_callback;
[email protected]7775c7d2010-06-21 17:50:2132 HttpAuth::Target target =
33 (k == 0) ? HttpAuth::AUTH_PROXY : HttpAuth::AUTH_SERVER;
34 NetLog::EventType event_type =
35 (k == 0) ? NetLog::TYPE_AUTH_PROXY : NetLog::TYPE_AUTH_SERVER;
36 HttpAuth::ChallengeTokenizer tokenizer(
37 challenge.begin(), challenge.end());
38 HttpAuthHandlerMock mock_handler;
[email protected]333bdf62012-06-08 22:57:2939 CapturingNetLog capturing_net_log;
[email protected]fba65f7b2012-03-15 05:22:1340 BoundNetLog bound_net_log(BoundNetLog::Make(&capturing_net_log,
41 net::NetLog::SOURCE_NONE));
[email protected]7775c7d2010-06-21 17:50:2142
43 mock_handler.InitFromChallenge(&tokenizer, target,
44 origin, bound_net_log);
45 mock_handler.SetGenerateExpectation(async, rv);
[email protected]f3cf9802011-10-28 18:44:5846 mock_handler.GenerateAuthToken(&credentials, &request,
[email protected]49639fa2011-12-20 23:22:4147 test_callback.callback(), &auth_token);
[email protected]7775c7d2010-06-21 17:50:2148 if (async)
49 test_callback.WaitForResult();
50
[email protected]333bdf62012-06-08 22:57:2951 CapturingNetLog::CapturedEntryList entries;
[email protected]b2fcd0e2010-12-01 15:19:4052 capturing_net_log.GetEntries(&entries);
53
54 EXPECT_EQ(2u, entries.size());
55 EXPECT_TRUE(LogContainsBeginEvent(entries, 0, event_type));
56 EXPECT_TRUE(LogContainsEndEvent(entries, 1, event_type));
[email protected]7775c7d2010-06-21 17:50:2157 }
58 }
59 }
60}
61
62} // namespace net