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

Side by Side Diff: chrome/browser/media/android/router/media_router_android_unittest.cc

Issue 2788783002: [Cast,Android] Handle some PresentationAPI edge cases (Closed)
Patch Set: Fixed the unittests Created 3 years, 8 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
(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 "content/public/test/test_browser_thread_bundle.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "url/origin.h"
17
18 using testing::_;
19 using testing::Expectation;
20 using testing::Return;
21
22 namespace media_router {
23
24 class MockMediaRouterAndroidBridge : public MediaRouterAndroidBridge {
25 public:
26 MockMediaRouterAndroidBridge() : MediaRouterAndroidBridge(nullptr) {}
27 ~MockMediaRouterAndroidBridge() = default;
28
29 MOCK_METHOD7(CreateRoute,
30 void(const MediaSource::Id&,
31 const MediaSink::Id&,
32 const std::string&,
33 const url::Origin&,
34 int,
35 bool,
36 int));
37 MOCK_METHOD5(JoinRoute,
38 void(const MediaSource::Id&,
39 const std::string&,
40 const url::Origin&,
41 int,
42 int));
43 MOCK_METHOD1(TerminateRoute, void(const MediaRoute::Id&));
44 MOCK_METHOD3(SendRouteMessage,
45 void(const MediaRoute::Id&, const std::string&, int));
46 MOCK_METHOD1(DetachRoute, void(const MediaRoute::Id&));
47 MOCK_METHOD1(StartObservingMediaSinks, bool(const MediaSource::Id&));
48 MOCK_METHOD1(StopObservingMediaSinks, void(const MediaSource::Id&));
49 };
50
51 class MediaRouterAndroidTest : public testing::Test {
52 public:
53 void SetUp() override {
54 mock_bridge_ = new MockMediaRouterAndroidBridge();
55 router_.reset(new MediaRouterAndroid(nullptr));
56 router_->SetMediaRouterBridgeForTest(mock_bridge_);
57 }
58
59 protected:
60 // For the checks that MediaRouter calls are running on the UI thread.
61 // Needs to be the first member variable to be destroyed last.
62 content::TestBrowserThreadBundle thread_bundle_;
63
64 std::unique_ptr<MediaRouterAndroid> router_;
65 MockMediaRouterAndroidBridge* mock_bridge_;
66 };
67
68 TEST_F(MediaRouterAndroidTest, DetachRoute) {
69 base::MockCallback<content::PresentationConnectionStateChangedCallback>
70 callback;
71 content::PresentationConnectionStateChangeInfo change_info_closed(
72 content::PRESENTATION_CONNECTION_STATE_CLOSED);
73 change_info_closed.close_reason =
74 content::PRESENTATION_CONNECTION_CLOSE_REASON_CLOSED;
75 change_info_closed.message = "Remove route";
76 EXPECT_CALL(callback, Run(StateChangeInfoEquals(change_info_closed)));
77
78 Expectation createRouteExpectation =
79 EXPECT_CALL(*mock_bridge_, CreateRoute(_, _, _, _, _, _, 1))
80 .WillOnce(Return());
81 EXPECT_CALL(*mock_bridge_, DetachRoute("route"))
82 .After(createRouteExpectation)
83 .WillOnce(Return());
84
85 router_->CreateRoute("source", "sink", url::Origin(), nullptr,
86 std::vector<MediaRouteResponseCallback>(),
87 base::TimeDelta(), false);
88 router_->OnRouteCreated("route", "sink", 1, false);
89
90 EXPECT_NE(nullptr, router_->FindRouteBySource("source"));
91
92 std::unique_ptr<PresentationConnectionStateSubscription> subscription =
93 router_->AddPresentationConnectionStateChangedCallback("route",
94 callback.Get());
95 router_->DetachRoute("route");
96
97 EXPECT_EQ(nullptr, router_->FindRouteBySource("source"));
98 }
99
100 TEST_F(MediaRouterAndroidTest, OnRouteClosed) {
101 base::MockCallback<content::PresentationConnectionStateChangedCallback>
102 callback;
103 content::PresentationConnectionStateChangeInfo change_info_terminated(
104 content::PRESENTATION_CONNECTION_STATE_TERMINATED);
105 EXPECT_CALL(callback, Run(StateChangeInfoEquals(change_info_terminated)));
106
107 Expectation createRouteExpectation =
108 EXPECT_CALL(*mock_bridge_, CreateRoute(_, _, _, _, _, _, 1))
109 .WillOnce(Return());
110 EXPECT_CALL(*mock_bridge_, DetachRoute("route"))
111 .After(createRouteExpectation)
112 .WillOnce(Return());
113
114 router_->CreateRoute("source", "sink", url::Origin(), nullptr,
115 std::vector<MediaRouteResponseCallback>(),
116 base::TimeDelta(), false);
117 router_->OnRouteCreated("route", "sink", 1, false);
118
119 EXPECT_NE(nullptr, router_->FindRouteBySource("source"));
120
121 std::unique_ptr<PresentationConnectionStateSubscription> subscription =
122 router_->AddPresentationConnectionStateChangedCallback("route",
123 callback.Get());
124 router_->OnRouteClosed("route");
125
126 EXPECT_EQ(nullptr, router_->FindRouteBySource("source"));
127 }
128
129 } // namespace media_router
OLDNEW
« no previous file with comments | « chrome/browser/media/android/router/media_router_android_bridge.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698