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

Side by Side Diff: chrome/browser/media/router/media_router_base_unittest.cc

Issue 2463843003: [Presentation API] Media Router: queue PresentationConnectionStateChanged events fired before callb… (Closed)
Patch Set: Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/bind.h" 5 #include "base/bind.h"
6 #include "chrome/browser/media/router/mock_media_router.h" 6 #include "chrome/browser/media/router/mock_media_router.h"
7 #include "chrome/browser/media/router/test_helper.h" 7 #include "chrome/browser/media/router/test_helper.h"
8 #include "content/public/browser/presentation_session.h" 8 #include "content/public/browser/presentation_session.h"
9 #include "content/public/test/test_browser_thread_bundle.h" 9 #include "content/public/test/test_browser_thread_bundle.h"
10 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 router.NotifyPresentationConnectionStateChange( 95 router.NotifyPresentationConnectionStateChange(
96 route_id2, content::PRESENTATION_CONNECTION_STATE_TERMINATED); 96 route_id2, content::PRESENTATION_CONNECTION_STATE_TERMINATED);
97 97
98 subscription2.reset(); 98 subscription2.reset();
99 router.NotifyPresentationConnectionStateChange( 99 router.NotifyPresentationConnectionStateChange(
100 route_id2, content::PRESENTATION_CONNECTION_STATE_TERMINATED); 100 route_id2, content::PRESENTATION_CONNECTION_STATE_TERMINATED);
101 101
102 router.Shutdown(); 102 router.Shutdown();
103 } 103 }
104 104
105 TEST(MediaRouterBaseTest, NotifyCallbacksPendingStateChange) {
106 content::TestBrowserThreadBundle thread_bundle_;
107 MockMediaRouterBase router;
108 router.Initialize();
109
110 MediaRoute::Id route_id1("id1");
111 MediaRoute::Id route_id2("id2");
112 MockPresentationConnectionStateChangedCallback callback1;
113 MockPresentationConnectionStateChangedCallback callback2;
114
115 content::PresentationConnectionStateChangeInfo change_info_connected(
116 content::PRESENTATION_CONNECTION_STATE_CONNECTED);
117 content::PresentationConnectionStateChangeInfo change_info_terminated(
118 content::PRESENTATION_CONNECTION_STATE_TERMINATED);
119 content::PresentationConnectionStateChangeInfo change_info_closed(
120 content::PRESENTATION_CONNECTION_STATE_CLOSED);
121 change_info_closed.close_reason =
122 content::PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY;
123 change_info_closed.message = "Test message";
124
125 EXPECT_CALL(callback1, Run(StateChangeInfoEquals(change_info_connected)))
126 .Times(0);
127 router.NotifyPresentationConnectionStateChange(
128 route_id1, content::PRESENTATION_CONNECTION_STATE_CONNECTED);
129
130 EXPECT_CALL(callback2, Run(StateChangeInfoEquals(change_info_connected)))
131 .Times(0);
132 router.NotifyPresentationConnectionStateChange(
133 route_id2, content::PRESENTATION_CONNECTION_STATE_CONNECTED);
134
135 EXPECT_CALL(callback1, Run(StateChangeInfoEquals(change_info_closed)))
136 .Times(0);
137 router.NotifyPresentationConnectionClose(
138 route_id1, change_info_closed.close_reason, change_info_closed.message);
139
140 EXPECT_EQ(size_t(2), router.queued_state_changes_.size());
141
142 EXPECT_CALL(callback1, Run(StateChangeInfoEquals(change_info_connected)))
143 .Times(0);
144 EXPECT_CALL(callback1, Run(StateChangeInfoEquals(change_info_closed)));
145 std::unique_ptr<PresentationConnectionStateSubscription> subscription1 =
146 router.AddPresentationConnectionStateChangedCallback(
147 route_id1,
148 base::Bind(&MockPresentationConnectionStateChangedCallback::Run,
149 base::Unretained(&callback1)));
150
151 EXPECT_CALL(callback2, Run(StateChangeInfoEquals(change_info_connected)));
152 std::unique_ptr<PresentationConnectionStateSubscription> subscription2 =
153 router.AddPresentationConnectionStateChangedCallback(
154 route_id2,
155 base::Bind(&MockPresentationConnectionStateChangedCallback::Run,
156 base::Unretained(&callback2)));
157
158 EXPECT_CALL(callback1, Run(StateChangeInfoEquals(change_info_terminated)));
159 router.NotifyPresentationConnectionStateChange(
160 route_id1, content::PRESENTATION_CONNECTION_STATE_TERMINATED);
161
162 EXPECT_EQ(size_t(0), router.queued_state_changes_.size());
163
164 router.Shutdown();
165 }
166
105 } // namespace media_router 167 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698