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
3 // found in the LICENSE file.
5 #include "net/url_request/url_request_context_builder.h"
7 #include "build/build_config.h"
8 #include "net/test/test_server.h"
9 #include "net/url_request/url_request.h"
10 #include "net/url_request/url_request_test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/platform_test.h"
14 #if defined(OS_LINUX) || defined(OS_ANDROID)
15 #include "net/proxy/proxy_config.h"
16 #include "net/proxy/proxy_config_service_fixed.h"
17 #endif // defined(OS_LINUX) || defined(OS_ANDROID)
23 // A subclass of TestServer that uses a statically-configured hostname. This is
24 // to work around mysterious failures in chrome_frame_net_tests. See:
25 // http://crbug.com/114369
26 class LocalHttpTestServer
: public TestServer
{
28 explicit LocalHttpTestServer(const FilePath
& document_root
)
29 : TestServer(TestServer::TYPE_HTTP
,
30 ScopedCustomUrlRequestTestHttpHost::value(),
33 : TestServer(TestServer::TYPE_HTTP
,
34 ScopedCustomUrlRequestTestHttpHost::value(),
38 class URLRequestContextBuilderTest
: public PlatformTest
{
40 URLRequestContextBuilderTest()
42 FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))) {
43 #if defined(OS_LINUX) || defined(OS_ANDROID)
44 builder_
.set_proxy_config_service(
45 new ProxyConfigServiceFixed(ProxyConfig::CreateDirect()));
46 #endif // defined(OS_LINUX) || defined(OS_ANDROID)
49 LocalHttpTestServer test_server_
;
50 URLRequestContextBuilder builder_
;
53 TEST_F(URLRequestContextBuilderTest
, DefaultSettings
) {
54 ASSERT_TRUE(test_server_
.Start());
56 scoped_ptr
<URLRequestContext
> context(builder_
.Build());
57 TestDelegate delegate
;
59 test_server_
.GetURL("echoheader?Foo"), &delegate
, context
.get());
60 request
.set_method("GET");
61 request
.SetExtraRequestHeaderByName("Foo", "Bar", false);
63 MessageLoop::current()->Run();
64 EXPECT_EQ("Bar", delegate
.data_received());
67 TEST_F(URLRequestContextBuilderTest
, UserAgent
) {
68 ASSERT_TRUE(test_server_
.Start());
70 builder_
.set_user_agent("Bar");
71 scoped_ptr
<URLRequestContext
> context(builder_
.Build());
72 TestDelegate delegate
;
74 test_server_
.GetURL("echoheader?User-Agent"), &delegate
, context
.get());
75 request
.set_method("GET");
77 MessageLoop::current()->Run();
78 EXPECT_EQ("Bar", delegate
.data_received());