| 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> |
| 6 #include <stdint.h> |
| 7 |
| 5 #include <string> | 8 #include <string> |
| 6 | 9 |
| 7 #include "base/bind.h" | 10 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 11 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/test/histogram_tester.h" | 16 #include "base/test/histogram_tester.h" |
| 13 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 14 #include "chrome/browser/media/router/issue.h" | 18 #include "chrome/browser/media/router/issue.h" |
| 15 #include "chrome/browser/media/router/media_route.h" | 19 #include "chrome/browser/media/router/media_route.h" |
| 16 #include "chrome/browser/media/router/media_router_metrics.h" | 20 #include "chrome/browser/media/router/media_router_metrics.h" |
| 17 #include "chrome/browser/media/router/media_router_mojo_test.h" | 21 #include "chrome/browser/media/router/media_router_mojo_test.h" |
| 18 #include "chrome/browser/media/router/media_router_type_converters.h" | 22 #include "chrome/browser/media/router/media_router_type_converters.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 const char kSource[] = "source1"; | 56 const char kSource[] = "source1"; |
| 53 const char kSource2[] = "source2"; | 57 const char kSource2[] = "source2"; |
| 54 const char kRouteId[] = "routeId"; | 58 const char kRouteId[] = "routeId"; |
| 55 const char kRouteId2[] = "routeId2"; | 59 const char kRouteId2[] = "routeId2"; |
| 56 const char kSinkId[] = "sink"; | 60 const char kSinkId[] = "sink"; |
| 57 const char kSinkId2[] = "sink2"; | 61 const char kSinkId2[] = "sink2"; |
| 58 const char kSinkName[] = "sinkName"; | 62 const char kSinkName[] = "sinkName"; |
| 59 const char kPresentationId[] = "presentationId"; | 63 const char kPresentationId[] = "presentationId"; |
| 60 const char kOrigin[] = "http://origin/"; | 64 const char kOrigin[] = "http://origin/"; |
| 61 const int kInvalidTabId = -1; | 65 const int kInvalidTabId = -1; |
| 62 const uint8 kBinaryMessage[] = {0x01, 0x02, 0x03, 0x04}; | 66 const uint8_t kBinaryMessage[] = {0x01, 0x02, 0x03, 0x04}; |
| 63 | 67 |
| 64 bool ArePresentationSessionMessagesEqual( | 68 bool ArePresentationSessionMessagesEqual( |
| 65 const content::PresentationSessionMessage* expected, | 69 const content::PresentationSessionMessage* expected, |
| 66 const content::PresentationSessionMessage* actual) { | 70 const content::PresentationSessionMessage* actual) { |
| 67 if (expected->type != actual->type) | 71 if (expected->type != actual->type) |
| 68 return false; | 72 return false; |
| 69 | 73 |
| 70 return expected->is_binary() ? *expected->data == *actual->data | 74 return expected->is_binary() ? *expected->data == *actual->data |
| 71 : expected->message == actual->message; | 75 : expected->message == actual->message; |
| 72 } | 76 } |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 | 571 |
| 568 SendMessageCallbackHandler handler; | 572 SendMessageCallbackHandler handler; |
| 569 EXPECT_CALL(handler, Invoke(true)); | 573 EXPECT_CALL(handler, Invoke(true)); |
| 570 router()->SendRouteMessage(kRouteId, kMessage, | 574 router()->SendRouteMessage(kRouteId, kMessage, |
| 571 base::Bind(&SendMessageCallbackHandler::Invoke, | 575 base::Bind(&SendMessageCallbackHandler::Invoke, |
| 572 base::Unretained(&handler))); | 576 base::Unretained(&handler))); |
| 573 ProcessEventLoop(); | 577 ProcessEventLoop(); |
| 574 } | 578 } |
| 575 | 579 |
| 576 TEST_F(MediaRouterMojoImplTest, SendRouteBinaryMessage) { | 580 TEST_F(MediaRouterMojoImplTest, SendRouteBinaryMessage) { |
| 577 scoped_ptr<std::vector<uint8>> expected_binary_data(new std::vector<uint8>( | 581 scoped_ptr<std::vector<uint8_t>> expected_binary_data( |
| 578 kBinaryMessage, kBinaryMessage + arraysize(kBinaryMessage))); | 582 new std::vector<uint8_t>(kBinaryMessage, |
| 583 kBinaryMessage + arraysize(kBinaryMessage))); |
| 579 | 584 |
| 580 EXPECT_CALL(mock_media_route_provider_, | 585 EXPECT_CALL(mock_media_route_provider_, |
| 581 SendRouteBinaryMessageInternal(mojo::String(kRouteId), _, _)) | 586 SendRouteBinaryMessageInternal(mojo::String(kRouteId), _, _)) |
| 582 .WillOnce(Invoke([]( | 587 .WillOnce(Invoke([]( |
| 583 const MediaRoute::Id& route_id, const std::vector<uint8>& data, | 588 const MediaRoute::Id& route_id, const std::vector<uint8_t>& data, |
| 584 const interfaces::MediaRouteProvider::SendRouteMessageCallback& cb) { | 589 const interfaces::MediaRouteProvider::SendRouteMessageCallback& cb) { |
| 585 EXPECT_EQ( | 590 EXPECT_EQ( |
| 586 0, memcmp(kBinaryMessage, &(data[0]), arraysize(kBinaryMessage))); | 591 0, memcmp(kBinaryMessage, &(data[0]), arraysize(kBinaryMessage))); |
| 587 cb.Run(true); | 592 cb.Run(true); |
| 588 })); | 593 })); |
| 589 | 594 |
| 590 SendMessageCallbackHandler handler; | 595 SendMessageCallbackHandler handler; |
| 591 EXPECT_CALL(handler, Invoke(true)); | 596 EXPECT_CALL(handler, Invoke(true)); |
| 592 router()->SendRouteBinaryMessage( | 597 router()->SendRouteBinaryMessage( |
| 593 kRouteId, expected_binary_data.Pass(), | 598 kRouteId, expected_binary_data.Pass(), |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))); | 1071 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))); |
| 1067 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId)) | 1072 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId)) |
| 1068 .WillOnce(Return(false)); | 1073 .WillOnce(Return(false)); |
| 1069 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId2))) | 1074 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId2))) |
| 1070 .Times(kMaxPendingRequests); | 1075 .Times(kMaxPendingRequests); |
| 1071 RegisterMediaRouteProvider(); | 1076 RegisterMediaRouteProvider(); |
| 1072 ProcessEventLoop(); | 1077 ProcessEventLoop(); |
| 1073 } | 1078 } |
| 1074 | 1079 |
| 1075 } // namespace media_router | 1080 } // namespace media_router |
| OLD | NEW |