OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/public/test/browser_test_base.h" | 5 #include "content/public/test/browser_test_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/stack_trace.h" | 9 #include "base/debug/stack_trace.h" |
10 #include "base/i18n/icu_util.h" | 10 #include "base/i18n/icu_util.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 } | 78 } |
79 | 79 |
80 // In many cases it may be not obvious that a test makes a real DNS lookup. | 80 // In many cases it may be not obvious that a test makes a real DNS lookup. |
81 // We generally don't want to rely on external DNS servers for our tests, | 81 // We generally don't want to rely on external DNS servers for our tests, |
82 // so this host resolver procedure catches external queries and returns a failed | 82 // so this host resolver procedure catches external queries and returns a failed |
83 // lookup result. | 83 // lookup result. |
84 class LocalHostResolverProc : public net::HostResolverProc { | 84 class LocalHostResolverProc : public net::HostResolverProc { |
85 public: | 85 public: |
86 LocalHostResolverProc() : HostResolverProc(NULL) {} | 86 LocalHostResolverProc() : HostResolverProc(NULL) {} |
87 | 87 |
88 virtual int Resolve(const std::string& host, | 88 int Resolve(const std::string& host, |
89 net::AddressFamily address_family, | 89 net::AddressFamily address_family, |
90 net::HostResolverFlags host_resolver_flags, | 90 net::HostResolverFlags host_resolver_flags, |
91 net::AddressList* addrlist, | 91 net::AddressList* addrlist, |
92 int* os_error) override { | 92 int* os_error) override { |
93 const char* kLocalHostNames[] = {"localhost", "127.0.0.1", "::1"}; | 93 const char* kLocalHostNames[] = {"localhost", "127.0.0.1", "::1"}; |
94 bool local = false; | 94 bool local = false; |
95 | 95 |
96 if (host == net::GetHostName()) { | 96 if (host == net::GetHostName()) { |
97 local = true; | 97 local = true; |
98 } else { | 98 } else { |
99 for (size_t i = 0; i < arraysize(kLocalHostNames); i++) | 99 for (size_t i = 0; i < arraysize(kLocalHostNames); i++) |
100 if (host == kLocalHostNames[i]) { | 100 if (host == kLocalHostNames[i]) { |
101 local = true; | 101 local = true; |
102 break; | 102 break; |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 // To avoid depending on external resources and to reduce (if not preclude) | 106 // To avoid depending on external resources and to reduce (if not preclude) |
107 // network interactions from tests, we simulate failure for non-local DNS | 107 // network interactions from tests, we simulate failure for non-local DNS |
108 // queries, rather than perform them. | 108 // queries, rather than perform them. |
109 // If you really need to make an external DNS query, use | 109 // If you really need to make an external DNS query, use |
110 // net::RuleBasedHostResolverProc and its AllowDirectLookup method. | 110 // net::RuleBasedHostResolverProc and its AllowDirectLookup method. |
111 if (!local) { | 111 if (!local) { |
112 DVLOG(1) << "To avoid external dependencies, simulating failure for " | 112 DVLOG(1) << "To avoid external dependencies, simulating failure for " |
113 "external DNS lookup of " << host; | 113 "external DNS lookup of " << host; |
114 return net::ERR_NOT_IMPLEMENTED; | 114 return net::ERR_NOT_IMPLEMENTED; |
115 } | 115 } |
116 | 116 |
117 return ResolveUsingPrevious(host, address_family, host_resolver_flags, | 117 return ResolveUsingPrevious(host, address_family, host_resolver_flags, |
118 addrlist, os_error); | 118 addrlist, os_error); |
119 } | 119 } |
120 | 120 |
121 private: | 121 private: |
122 virtual ~LocalHostResolverProc() {} | 122 ~LocalHostResolverProc() override {} |
123 }; | 123 }; |
124 | 124 |
125 void TraceDisableRecordingComplete(const base::Closure& quit, | 125 void TraceDisableRecordingComplete(const base::Closure& quit, |
126 const base::FilePath& file_path) { | 126 const base::FilePath& file_path) { |
127 LOG(ERROR) << "Tracing written to: " << file_path.value(); | 127 LOG(ERROR) << "Tracing written to: " << file_path.value(); |
128 quit.Run(); | 128 quit.Run(); |
129 } | 129 } |
130 | 130 |
131 } // namespace | 131 } // namespace |
132 | 132 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 use_software_compositing_ = true; | 340 use_software_compositing_ = true; |
341 } | 341 } |
342 | 342 |
343 bool BrowserTestBase::UsingOSMesa() const { | 343 bool BrowserTestBase::UsingOSMesa() const { |
344 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 344 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
345 return cmd->GetSwitchValueASCII(switches::kUseGL) == | 345 return cmd->GetSwitchValueASCII(switches::kUseGL) == |
346 gfx::kGLImplementationOSMesaName; | 346 gfx::kGLImplementationOSMesaName; |
347 } | 347 } |
348 | 348 |
349 } // namespace content | 349 } // namespace content |
OLD | NEW |