| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "chrome/browser/media/router/create_session_request.h" | 6 #include "chrome/browser/media/router/create_presentation_session_request.h" |
| 7 #include "chrome/browser/media/router/media_source_helper.h" | 7 #include "chrome/browser/media/router/media_source_helper.h" |
| 8 #include "content/public/browser/presentation_service_delegate.h" | 8 #include "content/public/browser/presentation_service_delegate.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace media_router { | 11 namespace media_router { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 const char kPresentationUrl[] = "http://foo.com"; | 15 const char kPresentationUrl[] = "http://foo.com"; |
| 16 const char kPresentationId[] = "presentationId"; | 16 const char kPresentationId[] = "presentationId"; |
| 17 const char kRouteId[] = | 17 const char kRouteId[] = |
| 18 "urn:x-org.chromium:media:route:presentationId/cast-sink1/http://foo.com"; | 18 "urn:x-org.chromium:media:route:presentationId/cast-sink1/http://foo.com"; |
| 19 | 19 |
| 20 } // namespace | 20 } // namespace |
| 21 | 21 |
| 22 class CreateSessionRequestTest : public ::testing::Test { | 22 class CreatePresentationSessionRequestTest : public ::testing::Test { |
| 23 public: | 23 public: |
| 24 CreateSessionRequestTest() : cb_invoked_(false) {} | 24 CreatePresentationSessionRequestTest() : cb_invoked_(false) {} |
| 25 ~CreateSessionRequestTest() override {} | 25 ~CreatePresentationSessionRequestTest() override {} |
| 26 | 26 |
| 27 void OnSuccess(const content::PresentationSessionInfo& expected_info, | 27 void OnSuccess(const content::PresentationSessionInfo& expected_info, |
| 28 const content::PresentationSessionInfo& actual_info, | 28 const content::PresentationSessionInfo& actual_info, |
| 29 const MediaRoute::Id& route_id) { | 29 const MediaRoute::Id& route_id) { |
| 30 cb_invoked_ = true; | 30 cb_invoked_ = true; |
| 31 EXPECT_EQ(expected_info.presentation_url, actual_info.presentation_url); | 31 EXPECT_EQ(expected_info.presentation_url, actual_info.presentation_url); |
| 32 EXPECT_EQ(expected_info.presentation_id, actual_info.presentation_id); | 32 EXPECT_EQ(expected_info.presentation_id, actual_info.presentation_id); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void OnError(const content::PresentationError& expected_error, | 35 void OnError(const content::PresentationError& expected_error, |
| 36 const content::PresentationError& actual_error) { | 36 const content::PresentationError& actual_error) { |
| 37 cb_invoked_ = true; | 37 cb_invoked_ = true; |
| 38 EXPECT_EQ(expected_error.error_type, actual_error.error_type); | 38 EXPECT_EQ(expected_error.error_type, actual_error.error_type); |
| 39 EXPECT_EQ(expected_error.message, actual_error.message); | 39 EXPECT_EQ(expected_error.message, actual_error.message); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void FailOnSuccess(const content::PresentationSessionInfo& info, | 42 void FailOnSuccess(const content::PresentationSessionInfo& info, |
| 43 const MediaRoute::Id& route_id) { | 43 const MediaRoute::Id& route_id) { |
| 44 FAIL() << "Success callback should not have been called."; | 44 FAIL() << "Success callback should not have been called."; |
| 45 } | 45 } |
| 46 | 46 |
| 47 void FailOnError(const content::PresentationError& error) { | 47 void FailOnError(const content::PresentationError& error) { |
| 48 FAIL() << "Error should not have been called."; | 48 FAIL() << "Error should not have been called."; |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool cb_invoked_; | 51 bool cb_invoked_; |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 // Test that the object's getters match the constructor parameters. | 54 // Test that the object's getters match the constructor parameters. |
| 55 TEST_F(CreateSessionRequestTest, Getters) { | 55 TEST_F(CreatePresentationSessionRequestTest, Getters) { |
| 56 GURL frame_url("http://frameUrl"); | 56 GURL frame_url("http://frameUrl"); |
| 57 | 57 |
| 58 content::PresentationSessionInfo session_info(kPresentationUrl, | 58 content::PresentationSessionInfo session_info(kPresentationUrl, |
| 59 kPresentationId); | 59 kPresentationId); |
| 60 | 60 content::PresentationError error(content::PRESENTATION_ERROR_UNKNOWN, |
| 61 CreateSessionRequest context( | 61 "Unknown error."); |
| 62 CreatePresentationSessionRequest context( |
| 62 kPresentationUrl, kPresentationId, frame_url, | 63 kPresentationUrl, kPresentationId, frame_url, |
| 63 CreateSessionRequest::PresentationSessionSuccessCallback(), | 64 base::Bind(&CreatePresentationSessionRequestTest::FailOnSuccess, |
| 64 CreateSessionRequest::PresentationSessionErrorCallback()); | 65 base::Unretained(this)), |
| 66 base::Bind(&CreatePresentationSessionRequestTest::OnError, |
| 67 base::Unretained(this), error)); |
| 65 EXPECT_TRUE(MediaSourceForPresentationUrl(kPresentationUrl) | 68 EXPECT_TRUE(MediaSourceForPresentationUrl(kPresentationUrl) |
| 66 .Equals(context.GetMediaSource())); | 69 .Equals(context.GetMediaSource())); |
| 67 EXPECT_EQ(frame_url, context.frame_url()); | 70 EXPECT_EQ(frame_url, context.frame_url()); |
| 68 content::PresentationSessionInfo actual_session_info( | 71 content::PresentationSessionInfo actual_session_info( |
| 69 context.presentation_info()); | 72 context.presentation_info()); |
| 70 EXPECT_EQ(kPresentationUrl, actual_session_info.presentation_url); | 73 EXPECT_EQ(kPresentationUrl, actual_session_info.presentation_url); |
| 71 EXPECT_EQ(kPresentationId, actual_session_info.presentation_id); | 74 EXPECT_EQ(kPresentationId, actual_session_info.presentation_id); |
| 75 // Since we didn't explicitly call MaybeInvoke*, the error callback will be |
| 76 // invoked when |context| is destroyed. |
| 72 } | 77 } |
| 73 | 78 |
| 74 TEST_F(CreateSessionRequestTest, SuccessCallback) { | 79 TEST_F(CreatePresentationSessionRequestTest, SuccessCallback) { |
| 75 GURL frame_url("http://frameUrl"); | 80 GURL frame_url("http://frameUrl"); |
| 76 content::PresentationSessionInfo session_info(kPresentationUrl, | 81 content::PresentationSessionInfo session_info(kPresentationUrl, |
| 77 kPresentationId); | 82 kPresentationId); |
| 78 CreateSessionRequest context( | 83 CreatePresentationSessionRequest context( |
| 79 kPresentationUrl, kPresentationId, frame_url, | 84 kPresentationUrl, kPresentationId, frame_url, |
| 80 base::Bind(&CreateSessionRequestTest::OnSuccess, base::Unretained(this), | 85 base::Bind(&CreatePresentationSessionRequestTest::OnSuccess, |
| 81 session_info), | 86 base::Unretained(this), session_info), |
| 82 base::Bind(&CreateSessionRequestTest::FailOnError, | 87 base::Bind(&CreatePresentationSessionRequestTest::FailOnError, |
| 83 base::Unretained(this))); | 88 base::Unretained(this))); |
| 84 context.MaybeInvokeSuccessCallback(kRouteId); | 89 context.MaybeInvokeSuccessCallback(kRouteId); |
| 85 // No-op since success callback is already invoked. | 90 // No-op since success callback is already invoked. |
| 86 context.MaybeInvokeErrorCallback(content::PresentationError( | 91 context.MaybeInvokeErrorCallback(content::PresentationError( |
| 87 content::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "Error message")); | 92 content::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "Error message")); |
| 88 EXPECT_TRUE(cb_invoked_); | 93 EXPECT_TRUE(cb_invoked_); |
| 89 } | 94 } |
| 90 | 95 |
| 91 TEST_F(CreateSessionRequestTest, ErrorCallback) { | 96 TEST_F(CreatePresentationSessionRequestTest, ErrorCallback) { |
| 92 GURL frame_url("http://frameUrl"); | 97 GURL frame_url("http://frameUrl"); |
| 93 content::PresentationSessionInfo session_info(kPresentationUrl, | 98 content::PresentationSessionInfo session_info(kPresentationUrl, |
| 94 kPresentationId); | 99 kPresentationId); |
| 95 content::PresentationError error( | 100 content::PresentationError error( |
| 96 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, | 101 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, |
| 97 "This is an error message"); | 102 "This is an error message"); |
| 98 CreateSessionRequest context( | 103 CreatePresentationSessionRequest context( |
| 99 kPresentationUrl, kPresentationId, frame_url, | 104 kPresentationUrl, kPresentationId, frame_url, |
| 100 base::Bind(&CreateSessionRequestTest::FailOnSuccess, | 105 base::Bind(&CreatePresentationSessionRequestTest::FailOnSuccess, |
| 101 base::Unretained(this)), | 106 base::Unretained(this)), |
| 102 base::Bind(&CreateSessionRequestTest::OnError, base::Unretained(this), | 107 base::Bind(&CreatePresentationSessionRequestTest::OnError, |
| 103 error)); | 108 base::Unretained(this), error)); |
| 104 context.MaybeInvokeErrorCallback(error); | 109 context.MaybeInvokeErrorCallback(error); |
| 105 // No-op since error callback is already invoked. | 110 // No-op since error callback is already invoked. |
| 106 context.MaybeInvokeSuccessCallback(kRouteId); | 111 context.MaybeInvokeSuccessCallback(kRouteId); |
| 107 EXPECT_TRUE(cb_invoked_); | 112 EXPECT_TRUE(cb_invoked_); |
| 108 } | 113 } |
| 109 | 114 |
| 110 } // namespace media_router | 115 } // namespace media_router |
| OLD | NEW |