| OLD | NEW |
| 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 23 matching lines...) Expand all Loading... |
| 34 #include "extensions/common/extension.h" | 34 #include "extensions/common/extension.h" |
| 35 #include "extensions/common/extension_builder.h" | 35 #include "extensions/common/extension_builder.h" |
| 36 #include "extensions/common/test_util.h" | 36 #include "extensions/common/test_util.h" |
| 37 #include "extensions/common/value_builder.h" | 37 #include "extensions/common/value_builder.h" |
| 38 #include "media/base/gmock_callback_support.h" | 38 #include "media/base/gmock_callback_support.h" |
| 39 #include "mojo/message_pump/message_pump_mojo.h" | 39 #include "mojo/message_pump/message_pump_mojo.h" |
| 40 #include "testing/gmock/include/gmock/gmock.h" | 40 #include "testing/gmock/include/gmock/gmock.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 42 | 42 |
| 43 using testing::_; | 43 using testing::_; |
| 44 using testing::AtMost; |
| 44 using testing::Eq; | 45 using testing::Eq; |
| 45 using testing::Invoke; | 46 using testing::Invoke; |
| 46 using testing::InvokeWithoutArgs; | 47 using testing::InvokeWithoutArgs; |
| 47 using testing::IsEmpty; | 48 using testing::IsEmpty; |
| 48 using testing::Mock; | 49 using testing::Mock; |
| 49 using testing::Not; | 50 using testing::Not; |
| 50 using testing::Pointee; | 51 using testing::Pointee; |
| 51 using testing::Return; | 52 using testing::Return; |
| 52 using testing::ReturnRef; | 53 using testing::ReturnRef; |
| 53 using testing::SaveArg; | 54 using testing::SaveArg; |
| (...skipping 1272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1326 // |mojo_media_router| signals its readiness to the MR by registering | 1327 // |mojo_media_router| signals its readiness to the MR by registering |
| 1327 // itself via RegisterMediaRouteProvider(). | 1328 // itself via RegisterMediaRouteProvider(). |
| 1328 // Now that the |media_router| and |mojo_media_router| are fully initialized, | 1329 // Now that the |media_router| and |mojo_media_router| are fully initialized, |
| 1329 // the queued DetachRoute() call should be executed. | 1330 // the queued DetachRoute() call should be executed. |
| 1330 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) | 1331 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) |
| 1331 .WillOnce(InvokeWithoutArgs([&run_loop]() { | 1332 .WillOnce(InvokeWithoutArgs([&run_loop]() { |
| 1332 run_loop.Quit(); | 1333 run_loop.Quit(); |
| 1333 })); | 1334 })); |
| 1334 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) | 1335 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) |
| 1335 .WillOnce(Return(false)); | 1336 .WillOnce(Return(false)); |
| 1337 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) |
| 1338 .Times(AtMost(1)); |
| 1336 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId))) | 1339 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId))) |
| 1337 .WillOnce(InvokeWithoutArgs([&run_loop2]() { | 1340 .WillOnce(InvokeWithoutArgs([&run_loop2]() { |
| 1338 run_loop2.Quit(); | 1341 run_loop2.Quit(); |
| 1339 })); | 1342 })); |
| 1340 RegisterMediaRouteProvider(); | 1343 RegisterMediaRouteProvider(); |
| 1341 run_loop.Run(); | 1344 run_loop.Run(); |
| 1342 run_loop2.Run(); | 1345 run_loop2.Run(); |
| 1343 | 1346 |
| 1344 base::RunLoop run_loop3; | 1347 base::RunLoop run_loop3; |
| 1345 // Extension is suspended and re-awoken. | 1348 // Extension is suspended and re-awoken. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1356 | 1359 |
| 1357 base::RunLoop run_loop4, run_loop5; | 1360 base::RunLoop run_loop4, run_loop5; |
| 1358 // RegisterMediaRouteProvider() is called. | 1361 // RegisterMediaRouteProvider() is called. |
| 1359 // The queued DetachRoute(kRouteId2) call should be executed. | 1362 // The queued DetachRoute(kRouteId2) call should be executed. |
| 1360 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) | 1363 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) |
| 1361 .WillOnce(InvokeWithoutArgs([&run_loop4]() { | 1364 .WillOnce(InvokeWithoutArgs([&run_loop4]() { |
| 1362 run_loop4.Quit(); | 1365 run_loop4.Quit(); |
| 1363 })); | 1366 })); |
| 1364 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) | 1367 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) |
| 1365 .WillOnce(Return(false)); | 1368 .WillOnce(Return(false)); |
| 1369 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) |
| 1370 .Times(AtMost(1)); |
| 1366 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId2))) | 1371 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId2))) |
| 1367 .WillOnce(InvokeWithoutArgs([&run_loop5]() { | 1372 .WillOnce(InvokeWithoutArgs([&run_loop5]() { |
| 1368 run_loop5.Quit(); | 1373 run_loop5.Quit(); |
| 1369 })); | 1374 })); |
| 1370 BindMediaRouteProvider(); | 1375 BindMediaRouteProvider(); |
| 1371 RegisterMediaRouteProvider(); | 1376 RegisterMediaRouteProvider(); |
| 1372 run_loop4.Run(); | 1377 run_loop4.Run(); |
| 1373 run_loop5.Run(); | 1378 run_loop5.Run(); |
| 1374 ExpectWakeReasonBucketCount(MediaRouteProviderWakeReason::DETACH_ROUTE, 1); | 1379 ExpectWakeReasonBucketCount(MediaRouteProviderWakeReason::DETACH_ROUTE, 1); |
| 1375 ExpectWakeupBucketCount(MediaRouteProviderWakeup::SUCCESS, 1); | 1380 ExpectWakeupBucketCount(MediaRouteProviderWakeup::SUCCESS, 1); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1467 base::RunLoop run_loop, run_loop2; | 1472 base::RunLoop run_loop, run_loop2; |
| 1468 size_t count = 0; | 1473 size_t count = 0; |
| 1469 // The oldest request should have been dropped, so we don't expect to see | 1474 // The oldest request should have been dropped, so we don't expect to see |
| 1470 // DetachRoute(kRouteId) here. | 1475 // DetachRoute(kRouteId) here. |
| 1471 BindMediaRouteProvider(); | 1476 BindMediaRouteProvider(); |
| 1472 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) | 1477 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) |
| 1473 .WillOnce(InvokeWithoutArgs([&run_loop]() { | 1478 .WillOnce(InvokeWithoutArgs([&run_loop]() { |
| 1474 run_loop.Quit(); | 1479 run_loop.Quit(); |
| 1475 })); | 1480 })); |
| 1476 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())); | 1481 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())); |
| 1482 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) |
| 1483 .Times(AtMost(1)); |
| 1477 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId2))) | 1484 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId2))) |
| 1478 .Times(kMaxPendingRequests) | 1485 .Times(kMaxPendingRequests) |
| 1479 .WillRepeatedly(InvokeWithoutArgs([&run_loop2, &count]() { | 1486 .WillRepeatedly(InvokeWithoutArgs([&run_loop2, &count]() { |
| 1480 if (++count == MediaRouterMojoImpl::kMaxPendingRequests) | 1487 if (++count == MediaRouterMojoImpl::kMaxPendingRequests) |
| 1481 run_loop2.Quit(); | 1488 run_loop2.Quit(); |
| 1482 })); | 1489 })); |
| 1483 RegisterMediaRouteProvider(); | 1490 RegisterMediaRouteProvider(); |
| 1484 run_loop.Run(); | 1491 run_loop.Run(); |
| 1485 run_loop2.Run(); | 1492 run_loop2.Run(); |
| 1486 ExpectVersionBucketCount(MediaRouteProviderVersion::SAME_VERSION_AS_CHROME, | 1493 ExpectVersionBucketCount(MediaRouteProviderVersion::SAME_VERSION_AS_CHROME, |
| 1487 1); | 1494 1); |
| 1488 } | 1495 } |
| 1489 | 1496 |
| 1497 #if defined(OS_WIN) |
| 1498 TEST_F(MediaRouterMojoExtensionTest, EnableMdnsAfterEachRegister) { |
| 1499 // This should be queued since no MRPM is registered yet. |
| 1500 media_router_->OnUserGesture(); |
| 1501 |
| 1502 BindMediaRouteProvider(); |
| 1503 |
| 1504 base::RunLoop run_loop; |
| 1505 base::RunLoop run_loop2; |
| 1506 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) |
| 1507 .WillOnce(InvokeWithoutArgs([&run_loop]() { |
| 1508 run_loop.Quit(); |
| 1509 })); |
| 1510 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) |
| 1511 .WillOnce(Return(false)); |
| 1512 // EnableMdnsDisocvery() is never called except on Windows. |
| 1513 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) |
| 1514 .WillOnce(InvokeWithoutArgs([&run_loop2]() { |
| 1515 run_loop2.Quit(); |
| 1516 })); |
| 1517 RegisterMediaRouteProvider(); |
| 1518 run_loop.Run(); |
| 1519 run_loop2.Run(); |
| 1520 // Always a no-op at this point. |
| 1521 media_router_->OnUserGesture(); |
| 1522 |
| 1523 // Reset the extension by "suspending" and notifying MR. |
| 1524 base::RunLoop run_loop3; |
| 1525 ResetMediaRouteProvider(); |
| 1526 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) |
| 1527 .WillOnce(Return(true)); |
| 1528 EXPECT_CALL(*process_manager_, WakeEventPage(extension_->id(), _)) |
| 1529 .WillOnce(testing::DoAll( |
| 1530 media::RunCallback<1>(true), |
| 1531 InvokeWithoutArgs([&run_loop3]() { run_loop3.Quit(); }), |
| 1532 Return(true))); |
| 1533 // Use DetachRoute because it unconditionally calls RunOrDefer(). |
| 1534 media_router_->DetachRoute(kRouteId); |
| 1535 run_loop3.Run(); |
| 1536 |
| 1537 base::RunLoop run_loop4; |
| 1538 base::RunLoop run_loop5; |
| 1539 // RegisterMediaRouteProvider() is called. |
| 1540 // The queued DetachRoute(kRouteId) call should be executed. |
| 1541 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))) |
| 1542 .WillOnce(InvokeWithoutArgs([&run_loop4]() { |
| 1543 run_loop4.Quit(); |
| 1544 })); |
| 1545 EXPECT_CALL(*process_manager_, IsEventPageSuspended(extension_->id())) |
| 1546 .WillOnce(Return(false)); |
| 1547 // Expected because it was used to wake up the page. |
| 1548 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId))); |
| 1549 // EnableMdnsDisocvery() is never called except on Windows. |
| 1550 EXPECT_CALL(mock_media_route_provider_, EnableMdnsDiscovery()) |
| 1551 .WillOnce(InvokeWithoutArgs([&run_loop5]() { |
| 1552 run_loop5.Quit(); |
| 1553 })); |
| 1554 BindMediaRouteProvider(); |
| 1555 RegisterMediaRouteProvider(); |
| 1556 run_loop4.Run(); |
| 1557 run_loop5.Run(); |
| 1558 // Always a no-op at this point. |
| 1559 media_router_->OnUserGesture(); |
| 1560 } |
| 1561 #endif |
| 1562 |
| 1490 } // namespace media_router | 1563 } // namespace media_router |
| OLD | NEW |