| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // 1) Resolution + HTTPS takes full 4 seconds and fails (but resolution | 26 // 1) Resolution + HTTPS takes full 4 seconds and fails (but resolution |
| 27 // succeeds). | 27 // succeeds). |
| 28 // 2) SOCKS5 takes the full 2 seconds. | 28 // 2) SOCKS5 takes the full 2 seconds. |
| 29 // Socket creation time seems unbounded, and has been observed to take >1 second | 29 // Socket creation time seems unbounded, and has been observed to take >1 second |
| 30 // on a linux machine under load. As such, we allow for 10 seconds for timeout, | 30 // on a linux machine under load. As such, we allow for 10 seconds for timeout, |
| 31 // though could still end up with some flakiness. | 31 // though could still end up with some flakiness. |
| 32 static const int kTimeoutMs = 10000; | 32 static const int kTimeoutMs = 10000; |
| 33 | 33 |
| 34 class AutoDetectProxyTest : public testing::Test, public sigslot::has_slots<> { | 34 class AutoDetectProxyTest : public testing::Test, public sigslot::has_slots<> { |
| 35 public: | 35 public: |
| 36 AutoDetectProxyTest() : auto_detect_proxy_(NULL), done_(false) {} | 36 AutoDetectProxyTest() : auto_detect_proxy_(nullptr), done_(false) {} |
| 37 | 37 |
| 38 protected: | 38 protected: |
| 39 bool Create(const std::string& user_agent, | 39 bool Create(const std::string& user_agent, |
| 40 const std::string& path, | 40 const std::string& path, |
| 41 const std::string& host, | 41 const std::string& host, |
| 42 uint16_t port, | 42 uint16_t port, |
| 43 bool secure, | 43 bool secure, |
| 44 bool startnow) { | 44 bool startnow) { |
| 45 auto_detect_proxy_ = new AutoDetectProxy(user_agent); | 45 auto_detect_proxy_ = new AutoDetectProxy(user_agent); |
| 46 EXPECT_TRUE(auto_detect_proxy_ != NULL); | 46 EXPECT_TRUE(auto_detect_proxy_ != nullptr); |
| 47 if (!auto_detect_proxy_) { | 47 if (!auto_detect_proxy_) { |
| 48 return false; | 48 return false; |
| 49 } | 49 } |
| 50 Url<char> host_url(path, host, port); | 50 Url<char> host_url(path, host, port); |
| 51 host_url.set_secure(secure); | 51 host_url.set_secure(secure); |
| 52 auto_detect_proxy_->set_server_url(host_url.url()); | 52 auto_detect_proxy_->set_server_url(host_url.url()); |
| 53 auto_detect_proxy_->SignalWorkDone.connect( | 53 auto_detect_proxy_->SignalWorkDone.connect( |
| 54 this, | 54 this, |
| 55 &AutoDetectProxyTest::OnWorkDone); | 55 &AutoDetectProxyTest::OnWorkDone); |
| 56 if (startnow) { | 56 if (startnow) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 83 SetProxy(proxy); | 83 SetProxy(proxy); |
| 84 Start(); | 84 Start(); |
| 85 ASSERT_TRUE(Run(kTimeoutMs)); | 85 ASSERT_TRUE(Run(kTimeoutMs)); |
| 86 } | 86 } |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 void OnWorkDone(rtc::SignalThread *thread) { | 89 void OnWorkDone(rtc::SignalThread *thread) { |
| 90 AutoDetectProxy *auto_detect_proxy = | 90 AutoDetectProxy *auto_detect_proxy = |
| 91 static_cast<rtc::AutoDetectProxy *>(thread); | 91 static_cast<rtc::AutoDetectProxy *>(thread); |
| 92 EXPECT_TRUE(auto_detect_proxy == auto_detect_proxy_); | 92 EXPECT_TRUE(auto_detect_proxy == auto_detect_proxy_); |
| 93 auto_detect_proxy_ = NULL; | 93 auto_detect_proxy_ = nullptr; |
| 94 auto_detect_proxy->Release(); | 94 auto_detect_proxy->Release(); |
| 95 done_ = true; | 95 done_ = true; |
| 96 } | 96 } |
| 97 | 97 |
| 98 AutoDetectProxy *auto_detect_proxy_; | 98 AutoDetectProxy *auto_detect_proxy_; |
| 99 bool done_; | 99 bool done_; |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 TEST_F(AutoDetectProxyTest, TestDetectUnresolvedProxy) { | 102 TEST_F(AutoDetectProxyTest, TestDetectUnresolvedProxy) { |
| 103 TestCopesWithProxy(rtc::SocketAddress("localhost", 9999)); | 103 TestCopesWithProxy(rtc::SocketAddress("localhost", 9999)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 122 ASSERT_TRUE(Create(kUserAgent, | 122 ASSERT_TRUE(Create(kUserAgent, |
| 123 kPath, | 123 kPath, |
| 124 kHost, | 124 kHost, |
| 125 kPort, | 125 kPort, |
| 126 kSecure, | 126 kSecure, |
| 127 true)); | 127 true)); |
| 128 ASSERT_TRUE(Run(kTimeoutMs)); | 128 ASSERT_TRUE(Run(kTimeoutMs)); |
| 129 } | 129 } |
| 130 | 130 |
| 131 } // namespace rtc | 131 } // namespace rtc |
| OLD | NEW |