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/base/request_priority.h"
9 #include "net/test/spawned_test_server/spawned_test_server.h"
10 #include "net/url_request/url_request.h"
11 #include "net/url_request/url_request_test_util.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/platform_test.h"
15 #if defined(OS_LINUX) || defined(OS_ANDROID)
16 #include "net/proxy/proxy_config.h"
17 #include "net/proxy/proxy_config_service_fixed.h"
18 #endif // defined(OS_LINUX) || defined(OS_ANDROID)
24 // A subclass of SpawnedTestServer that uses a statically-configured hostname.
25 // This is to work around mysterious failures in chrome_frame_net_tests. See:
26 // http://crbug.com/114369
27 class LocalHttpTestServer
: public SpawnedTestServer
{
29 explicit LocalHttpTestServer(const base::FilePath
& document_root
)
30 : SpawnedTestServer(SpawnedTestServer::TYPE_HTTP
,
31 ScopedCustomUrlRequestTestHttpHost::value(),
34 : SpawnedTestServer(SpawnedTestServer::TYPE_HTTP
,
35 ScopedCustomUrlRequestTestHttpHost::value(),
39 class URLRequestContextBuilderTest
: public PlatformTest
{
41 URLRequestContextBuilderTest()
43 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))) {
44 #if defined(OS_LINUX) || defined(OS_ANDROID)
45 builder_
.set_proxy_config_service(
46 new ProxyConfigServiceFixed(ProxyConfig::CreateDirect()));
47 #endif // defined(OS_LINUX) || defined(OS_ANDROID)
50 LocalHttpTestServer test_server_
;
51 URLRequestContextBuilder builder_
;
54 TEST_F(URLRequestContextBuilderTest
, DefaultSettings
) {
55 ASSERT_TRUE(test_server_
.Start());
57 scoped_ptr
<URLRequestContext
> context(builder_
.Build());
58 TestDelegate delegate
;
59 URLRequest
request(test_server_
.GetURL("echoheader?Foo"),
63 request
.set_method("GET");
64 request
.SetExtraRequestHeaderByName("Foo", "Bar", false);
66 base::MessageLoop::current()->Run();
67 EXPECT_EQ("Bar", delegate
.data_received());
70 TEST_F(URLRequestContextBuilderTest
, UserAgent
) {
71 ASSERT_TRUE(test_server_
.Start());
73 builder_
.set_user_agent("Bar");
74 scoped_ptr
<URLRequestContext
> context(builder_
.Build());
75 TestDelegate delegate
;
76 URLRequest
request(test_server_
.GetURL("echoheader?User-Agent"),
80 request
.set_method("GET");
82 base::MessageLoop::current()->Run();
83 EXPECT_EQ("Bar", delegate
.data_received());