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 "net/proxy/proxy_service.h" | 5 #include "net/proxy/proxy_service.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 #include "net/base/net_errors.h" |
14 #include "net/base/net_log.h" | 15 #include "net/base/net_log.h" |
15 #include "net/base/net_log_unittest.h" | 16 #include "net/base/net_log_unittest.h" |
16 #include "net/base/net_errors.h" | |
17 #include "net/base/test_completion_callback.h" | 17 #include "net/base/test_completion_callback.h" |
18 #include "net/proxy/mock_proxy_resolver.h" | 18 #include "net/proxy/mock_proxy_resolver.h" |
19 #include "net/proxy/proxy_config_service.h" | 19 #include "net/proxy/proxy_config_service.h" |
20 #include "net/proxy/proxy_resolver.h" | 20 #include "net/proxy/proxy_resolver.h" |
21 #include "net/proxy/proxy_script_fetcher.h" | 21 #include "net/proxy/proxy_script_fetcher.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
24 // TODO(eroman): Write a test which exercises | 24 // TODO(eroman): Write a test which exercises |
25 // ProxyService::SuspendAllPendingRequests(). | 25 // ProxyService::SuspendAllPendingRequests(). |
26 namespace net { | 26 namespace net { |
27 namespace { | 27 namespace { |
28 | 28 |
29 class MockProxyConfigService: public ProxyConfigService { | 29 class MockProxyConfigService: public ProxyConfigService { |
30 public: | 30 public: |
31 explicit MockProxyConfigService(const ProxyConfig& config) | 31 explicit MockProxyConfigService(const ProxyConfig& config) |
32 : has_config_(true), config_(config) { | 32 : availability_(CONFIG_VALID), |
| 33 config_(config) { |
33 } | 34 } |
34 | 35 |
35 explicit MockProxyConfigService(const std::string& pac_url) | 36 explicit MockProxyConfigService(const std::string& pac_url) |
36 : has_config_(true), | 37 : availability_(CONFIG_VALID), |
37 config_(ProxyConfig::CreateFromCustomPacURL(GURL(pac_url))) { | 38 config_(ProxyConfig::CreateFromCustomPacURL(GURL(pac_url))) { |
38 } | 39 } |
39 | 40 |
40 virtual void AddObserver(Observer* observer) { | 41 virtual void AddObserver(Observer* observer) { |
41 observers_.AddObserver(observer); | 42 observers_.AddObserver(observer); |
42 } | 43 } |
43 | 44 |
44 virtual void RemoveObserver(Observer* observer) { | 45 virtual void RemoveObserver(Observer* observer) { |
45 observers_.RemoveObserver(observer); | 46 observers_.RemoveObserver(observer); |
46 } | 47 } |
47 | 48 |
48 virtual bool GetLatestProxyConfig(ProxyConfig* results) { | 49 virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* results) { |
49 if (has_config_) { | 50 if (availability_ == CONFIG_VALID) |
50 *results = config_; | 51 *results = config_; |
51 return true; | 52 return availability_; |
52 } | |
53 return false; | |
54 } | 53 } |
55 | 54 |
56 void SetConfig(const ProxyConfig& config) { | 55 void SetConfig(const ProxyConfig& config) { |
57 has_config_ = true; | 56 availability_ = CONFIG_VALID; |
58 config_ = config; | 57 config_ = config; |
59 FOR_EACH_OBSERVER(Observer, observers_, OnProxyConfigChanged(config)); | 58 FOR_EACH_OBSERVER(Observer, observers_, |
| 59 OnProxyConfigChanged(config_, availability_)); |
60 } | 60 } |
61 | 61 |
62 private: | 62 private: |
63 bool has_config_; | 63 ConfigAvailability availability_; |
64 ProxyConfig config_; | 64 ProxyConfig config_; |
65 ObserverList<Observer, true> observers_; | 65 ObserverList<Observer, true> observers_; |
66 }; | 66 }; |
67 | 67 |
68 } // namespace | 68 } // namespace |
69 | 69 |
70 // A mock ProxyScriptFetcher. No result will be returned to the fetch client | 70 // A mock ProxyScriptFetcher. No result will be returned to the fetch client |
71 // until we call NotifyFetchCompletion() to set the results. | 71 // until we call NotifyFetchCompletion() to set the results. |
72 class MockProxyScriptFetcher : public ProxyScriptFetcher { | 72 class MockProxyScriptFetcher : public ProxyScriptFetcher { |
73 public: | 73 public: |
(...skipping 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 log.GetEntries(&entries); | 1694 log.GetEntries(&entries); |
1695 | 1695 |
1696 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, | 1696 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, |
1697 NetLog::TYPE_PROXY_CONFIG_CHANGED)); | 1697 NetLog::TYPE_PROXY_CONFIG_CHANGED)); |
1698 ASSERT_EQ(13u, entries.size()); | 1698 ASSERT_EQ(13u, entries.size()); |
1699 for (size_t i = 1; i < entries.size(); ++i) | 1699 for (size_t i = 1; i < entries.size(); ++i) |
1700 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); | 1700 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); |
1701 } | 1701 } |
1702 | 1702 |
1703 } // namespace net | 1703 } // namespace net |
OLD | NEW |