Disable view source for Developer Tools.
[chromium-blink-merge.git] / net / url_request / url_request_context_builder_unittest.cc
blobe882253773fb4928f94a029039f8baafd7d1878b
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)
20 namespace net {
22 namespace {
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 {
28 public:
29 explicit LocalHttpTestServer(const base::FilePath& document_root)
30 : SpawnedTestServer(SpawnedTestServer::TYPE_HTTP,
31 ScopedCustomUrlRequestTestHttpHost::value(),
32 document_root) {}
33 LocalHttpTestServer()
34 : SpawnedTestServer(SpawnedTestServer::TYPE_HTTP,
35 ScopedCustomUrlRequestTestHttpHost::value(),
36 base::FilePath()) {}
39 class URLRequestContextBuilderTest : public PlatformTest {
40 protected:
41 URLRequestContextBuilderTest()
42 : test_server_(
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"),
60 DEFAULT_PRIORITY,
61 &delegate,
62 context.get());
63 request.set_method("GET");
64 request.SetExtraRequestHeaderByName("Foo", "Bar", false);
65 request.Start();
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"),
77 DEFAULT_PRIORITY,
78 &delegate,
79 context.get());
80 request.set_method("GET");
81 request.Start();
82 base::MessageLoop::current()->Run();
83 EXPECT_EQ("Bar", delegate.data_received());
86 } // namespace
88 } // namespace net