OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/local_discovery/privet_http_asynchronous_factory.h" |
| 6 |
5 #include "chrome/browser/local_discovery/privet_notifications.h" | 7 #include "chrome/browser/local_discovery/privet_notifications.h" |
6 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
8 | 10 |
9 using testing::StrictMock; | 11 using testing::StrictMock; |
10 | 12 |
11 using ::testing::_; | 13 using ::testing::_; |
12 using ::testing::SaveArg; | 14 using ::testing::SaveArg; |
13 | 15 |
14 namespace local_discovery { | 16 namespace local_discovery { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 return NULL; | 93 return NULL; |
92 } | 94 } |
93 | 95 |
94 private: | 96 private: |
95 MockPrivetInfoOperation::DelegateForTests* delegate_for_tests_; | 97 MockPrivetInfoOperation::DelegateForTests* delegate_for_tests_; |
96 std::string name_; | 98 std::string name_; |
97 }; | 99 }; |
98 | 100 |
99 class MockPrivetHttpFactory : public PrivetHTTPAsynchronousFactory { | 101 class MockPrivetHttpFactory : public PrivetHTTPAsynchronousFactory { |
100 public: | 102 public: |
101 class MockResolution : public Resolution { | 103 class MockResolution : public PrivetHTTPResolution { |
102 public: | 104 public: |
103 MockResolution( | 105 MockResolution( |
104 const std::string& name, | 106 const std::string& name, |
105 MockPrivetInfoOperation::DelegateForTests* delegate_for_tests, | 107 MockPrivetInfoOperation::DelegateForTests* delegate_for_tests, |
106 const ResultCallback& callback) | 108 const ResultCallback& callback) |
107 : name_(name), delegate_for_tests_(delegate_for_tests), | 109 : name_(name), delegate_for_tests_(delegate_for_tests), |
108 callback_(callback) { | 110 callback_(callback) { |
109 } | 111 } |
110 | 112 |
111 virtual ~MockResolution() { | 113 virtual ~MockResolution() { |
112 } | 114 } |
113 | 115 |
114 virtual void Start() OVERRIDE { | 116 virtual void Start() OVERRIDE { |
115 callback_.Run(scoped_ptr<PrivetHTTPClient>( | 117 callback_.Run(scoped_ptr<PrivetHTTPClient>( |
116 new MockPrivetHTTPClient(delegate_for_tests_, name_))); | 118 new MockPrivetHTTPClient(delegate_for_tests_, name_))); |
117 } | 119 } |
118 | 120 |
119 private: | 121 private: |
120 std::string name_; | 122 std::string name_; |
121 MockPrivetInfoOperation::DelegateForTests* delegate_for_tests_; | 123 MockPrivetInfoOperation::DelegateForTests* delegate_for_tests_; |
122 ResultCallback callback_; | 124 ResultCallback callback_; |
123 }; | 125 }; |
124 | 126 |
125 MockPrivetHttpFactory( | 127 MockPrivetHttpFactory( |
126 MockPrivetInfoOperation::DelegateForTests* delegate_for_tests) | 128 MockPrivetInfoOperation::DelegateForTests* delegate_for_tests) |
127 : delegate_for_tests_(delegate_for_tests) { | 129 : delegate_for_tests_(delegate_for_tests) { |
128 } | 130 } |
129 | 131 |
130 virtual scoped_ptr<Resolution> CreatePrivetHTTP( | 132 virtual scoped_ptr<PrivetHTTPResolution> CreatePrivetHTTP( |
131 const std::string& name, | 133 const std::string& name, |
132 const net::HostPortPair& address, | 134 const net::HostPortPair& address, |
133 const ResultCallback& callback) OVERRIDE { | 135 const ResultCallback& callback) OVERRIDE { |
134 return scoped_ptr<Resolution>( | 136 return scoped_ptr<PrivetHTTPResolution>( |
135 new MockResolution(name, delegate_for_tests_, callback)); | 137 new MockResolution(name, delegate_for_tests_, callback)); |
136 } | 138 } |
137 | 139 |
138 private: | 140 private: |
139 MockPrivetInfoOperation::DelegateForTests* delegate_for_tests_; | 141 MockPrivetInfoOperation::DelegateForTests* delegate_for_tests_; |
140 }; | 142 }; |
141 | 143 |
142 class MockDelegateForTests : public MockPrivetInfoOperation::DelegateForTests { | 144 class MockDelegateForTests : public MockPrivetInfoOperation::DelegateForTests { |
143 public: | 145 public: |
144 MOCK_METHOD1(InfoOperationStarted, void(MockPrivetInfoOperation* operation)); | 146 MOCK_METHOD1(InfoOperationStarted, void(MockPrivetInfoOperation* operation)); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 base::DictionaryValue value; | 290 base::DictionaryValue value; |
289 value.SetString("error", "internal_error"); | 291 value.SetString("error", "internal_error"); |
290 | 292 |
291 info_operation_->delegate()->OnPrivetInfoDone(info_operation_, | 293 info_operation_->delegate()->OnPrivetInfoDone(info_operation_, |
292 200, &value); | 294 200, &value); |
293 } | 295 } |
294 | 296 |
295 } // namespace | 297 } // namespace |
296 | 298 |
297 } // namespace local_discovery | 299 } // namespace local_discovery |
OLD | NEW |