Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <memory> | |
| 6 | |
| 7 #include "base/test/mock_callback.h" | |
| 8 #include "chrome/browser/media/android/router/media_router_android.h" | |
| 9 #include "chrome/browser/media/android/router/media_router_android_bridge.h" | |
| 10 #include "chrome/browser/media/router/test_helper.h" | |
| 11 #include "content/public/browser/presentation_service_delegate.h" | |
| 12 #include "content/public/common/presentation_info.h" | |
| 13 #include "testing/gmock/include/gmock/gmock.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 #include "url/origin.h" | |
| 16 | |
| 17 using testing::_; | |
| 18 using testing::Expectation; | |
| 19 using testing::Return; | |
| 20 | |
| 21 namespace media_router { | |
| 22 | |
| 23 class MockMediaRouterAndroidBridge : public MediaRouterAndroidBridge { | |
| 24 public: | |
| 25 MockMediaRouterAndroidBridge() : MediaRouterAndroidBridge(nullptr) {} | |
| 26 ~MockMediaRouterAndroidBridge() = default; | |
| 27 | |
| 28 MOCK_METHOD7(CreateRoute, | |
| 29 void(const MediaSource::Id&, | |
| 30 const MediaSink::Id&, | |
| 31 const std::string&, | |
| 32 const url::Origin&, | |
| 33 int, | |
| 34 bool, | |
| 35 int)); | |
| 36 MOCK_METHOD5(JoinRoute, | |
| 37 void(const MediaSource::Id&, | |
| 38 const std::string&, | |
| 39 const url::Origin&, | |
| 40 int, | |
| 41 int)); | |
| 42 MOCK_METHOD1(TerminateRoute, void(const MediaRoute::Id&)); | |
| 43 MOCK_METHOD3(SendRouteMessage, | |
| 44 void(const MediaRoute::Id&, const std::string&, int)); | |
| 45 MOCK_METHOD1(DetachRoute, void(const MediaRoute::Id&)); | |
| 46 MOCK_METHOD1(StartObservingMediaSinks, bool(const MediaSource::Id&)); | |
| 47 MOCK_METHOD1(StopObservingMediaSinks, void(const MediaSource::Id&)); | |
| 48 }; | |
| 49 | |
| 50 class MediaRouterAndroidTest : public testing::Test { | |
| 51 public: | |
| 52 void SetUp() override { | |
| 53 mock_bridge_ = new MockMediaRouterAndroidBridge(); | |
| 54 router_.reset(new MediaRouterAndroid(nullptr)); | |
| 55 router_->SetMediaRouterBridgeForTest(mock_bridge_); | |
| 56 } | |
| 57 | |
| 58 void TearDown() override {} | |
|
mlamouri (slow - plz ping)
2017/04/11 13:18:12
nit: could you just drop this?
whywhat
2017/04/11 16:36:12
Done.
| |
| 59 | |
| 60 protected: | |
| 61 std::unique_ptr<MediaRouterAndroid> router_; | |
| 62 MockMediaRouterAndroidBridge* mock_bridge_; | |
| 63 }; | |
| 64 | |
| 65 TEST_F(MediaRouterAndroidTest, DetachRoute) { | |
| 66 base::MockCallback<content::PresentationConnectionStateChangedCallback> | |
| 67 callback; | |
| 68 content::PresentationConnectionStateChangeInfo change_info_closed( | |
| 69 content::PRESENTATION_CONNECTION_STATE_CLOSED); | |
| 70 EXPECT_CALL(callback, Run(StateChangeInfoEquals(change_info_closed))); | |
| 71 | |
| 72 Expectation createRouteExpectation = | |
| 73 EXPECT_CALL(*mock_bridge_, CreateRoute(_, _, _, _, _, _, 1)) | |
| 74 .WillOnce(Return()); | |
| 75 EXPECT_CALL(*mock_bridge_, DetachRoute("route")) | |
| 76 .After(createRouteExpectation) | |
| 77 .WillOnce(Return()); | |
| 78 | |
| 79 router_->CreateRoute("source", "sink", url::Origin(), nullptr, | |
| 80 std::vector<MediaRouteResponseCallback>(), | |
| 81 base::TimeDelta(), false); | |
| 82 router_->OnRouteCreated("route", "sink", 1, false); | |
| 83 | |
| 84 EXPECT_NE(nullptr, router_->FindRouteBySource("source")); | |
| 85 | |
| 86 std::unique_ptr<PresentationConnectionStateSubscription> subscription = | |
| 87 router_->AddPresentationConnectionStateChangedCallback("route", | |
| 88 callback.Get()); | |
| 89 router_->DetachRoute("route"); | |
| 90 | |
| 91 EXPECT_EQ(nullptr, router_->FindRouteBySource("source")); | |
| 92 } | |
| 93 | |
| 94 TEST_F(MediaRouterAndroidTest, OnRouteClosed) { | |
| 95 base::MockCallback<content::PresentationConnectionStateChangedCallback> | |
| 96 callback; | |
| 97 content::PresentationConnectionStateChangeInfo change_info_closed( | |
| 98 content::PRESENTATION_CONNECTION_STATE_TERMINATED); | |
| 99 EXPECT_CALL(callback, Run(StateChangeInfoEquals(change_info_closed))); | |
| 100 | |
| 101 Expectation createRouteExpectation = | |
| 102 EXPECT_CALL(*mock_bridge_, CreateRoute(_, _, _, _, _, _, 1)) | |
| 103 .WillOnce(Return()); | |
| 104 EXPECT_CALL(*mock_bridge_, DetachRoute("route")) | |
| 105 .After(createRouteExpectation) | |
| 106 .WillOnce(Return()); | |
| 107 | |
| 108 router_->CreateRoute("source", "sink", url::Origin(), nullptr, | |
| 109 std::vector<MediaRouteResponseCallback>(), | |
| 110 base::TimeDelta(), false); | |
| 111 router_->OnRouteCreated("route", "sink", 1, false); | |
| 112 | |
| 113 EXPECT_NE(nullptr, router_->FindRouteBySource("source")); | |
| 114 | |
| 115 std::unique_ptr<PresentationConnectionStateSubscription> subscription = | |
| 116 router_->AddPresentationConnectionStateChangedCallback("route", | |
| 117 callback.Get()); | |
| 118 router_->OnRouteClosed("route"); | |
| 119 | |
| 120 EXPECT_EQ(nullptr, router_->FindRouteBySource("source")); | |
| 121 } | |
| 122 | |
| 123 } // namespace media_router | |
| OLD | NEW |