| 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" | 5 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h" |
| 6 | 6 |
| 7 #include "chrome/browser/local_discovery/privet_http_impl.h" | 7 #include "chrome/browser/local_discovery/privet_http_impl.h" |
| 8 #include "chrome/browser/local_discovery/privet_notifications.h" | 8 #include "chrome/browser/local_discovery/privet_notifications.h" |
| 9 #include "net/url_request/test_url_fetcher_factory.h" | 9 #include "net/url_request/test_url_fetcher_factory.h" |
| 10 #include "net/url_request/url_request_test_util.h" | 10 #include "net/url_request/url_request_test_util.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 : public PrivetNotificationsListener::Delegate { | 34 : public PrivetNotificationsListener::Delegate { |
| 35 public: | 35 public: |
| 36 MOCK_METHOD2(PrivetNotify, void(bool multiple, bool added)); | 36 MOCK_METHOD2(PrivetNotify, void(bool multiple, bool added)); |
| 37 MOCK_METHOD0(PrivetRemoveNotification, void()); | 37 MOCK_METHOD0(PrivetRemoveNotification, void()); |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 class MockPrivetHttpFactory : public PrivetHTTPAsynchronousFactory { | 40 class MockPrivetHttpFactory : public PrivetHTTPAsynchronousFactory { |
| 41 public: | 41 public: |
| 42 class MockResolution : public PrivetHTTPResolution { | 42 class MockResolution : public PrivetHTTPResolution { |
| 43 public: | 43 public: |
| 44 MockResolution( | 44 MockResolution(const std::string& name, |
| 45 const std::string& name, | 45 net::URLRequestContextGetter* request_context) |
| 46 net::URLRequestContextGetter* request_context, | 46 : name_(name), request_context_(request_context) {} |
| 47 const ResultCallback& callback) | |
| 48 : name_(name), request_context_(request_context), callback_(callback) { | |
| 49 } | |
| 50 | 47 |
| 51 ~MockResolution() override {} | 48 ~MockResolution() override {} |
| 52 | 49 |
| 53 void Start() override { | 50 void Start(const net::HostPortPair& address, |
| 54 callback_.Run(scoped_ptr<PrivetHTTPClient>(new PrivetHTTPClientImpl( | 51 const ResultCallback& callback) override { |
| 52 callback.Run(scoped_ptr<PrivetHTTPClient>(new PrivetHTTPClientImpl( |
| 55 name_, net::HostPortPair("1.2.3.4", 8080), request_context_.get()))); | 53 name_, net::HostPortPair("1.2.3.4", 8080), request_context_.get()))); |
| 56 } | 54 } |
| 57 | 55 |
| 58 const std::string& GetName() override { return name_; } | 56 const std::string& GetName() override { return name_; } |
| 59 | 57 |
| 60 private: | 58 private: |
| 61 std::string name_; | 59 std::string name_; |
| 62 scoped_refptr<net::URLRequestContextGetter> request_context_; | 60 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 63 ResultCallback callback_; | |
| 64 }; | 61 }; |
| 65 | 62 |
| 66 explicit MockPrivetHttpFactory(net::URLRequestContextGetter* request_context) | 63 explicit MockPrivetHttpFactory(net::URLRequestContextGetter* request_context) |
| 67 : request_context_(request_context) { | 64 : request_context_(request_context) { |
| 68 } | 65 } |
| 69 | 66 |
| 70 scoped_ptr<PrivetHTTPResolution> CreatePrivetHTTP( | 67 scoped_ptr<PrivetHTTPResolution> CreatePrivetHTTP( |
| 71 const std::string& name, | 68 const std::string& name) override { |
| 72 const net::HostPortPair& address, | |
| 73 const ResultCallback& callback) override { | |
| 74 return scoped_ptr<PrivetHTTPResolution>( | 69 return scoped_ptr<PrivetHTTPResolution>( |
| 75 new MockResolution(name, request_context_.get(), callback)); | 70 new MockResolution(name, request_context_.get())); |
| 76 } | 71 } |
| 77 | 72 |
| 78 private: | 73 private: |
| 79 scoped_refptr<net::URLRequestContextGetter> request_context_; | 74 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 80 }; | 75 }; |
| 81 | 76 |
| 82 class PrivetNotificationsListenerTest : public ::testing::Test { | 77 class PrivetNotificationsListenerTest : public ::testing::Test { |
| 83 public: | 78 public: |
| 84 PrivetNotificationsListenerTest() : request_context_( | 79 PrivetNotificationsListenerTest() : request_context_( |
| 85 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current())) { | 80 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current())) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 true, | 203 true, |
| 209 kExampleDeviceName, | 204 kExampleDeviceName, |
| 210 description_); | 205 description_); |
| 211 | 206 |
| 212 SuccessfulResponseToInfo(kInfoResponseNoUptime); | 207 SuccessfulResponseToInfo(kInfoResponseNoUptime); |
| 213 } | 208 } |
| 214 | 209 |
| 215 } // namespace | 210 } // namespace |
| 216 | 211 |
| 217 } // namespace local_discovery | 212 } // namespace local_discovery |
| OLD | NEW |