| 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 "base/thread_task_runner_handle.h" | 5 #include "base/thread_task_runner_handle.h" |
| 6 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h" | 6 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h" |
| 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 15 matching lines...) Expand all Loading... |
| 26 const char kExampleDeviceID[] = "__test__id"; | 26 const char kExampleDeviceID[] = "__test__id"; |
| 27 const char kDeviceInfoURL[] = "http://1.2.3.4:8080/privet/info"; | 27 const char kDeviceInfoURL[] = "http://1.2.3.4:8080/privet/info"; |
| 28 | 28 |
| 29 const char kInfoResponseUptime20[] = "{\"uptime\": 20}"; | 29 const char kInfoResponseUptime20[] = "{\"uptime\": 20}"; |
| 30 const char kInfoResponseUptime3600[] = "{\"uptime\": 3600}"; | 30 const char kInfoResponseUptime3600[] = "{\"uptime\": 3600}"; |
| 31 const char kInfoResponseNoUptime[] = "{}"; | 31 const char kInfoResponseNoUptime[] = "{}"; |
| 32 | 32 |
| 33 class MockPrivetNotificationsListenerDeleagate | 33 class MockPrivetNotificationsListenerDeleagate |
| 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(int devices_active, 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(const std::string& name, | 44 MockResolution(const std::string& name, |
| 45 net::URLRequestContextGetter* request_context) | 45 net::URLRequestContextGetter* request_context) |
| 46 : name_(name), request_context_(request_context) {} | 46 : name_(name), request_context_(request_context) {} |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 scoped_ptr<PrivetNotificationsListener> notification_listener_; | 116 scoped_ptr<PrivetNotificationsListener> notification_listener_; |
| 117 base::MessageLoop message_loop_; | 117 base::MessageLoop message_loop_; |
| 118 scoped_refptr<net::TestURLRequestContextGetter> request_context_; | 118 scoped_refptr<net::TestURLRequestContextGetter> request_context_; |
| 119 net::TestURLFetcherFactory fetcher_factory_; | 119 net::TestURLFetcherFactory fetcher_factory_; |
| 120 DeviceDescription description_; | 120 DeviceDescription description_; |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 TEST_F(PrivetNotificationsListenerTest, DisappearReappearTest) { | 123 TEST_F(PrivetNotificationsListenerTest, DisappearReappearTest) { |
| 124 | 124 |
| 125 EXPECT_CALL(mock_delegate_, PrivetNotify( | 125 EXPECT_CALL(mock_delegate_, PrivetNotify( |
| 126 false, | 126 1, |
| 127 true)); | 127 true)); |
| 128 | 128 |
| 129 notification_listener_->DeviceChanged( | 129 notification_listener_->DeviceChanged( |
| 130 true, | 130 true, |
| 131 kExampleDeviceName, | 131 kExampleDeviceName, |
| 132 description_); | 132 description_); |
| 133 | 133 |
| 134 SuccessfulResponseToInfo(kInfoResponseUptime20); | 134 SuccessfulResponseToInfo(kInfoResponseUptime20); |
| 135 | 135 |
| 136 EXPECT_CALL(mock_delegate_, PrivetRemoveNotification()); | 136 EXPECT_CALL(mock_delegate_, PrivetRemoveNotification()); |
| 137 | 137 |
| 138 notification_listener_->DeviceRemoved( | 138 notification_listener_->DeviceRemoved( |
| 139 kExampleDeviceName); | 139 kExampleDeviceName); |
| 140 | 140 |
| 141 notification_listener_->DeviceChanged( | 141 notification_listener_->DeviceChanged( |
| 142 true, | 142 true, |
| 143 kExampleDeviceName, | 143 kExampleDeviceName, |
| 144 description_); | 144 description_); |
| 145 | 145 |
| 146 description_.id = kExampleDeviceID; | 146 description_.id = kExampleDeviceID; |
| 147 | 147 |
| 148 notification_listener_->DeviceChanged( | 148 notification_listener_->DeviceChanged( |
| 149 true, | 149 true, |
| 150 kExampleDeviceName, | 150 kExampleDeviceName, |
| 151 description_); | 151 description_); |
| 152 } | 152 } |
| 153 | 153 |
| 154 TEST_F(PrivetNotificationsListenerTest, RegisterTest) { | 154 TEST_F(PrivetNotificationsListenerTest, RegisterTest) { |
| 155 EXPECT_CALL(mock_delegate_, PrivetNotify( | 155 EXPECT_CALL(mock_delegate_, PrivetNotify( |
| 156 false, | 156 1, |
| 157 true)); | 157 true)); |
| 158 | 158 |
| 159 notification_listener_->DeviceChanged( | 159 notification_listener_->DeviceChanged( |
| 160 true, | 160 true, |
| 161 kExampleDeviceName, | 161 kExampleDeviceName, |
| 162 description_); | 162 description_); |
| 163 | 163 |
| 164 SuccessfulResponseToInfo(kInfoResponseUptime20); | 164 SuccessfulResponseToInfo(kInfoResponseUptime20); |
| 165 | 165 |
| 166 EXPECT_CALL(mock_delegate_, PrivetRemoveNotification()); | 166 EXPECT_CALL(mock_delegate_, PrivetRemoveNotification()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 true, | 208 true, |
| 209 kExampleDeviceName, | 209 kExampleDeviceName, |
| 210 description_); | 210 description_); |
| 211 | 211 |
| 212 SuccessfulResponseToInfo(kInfoResponseNoUptime); | 212 SuccessfulResponseToInfo(kInfoResponseNoUptime); |
| 213 } | 213 } |
| 214 | 214 |
| 215 } // namespace | 215 } // namespace |
| 216 | 216 |
| 217 } // namespace local_discovery | 217 } // namespace local_discovery |
| OLD | NEW |