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

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

Issue 1846673002: [Media Router] Conditionally enable mDNS on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: Patch-up newly-added test. Created 4 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include <stdint.h> 6 #include <stdint.h>
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 17 matching lines...) Expand all
28 #include "chrome/test/base/testing_profile.h" 28 #include "chrome/test/base/testing_profile.h"
29 #include "extensions/browser/extension_registry.h" 29 #include "extensions/browser/extension_registry.h"
30 #include "extensions/browser/process_manager.h" 30 #include "extensions/browser/process_manager.h"
31 #include "extensions/browser/process_manager_factory.h" 31 #include "extensions/browser/process_manager_factory.h"
32 #include "media/base/gmock_callback_support.h" 32 #include "media/base/gmock_callback_support.h"
33 #include "mojo/message_pump/message_pump_mojo.h" 33 #include "mojo/message_pump/message_pump_mojo.h"
34 #include "testing/gmock/include/gmock/gmock.h" 34 #include "testing/gmock/include/gmock/gmock.h"
35 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
36 36
37 using testing::_; 37 using testing::_;
38 using testing::AtMost;
38 using testing::Eq; 39 using testing::Eq;
39 using testing::Invoke; 40 using testing::Invoke;
40 using testing::InvokeWithoutArgs; 41 using testing::InvokeWithoutArgs;
41 using testing::IsEmpty; 42 using testing::IsEmpty;
42 using testing::Mock; 43 using testing::Mock;
43 using testing::Not; 44 using testing::Not;
44 using testing::Pointee; 45 using testing::Pointee;
45 using testing::Return; 46 using testing::Return;
46 using testing::ReturnRef; 47 using testing::ReturnRef;
47 using testing::SaveArg; 48 using testing::SaveArg;
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 // |mojo_media_router| signals its readiness to the MR by registering 1137 // |mojo_media_router| signals its readiness to the MR by registering
1137 // itself via RegisterMediaRouteProvider(). 1138 // itself via RegisterMediaRouteProvider().
1138 // Now that the |media_router| and |mojo_media_router| are fully initialized, 1139 // Now that the |media_router| and |mojo_media_router| are fully initialized,
1139 // the queued DetachRoute() call should be executed. 1140 // the queued DetachRoute() call should be executed.
1140 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) 1141 EXPECT_CALL(provide_handler_, Invoke(testing::Not("")))
1141 .WillOnce(InvokeWithoutArgs([&run_loop]() { 1142 .WillOnce(InvokeWithoutArgs([&run_loop]() {
1142 run_loop.Quit(); 1143 run_loop.Quit();
1143 })); 1144 }));
1144 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId)) 1145 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId))
1145 .WillOnce(Return(false)); 1146 .WillOnce(Return(false));
1147 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery())
1148 .Times(AtMost(1));
1146 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId))) 1149 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId)))
1147 .WillOnce(InvokeWithoutArgs([&run_loop2]() { 1150 .WillOnce(InvokeWithoutArgs([&run_loop2]() {
1148 run_loop2.Quit(); 1151 run_loop2.Quit();
1149 })); 1152 }));
1150 RegisterMediaRouteProvider(); 1153 RegisterMediaRouteProvider();
1151 run_loop.Run(); 1154 run_loop.Run();
1152 run_loop2.Run(); 1155 run_loop2.Run();
1153 1156
1154 base::RunLoop run_loop3; 1157 base::RunLoop run_loop3;
1155 // Extension is suspended and re-awoken. 1158 // Extension is suspended and re-awoken.
(...skipping 11 matching lines...) Expand all
1167 1170
1168 base::RunLoop run_loop4, run_loop5; 1171 base::RunLoop run_loop4, run_loop5;
1169 // RegisterMediaRouteProvider() is called. 1172 // RegisterMediaRouteProvider() is called.
1170 // The queued DetachRoute(kRouteId2) call should be executed. 1173 // The queued DetachRoute(kRouteId2) call should be executed.
1171 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) 1174 EXPECT_CALL(provide_handler_, Invoke(testing::Not("")))
1172 .WillOnce(InvokeWithoutArgs([&run_loop4]() { 1175 .WillOnce(InvokeWithoutArgs([&run_loop4]() {
1173 run_loop4.Quit(); 1176 run_loop4.Quit();
1174 })); 1177 }));
1175 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId)) 1178 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId))
1176 .WillOnce(Return(false)); 1179 .WillOnce(Return(false));
1180 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery())
1181 .Times(AtMost(1));
1177 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId2))) 1182 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId2)))
1178 .WillOnce(InvokeWithoutArgs([&run_loop5]() { 1183 .WillOnce(InvokeWithoutArgs([&run_loop5]() {
1179 run_loop5.Quit(); 1184 run_loop5.Quit();
1180 })); 1185 }));
1181 BindMediaRouteProvider(); 1186 BindMediaRouteProvider();
1182 RegisterMediaRouteProvider(); 1187 RegisterMediaRouteProvider();
1183 run_loop4.Run(); 1188 run_loop4.Run();
1184 run_loop5.Run(); 1189 run_loop5.Run();
1185 ExpectWakeReasonBucketCount(MediaRouteProviderWakeReason::DETACH_ROUTE, 1); 1190 ExpectWakeReasonBucketCount(MediaRouteProviderWakeReason::DETACH_ROUTE, 1);
1186 } 1191 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 base::RunLoop run_loop, run_loop2; 1273 base::RunLoop run_loop, run_loop2;
1269 size_t count = 0; 1274 size_t count = 0;
1270 // The oldest request should have been dropped, so we don't expect to see 1275 // The oldest request should have been dropped, so we don't expect to see
1271 // DetachRoute(kRouteId) here. 1276 // DetachRoute(kRouteId) here.
1272 BindMediaRouteProvider(); 1277 BindMediaRouteProvider();
1273 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) 1278 EXPECT_CALL(provide_handler_, Invoke(testing::Not("")))
1274 .WillOnce(InvokeWithoutArgs([&run_loop]() { 1279 .WillOnce(InvokeWithoutArgs([&run_loop]() {
1275 run_loop.Quit(); 1280 run_loop.Quit();
1276 })); 1281 }));
1277 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId)); 1282 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId));
1283 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery())
1284 .Times(AtMost(1));
1278 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId2))) 1285 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId2)))
1279 .Times(kMaxPendingRequests) 1286 .Times(kMaxPendingRequests)
1280 .WillRepeatedly(InvokeWithoutArgs([&run_loop2, &count]() { 1287 .WillRepeatedly(InvokeWithoutArgs([&run_loop2, &count]() {
1281 if (++count == MediaRouterMojoImpl::kMaxPendingRequests) 1288 if (++count == MediaRouterMojoImpl::kMaxPendingRequests)
1282 run_loop2.Quit(); 1289 run_loop2.Quit();
1283 })); 1290 }));
1284 RegisterMediaRouteProvider(); 1291 RegisterMediaRouteProvider();
1285 run_loop.Run(); 1292 run_loop.Run();
1286 run_loop2.Run(); 1293 run_loop2.Run();
1287 } 1294 }
1288 1295
1296 #if defined(OS_WIN)
1297 TEST_F(MediaRouterMojoExtensionTest, EnableMdnsAfterEachRegister) {
1298 // This should be queued since no MRPM is registered yet.
1299 media_router_->OnUserGesture();
1300
1301 BindMediaRouteProvider();
1302
1303 base::RunLoop run_loop;
1304 base::RunLoop run_loop2;
1305 EXPECT_CALL(provide_handler_, Invoke(testing::Not("")))
1306 .WillOnce(InvokeWithoutArgs([&run_loop]() {
1307 run_loop.Quit();
1308 }));
1309 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_id()))
1310 .WillOnce(Return(false));
1311 // EnableMdnsDisocvery() is never called except on Windows.
1312 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery())
1313 .WillOnce(InvokeWithoutArgs([&run_loop2]() {
1314 run_loop2.Quit();
1315 }));
1316 RegisterMediaRouteProvider();
1317 run_loop.Run();
1318 run_loop2.Run();
1319 // Always a no-op at this point.
1320 media_router_->OnUserGesture();
1321
1322 // Reset the extension by "suspending" and notifying MR.
1323 base::RunLoop run_loop3;
1324 ResetMediaRouteProvider();
1325 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_id()))
1326 .WillOnce(Return(true));
1327 EXPECT_CALL(*process_manager_, WakeEventPage(extension_id(), _))
1328 .WillOnce(testing::DoAll(
1329 media::RunCallback<1>(true),
1330 InvokeWithoutArgs([&run_loop3]() { run_loop3.Quit(); }),
1331 Return(true)));
1332 // Use DetachRoute because it unconditionally calls RunOrDefer().
1333 media_router_->DetachRoute(kRouteId);
1334 run_loop3.Run();
1335
1336 base::RunLoop run_loop4;
1337 base::RunLoop run_loop5;
1338 // RegisterMediaRouteProvider() is called.
1339 // The queued DetachRoute(kRouteId) call should be executed.
1340 EXPECT_CALL(provide_handler_, Invoke(testing::Not("")))
1341 .WillOnce(InvokeWithoutArgs([&run_loop4]() {
1342 run_loop4.Quit();
1343 }));
1344 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_id()))
1345 .WillOnce(Return(false));
1346 // Expected because it was used to wake up the page.
1347 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId)));
1348 // EnableMdnsDisocvery() is never called except on Windows.
1349 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery())
1350 .WillOnce(InvokeWithoutArgs([&run_loop5]() {
1351 run_loop5.Quit();
1352 }));
1353 BindMediaRouteProvider();
1354 RegisterMediaRouteProvider();
1355 run_loop4.Run();
1356 run_loop5.Run();
1357 // Always a no-op at this point.
1358 media_router_->OnUserGesture();
1359 }
1360 #endif
1361
1289 } // namespace media_router 1362 } // namespace media_router
OLDNEW
« no previous file with comments | « chrome/browser/media/router/media_router_mojo_impl.cc ('k') | chrome/browser/media/router/media_router_mojo_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698