Enables compositing support for webview.
[chromium-blink-merge.git] / net / url_request / url_request_context_builder_unittest.cc
blobbc934162e6cc56480aa155788a814f77d290ac46
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)
19 namespace net {
21 namespace {
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 {
27 public:
28 explicit LocalHttpTestServer(const FilePath& document_root)
29 : TestServer(TestServer::TYPE_HTTP,
30 ScopedCustomUrlRequestTestHttpHost::value(),
31 document_root) {}
32 LocalHttpTestServer()
33 : TestServer(TestServer::TYPE_HTTP,
34 ScopedCustomUrlRequestTestHttpHost::value(),
35 FilePath()) {}
38 class URLRequestContextBuilderTest : public PlatformTest {
39 protected:
40 URLRequestContextBuilderTest()
41 : test_server_(
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;
58 URLRequest request(
59 test_server_.GetURL("echoheader?Foo"), &delegate, context.get());
60 request.set_method("GET");
61 request.SetExtraRequestHeaderByName("Foo", "Bar", false);
62 request.Start();
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;
73 URLRequest request(
74 test_server_.GetURL("echoheader?User-Agent"), &delegate, context.get());
75 request.set_method("GET");
76 request.Start();
77 MessageLoop::current()->Run();
78 EXPECT_EQ("Bar", delegate.data_received());
81 } // namespace
83 } // namespace net