| 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_presentation_connection_request.h" | 6 #include "chrome/browser/media/router/create_presentation_connection_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 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 class CreatePresentationConnectionRequestTest : public ::testing::Test { | 25 class CreatePresentationConnectionRequestTest : public ::testing::Test { |
| 26 public: | 26 public: |
| 27 CreatePresentationConnectionRequestTest() | 27 CreatePresentationConnectionRequestTest() |
| 28 : cb_invoked_(false), | 28 : cb_invoked_(false), |
| 29 render_frame_host_id_(1, 2), | 29 render_frame_host_id_(1, 2), |
| 30 presentation_url_(kPresentationUrl1), | 30 presentation_url_(kPresentationUrl1), |
| 31 presentation_urls_({presentation_url_, GURL(kPresentationUrl2)}) {} | 31 presentation_urls_({presentation_url_, GURL(kPresentationUrl2)}) {} |
| 32 | 32 |
| 33 ~CreatePresentationConnectionRequestTest() override {} | 33 ~CreatePresentationConnectionRequestTest() override {} |
| 34 | 34 |
| 35 void OnSuccess(const content::PresentationSessionInfo& expected_info, | 35 void OnSuccess(const content::PresentationInfo& expected_info, |
| 36 const content::PresentationSessionInfo& actual_info, | 36 const content::PresentationInfo& actual_info, |
| 37 const MediaRoute& route) { | 37 const MediaRoute& route) { |
| 38 cb_invoked_ = true; | 38 cb_invoked_ = true; |
| 39 EXPECT_EQ(expected_info.presentation_url, actual_info.presentation_url); | 39 EXPECT_EQ(expected_info.presentation_url, actual_info.presentation_url); |
| 40 EXPECT_EQ(expected_info.presentation_id, actual_info.presentation_id); | 40 EXPECT_EQ(expected_info.presentation_id, actual_info.presentation_id); |
| 41 EXPECT_EQ(route.media_route_id(), kRouteId); | 41 EXPECT_EQ(route.media_route_id(), kRouteId); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void OnError(const content::PresentationError& expected_error, | 44 void OnError(const content::PresentationError& expected_error, |
| 45 const content::PresentationError& actual_error) { | 45 const content::PresentationError& actual_error) { |
| 46 cb_invoked_ = true; | 46 cb_invoked_ = true; |
| 47 EXPECT_EQ(expected_error.error_type, actual_error.error_type); | 47 EXPECT_EQ(expected_error.error_type, actual_error.error_type); |
| 48 EXPECT_EQ(expected_error.message, actual_error.message); | 48 EXPECT_EQ(expected_error.message, actual_error.message); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void FailOnSuccess(const content::PresentationSessionInfo& info, | 51 void FailOnSuccess(const content::PresentationInfo& info, |
| 52 const MediaRoute& route) { | 52 const MediaRoute& route) { |
| 53 FAIL() << "Success callback should not have been called."; | 53 FAIL() << "Success callback should not have been called."; |
| 54 } | 54 } |
| 55 | 55 |
| 56 void FailOnError(const content::PresentationError& error) { | 56 void FailOnError(const content::PresentationError& error) { |
| 57 FAIL() << "Error should not have been called."; | 57 FAIL() << "Error should not have been called."; |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool cb_invoked_; | 60 bool cb_invoked_; |
| 61 const RenderFrameHostId render_frame_host_id_; | 61 const RenderFrameHostId render_frame_host_id_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 75 base::Unretained(this), error)); | 75 base::Unretained(this), error)); |
| 76 | 76 |
| 77 PresentationRequest presentation_request( | 77 PresentationRequest presentation_request( |
| 78 render_frame_host_id_, presentation_urls_, url::Origin(GURL(kFrameUrl))); | 78 render_frame_host_id_, presentation_urls_, url::Origin(GURL(kFrameUrl))); |
| 79 EXPECT_TRUE(request.presentation_request().Equals(presentation_request)); | 79 EXPECT_TRUE(request.presentation_request().Equals(presentation_request)); |
| 80 // Since we didn't explicitly call Invoke*, the error callback will be | 80 // Since we didn't explicitly call Invoke*, the error callback will be |
| 81 // invoked when |request| is destroyed. | 81 // invoked when |request| is destroyed. |
| 82 } | 82 } |
| 83 | 83 |
| 84 TEST_F(CreatePresentationConnectionRequestTest, SuccessCallback) { | 84 TEST_F(CreatePresentationConnectionRequestTest, SuccessCallback) { |
| 85 content::PresentationSessionInfo session_info(presentation_url_, | 85 content::PresentationInfo presentation_info(presentation_url_, |
| 86 kPresentationId); | 86 kPresentationId); |
| 87 CreatePresentationConnectionRequest request( | 87 CreatePresentationConnectionRequest request( |
| 88 render_frame_host_id_, {presentation_url_}, url::Origin(GURL(kFrameUrl)), | 88 render_frame_host_id_, {presentation_url_}, url::Origin(GURL(kFrameUrl)), |
| 89 base::Bind(&CreatePresentationConnectionRequestTest::OnSuccess, | 89 base::Bind(&CreatePresentationConnectionRequestTest::OnSuccess, |
| 90 base::Unretained(this), session_info), | 90 base::Unretained(this), presentation_info), |
| 91 base::Bind(&CreatePresentationConnectionRequestTest::FailOnError, | 91 base::Bind(&CreatePresentationConnectionRequestTest::FailOnError, |
| 92 base::Unretained(this))); | 92 base::Unretained(this))); |
| 93 MediaRoute route(kRouteId, MediaSourceForTab(1), "sinkId", "Description", | 93 MediaRoute route(kRouteId, MediaSourceForTab(1), "sinkId", "Description", |
| 94 false, "", false); | 94 false, "", false); |
| 95 request.InvokeSuccessCallback(kPresentationId, presentation_url_, route); | 95 request.InvokeSuccessCallback(kPresentationId, presentation_url_, route); |
| 96 EXPECT_TRUE(cb_invoked_); | 96 EXPECT_TRUE(cb_invoked_); |
| 97 } | 97 } |
| 98 | 98 |
| 99 TEST_F(CreatePresentationConnectionRequestTest, ErrorCallback) { | 99 TEST_F(CreatePresentationConnectionRequestTest, ErrorCallback) { |
| 100 content::PresentationError error( | 100 content::PresentationError error( |
| 101 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, | 101 content::PRESENTATION_ERROR_PRESENTATION_REQUEST_CANCELLED, |
| 102 "This is an error message"); | 102 "This is an error message"); |
| 103 CreatePresentationConnectionRequest request( | 103 CreatePresentationConnectionRequest request( |
| 104 render_frame_host_id_, presentation_urls_, url::Origin(GURL(kFrameUrl)), | 104 render_frame_host_id_, presentation_urls_, url::Origin(GURL(kFrameUrl)), |
| 105 base::Bind(&CreatePresentationConnectionRequestTest::FailOnSuccess, | 105 base::Bind(&CreatePresentationConnectionRequestTest::FailOnSuccess, |
| 106 base::Unretained(this)), | 106 base::Unretained(this)), |
| 107 base::Bind(&CreatePresentationConnectionRequestTest::OnError, | 107 base::Bind(&CreatePresentationConnectionRequestTest::OnError, |
| 108 base::Unretained(this), error)); | 108 base::Unretained(this), error)); |
| 109 request.InvokeErrorCallback(error); | 109 request.InvokeErrorCallback(error); |
| 110 EXPECT_TRUE(cb_invoked_); | 110 EXPECT_TRUE(cb_invoked_); |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace media_router | 113 } // namespace media_router |
| OLD | NEW |