Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Side by Side Diff: chrome/browser/media/router/discovery/dial/dial_registry_unittest.cc

Issue 2756483007: [Device Discovery] Move files from browser/extensions/api/dial to browser/media/router/discovery/di… (Closed)
Patch Set: add deps to extension/api/DEPS Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "chrome/browser/extensions/api/dial/dial_device_data.h" 8 #include "chrome/browser/media/router/discovery/dial/dial_device_data.h"
9 #include "chrome/browser/extensions/api/dial/dial_registry.h" 9 #include "chrome/browser/media/router/discovery/dial/dial_registry.h"
10 #include "chrome/browser/extensions/api/dial/dial_service.h" 10 #include "chrome/browser/media/router/discovery/dial/dial_service.h"
11 #include "chrome/test/base/testing_profile.h" 11 #include "chrome/test/base/testing_profile.h"
12 #include "content/public/test/test_browser_thread_bundle.h" 12 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 16
17 using base::Time; 17 using base::Time;
18 using base::TimeDelta; 18 using base::TimeDelta;
19 using ::testing::A; 19 using ::testing::A;
20 using ::testing::AtLeast; 20 using ::testing::AtLeast;
21 using ::testing::Return; 21 using ::testing::Return;
22 using ::testing::InSequence; 22 using ::testing::InSequence;
23 23
24 namespace extensions { 24 namespace media_router {
25 namespace api {
26 namespace dial {
27 25
28 class MockDialObserver : public DialRegistry::Observer { 26 class MockDialObserver : public DialRegistry::Observer {
29 public: 27 public:
30 ~MockDialObserver() override {} 28 ~MockDialObserver() override {}
31 29
32 MOCK_METHOD1(OnDialDeviceEvent, 30 MOCK_METHOD1(OnDialDeviceEvent,
33 void(const DialRegistry::DeviceList& devices)); 31 void(const DialRegistry::DeviceList& devices));
34 MOCK_METHOD1(OnDialError, void(DialRegistry::DialErrorCode type)); 32 MOCK_METHOD1(OnDialError, void(DialRegistry::DialErrorCode type));
35 }; 33 };
36 34
(...skipping 16 matching lines...) Expand all
53 time_(Time::Now()) {} 51 time_(Time::Now()) {}
54 52
55 ~MockDialRegistry() override { 53 ~MockDialRegistry() override {
56 // Don't let the DialRegistry delete this. 54 // Don't let the DialRegistry delete this.
57 DialService* tmp = dial_.release(); 55 DialService* tmp = dial_.release();
58 if (tmp) 56 if (tmp)
59 CHECK_EQ(&mock_service_, tmp); 57 CHECK_EQ(&mock_service_, tmp);
60 } 58 }
61 59
62 // Returns the mock Dial service. 60 // Returns the mock Dial service.
63 MockDialService& mock_service() { 61 MockDialService& mock_service() { return mock_service_; }
64 return mock_service_;
65 }
66 62
67 void set_time(Time time) { time_ = time; } 63 void set_time(Time time) { time_ = time; }
68 64
69 protected: 65 protected:
70 base::Time Now() const override { return time_; } 66 base::Time Now() const override { return time_; }
71 67
72 std::unique_ptr<DialService> CreateDialService() override { 68 std::unique_ptr<DialService> CreateDialService() override {
73 return base::WrapUnique(&mock_service_); 69 return base::WrapUnique(&mock_service_);
74 } 70 }
75 71
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 registry_->OnDiscoveryFinished(nullptr); 217 registry_->OnDiscoveryFinished(nullptr);
222 registry_->OnListenerRemoved(); 218 registry_->OnListenerRemoved();
223 } 219 }
224 220
225 TEST_F(DialRegistryTest, TestExpiredDeviceIsRediscovered) { 221 TEST_F(DialRegistryTest, TestExpiredDeviceIsRediscovered) {
226 std::vector<Time> discovery_times; 222 std::vector<Time> discovery_times;
227 discovery_times.push_back(Time::Now()); 223 discovery_times.push_back(Time::Now());
228 discovery_times.push_back(discovery_times[0] + TimeDelta::FromSeconds(30)); 224 discovery_times.push_back(discovery_times[0] + TimeDelta::FromSeconds(30));
229 discovery_times.push_back(discovery_times[1] + TimeDelta::FromSeconds(30)); 225 discovery_times.push_back(discovery_times[1] + TimeDelta::FromSeconds(30));
230 226
231 DialDeviceData rediscovered_device("first", 227 DialDeviceData rediscovered_device("first", GURL("http://127.0.0.1/dd.xml"),
232 GURL("http://127.0.0.1/dd.xml"),
233 discovery_times[2]); 228 discovery_times[2]);
234 229
235 SetListenerExpectations(); 230 SetListenerExpectations();
236 231
237 InSequence s; 232 InSequence s;
238 EXPECT_CALL(registry_->mock_service(), Discover()); 233 EXPECT_CALL(registry_->mock_service(), Discover());
239 EXPECT_CALL(mock_observer_, OnDialDeviceEvent(empty_list_)); 234 EXPECT_CALL(mock_observer_, OnDialDeviceEvent(empty_list_));
240 EXPECT_CALL(mock_observer_, OnDialDeviceEvent(list_with_first_device_)); 235 EXPECT_CALL(mock_observer_, OnDialDeviceEvent(list_with_first_device_));
241 EXPECT_CALL(registry_->mock_service(), Discover()); 236 EXPECT_CALL(registry_->mock_service(), Discover());
242 EXPECT_CALL(mock_observer_, OnDialDeviceEvent(empty_list_)); 237 EXPECT_CALL(mock_observer_, OnDialDeviceEvent(empty_list_));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 322
328 TEST_F(DialRegistryTest, TestNetworkEventConnectionRestored) { 323 TEST_F(DialRegistryTest, TestNetworkEventConnectionRestored) {
329 DialRegistry::DeviceList expected_list3; 324 DialRegistry::DeviceList expected_list3;
330 expected_list3.push_back(second_device_); 325 expected_list3.push_back(second_device_);
331 expected_list3.push_back(third_device_); 326 expected_list3.push_back(third_device_);
332 327
333 // A disconnection should shutdown the DialService, so we expect the observer 328 // A disconnection should shutdown the DialService, so we expect the observer
334 // to be added twice. 329 // to be added twice.
335 EXPECT_CALL(registry_->mock_service(), 330 EXPECT_CALL(registry_->mock_service(),
336 AddObserver(A<DialService::Observer*>())) 331 AddObserver(A<DialService::Observer*>()))
337 .Times(2); 332 .Times(2);
338 EXPECT_CALL(registry_->mock_service(), 333 EXPECT_CALL(registry_->mock_service(),
339 RemoveObserver(A<DialService::Observer*>())) 334 RemoveObserver(A<DialService::Observer*>()))
340 .Times(2); 335 .Times(2);
341 336
342 InSequence s; 337 InSequence s;
343 EXPECT_CALL(registry_->mock_service(), Discover()); 338 EXPECT_CALL(registry_->mock_service(), Discover());
344 EXPECT_CALL(mock_observer_, OnDialDeviceEvent(empty_list_)); 339 EXPECT_CALL(mock_observer_, OnDialDeviceEvent(empty_list_));
345 EXPECT_CALL(mock_observer_, OnDialDeviceEvent(list_with_first_device_)); 340 EXPECT_CALL(mock_observer_, OnDialDeviceEvent(list_with_first_device_));
346 341
347 EXPECT_CALL(mock_observer_, 342 EXPECT_CALL(mock_observer_,
348 OnDialError(DialRegistry::DIAL_NETWORK_DISCONNECTED)); 343 OnDialError(DialRegistry::DIAL_NETWORK_DISCONNECTED));
349 EXPECT_CALL(mock_observer_, OnDialDeviceEvent(empty_list_)); 344 EXPECT_CALL(mock_observer_, OnDialDeviceEvent(empty_list_));
350 345
(...skipping 19 matching lines...) Expand all
370 365
371 registry_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); 366 registry_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET);
372 367
373 registry_->OnDiscoveryRequest(nullptr); 368 registry_->OnDiscoveryRequest(nullptr);
374 registry_->OnDeviceDiscovered(nullptr, third_device_); 369 registry_->OnDeviceDiscovered(nullptr, third_device_);
375 registry_->OnDiscoveryFinished(nullptr); 370 registry_->OnDiscoveryFinished(nullptr);
376 371
377 registry_->OnListenerRemoved(); 372 registry_->OnListenerRemoved();
378 } 373 }
379 374
380 } // namespace dial 375 } // namespace media_router
381 } // namespace api
382 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698