Chromium Code Reviews| 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 |
| 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 kFrameUrl[] = "http://google.com"; | 16 const char kFrameUrl[] = "http://google.com"; |
| 17 const char kPresentationId[] = "presentationId"; | 17 const char kPresentationId[] = "presentationId"; |
| 18 const char kRouteId[] = | 18 const char kRouteId[] = |
| 19 "urn:x-org.chromium:media:route:presentationId/cast-sink1/http://foo.com"; | 19 "urn:x-org.chromium:media:route:presentationId/cast-sink1/http://foo.com"; |
| 20 | 20 |
| 21 } // namespace | 21 } // namespace |
| 22 | 22 |
| 23 class CreatePresentationConnectionRequestTest : public ::testing::Test { | 23 class CreatePresentationConnectionRequestTest : public ::testing::Test { |
| 24 public: | 24 public: |
| 25 CreatePresentationConnectionRequestTest() | 25 CreatePresentationConnectionRequestTest() |
| 26 : cb_invoked_(false), render_frame_host_id_(1, 2) {} | 26 : cb_invoked_(false), |
| 27 render_frame_host_id_(1, 2), | |
| 28 presentation_url_(kPresentationUrl) {} | |
|
imcheng
2016/10/07 00:38:36
presentation_urls_(kPresentationUrl, 1)
or
prese
mark a. foltz
2016/10/07 23:14:10
Done.
| |
| 27 ~CreatePresentationConnectionRequestTest() override {} | 29 ~CreatePresentationConnectionRequestTest() override {} |
| 28 | 30 |
| 31 void SetUp() override { presentation_urls_.push_back(presentation_url_); } | |
| 32 | |
| 29 void OnSuccess(const content::PresentationSessionInfo& expected_info, | 33 void OnSuccess(const content::PresentationSessionInfo& expected_info, |
| 30 const content::PresentationSessionInfo& actual_info, | 34 const content::PresentationSessionInfo& actual_info, |
| 31 const MediaRoute::Id& route_id) { | 35 const MediaRoute::Id& route_id) { |
| 32 cb_invoked_ = true; | 36 cb_invoked_ = true; |
| 33 EXPECT_EQ(expected_info.presentation_url, actual_info.presentation_url); | 37 EXPECT_EQ(expected_info.presentation_url, actual_info.presentation_url); |
| 34 EXPECT_EQ(expected_info.presentation_id, actual_info.presentation_id); | 38 EXPECT_EQ(expected_info.presentation_id, actual_info.presentation_id); |
| 35 } | 39 } |
| 36 | 40 |
| 37 void OnError(const content::PresentationError& expected_error, | 41 void OnError(const content::PresentationError& expected_error, |
| 38 const content::PresentationError& actual_error) { | 42 const content::PresentationError& actual_error) { |
| 39 cb_invoked_ = true; | 43 cb_invoked_ = true; |
| 40 EXPECT_EQ(expected_error.error_type, actual_error.error_type); | 44 EXPECT_EQ(expected_error.error_type, actual_error.error_type); |
| 41 EXPECT_EQ(expected_error.message, actual_error.message); | 45 EXPECT_EQ(expected_error.message, actual_error.message); |
| 42 } | 46 } |
| 43 | 47 |
| 44 void FailOnSuccess(const content::PresentationSessionInfo& info, | 48 void FailOnSuccess(const content::PresentationSessionInfo& info, |
| 45 const MediaRoute::Id& route_id) { | 49 const MediaRoute::Id& route_id) { |
| 46 FAIL() << "Success callback should not have been called."; | 50 FAIL() << "Success callback should not have been called."; |
| 47 } | 51 } |
| 48 | 52 |
| 49 void FailOnError(const content::PresentationError& error) { | 53 void FailOnError(const content::PresentationError& error) { |
| 50 FAIL() << "Error should not have been called."; | 54 FAIL() << "Error should not have been called."; |
| 51 } | 55 } |
| 52 | 56 |
| 53 bool cb_invoked_; | 57 bool cb_invoked_; |
| 54 const RenderFrameHostId render_frame_host_id_; | 58 const RenderFrameHostId render_frame_host_id_; |
| 59 GURL presentation_url_; | |
| 60 std::vector<GURL> presentation_urls_; | |
| 55 }; | 61 }; |
| 56 | 62 |
| 57 // Test that the object's getters match the constructor parameters. | 63 // Test that the object's getters match the constructor parameters. |
| 58 TEST_F(CreatePresentationConnectionRequestTest, Getters) { | 64 TEST_F(CreatePresentationConnectionRequestTest, Getters) { |
| 59 content::PresentationError error(content::PRESENTATION_ERROR_UNKNOWN, | 65 content::PresentationError error(content::PRESENTATION_ERROR_UNKNOWN, |
| 60 "Unknown error."); | 66 "Unknown error."); |
| 61 CreatePresentationConnectionRequest request( | 67 CreatePresentationConnectionRequest request( |
| 62 render_frame_host_id_, kPresentationUrl, GURL(kFrameUrl), | 68 render_frame_host_id_, presentation_url_, GURL(kFrameUrl), |
| 63 base::Bind(&CreatePresentationConnectionRequestTest::FailOnSuccess, | 69 base::Bind(&CreatePresentationConnectionRequestTest::FailOnSuccess, |
| 64 base::Unretained(this)), | 70 base::Unretained(this)), |
| 65 base::Bind(&CreatePresentationConnectionRequestTest::OnError, | 71 base::Bind(&CreatePresentationConnectionRequestTest::OnError, |
| 66 base::Unretained(this), error)); | 72 base::Unretained(this), error)); |
| 67 | 73 |
| 68 PresentationRequest presentation_request(render_frame_host_id_, | 74 PresentationRequest presentation_request(render_frame_host_id_, |
| 69 {kPresentationUrl}, GURL(kFrameUrl)); | 75 presentation_urls_, GURL(kFrameUrl)); |
| 70 EXPECT_TRUE(request.presentation_request().Equals(presentation_request)); | 76 EXPECT_TRUE(request.presentation_request().Equals(presentation_request)); |
| 71 // Since we didn't explicitly call Invoke*, the error callback will be | 77 // Since we didn't explicitly call Invoke*, the error callback will be |
| 72 // invoked when |request| is destroyed. | 78 // invoked when |request| is destroyed. |
| 73 } | 79 } |
| 74 | 80 |
| 75 TEST_F(CreatePresentationConnectionRequestTest, SuccessCallback) { | 81 TEST_F(CreatePresentationConnectionRequestTest, SuccessCallback) { |
| 76 content::PresentationSessionInfo session_info(kPresentationUrl, | 82 content::PresentationSessionInfo session_info(presentation_url_, |
| 77 kPresentationId); | 83 kPresentationId); |
| 78 CreatePresentationConnectionRequest request( | 84 CreatePresentationConnectionRequest request( |
| 79 render_frame_host_id_, kPresentationUrl, GURL(kFrameUrl), | 85 render_frame_host_id_, presentation_url_, GURL(kFrameUrl), |
| 80 base::Bind(&CreatePresentationConnectionRequestTest::OnSuccess, | 86 base::Bind(&CreatePresentationConnectionRequestTest::OnSuccess, |
| 81 base::Unretained(this), session_info), | 87 base::Unretained(this), session_info), |
| 82 base::Bind(&CreatePresentationConnectionRequestTest::FailOnError, | 88 base::Bind(&CreatePresentationConnectionRequestTest::FailOnError, |
| 83 base::Unretained(this))); | 89 base::Unretained(this))); |
| 84 request.InvokeSuccessCallback(kPresentationId, kRouteId); | 90 request.InvokeSuccessCallback(kPresentationId, kRouteId); |
| 85 EXPECT_TRUE(cb_invoked_); | 91 EXPECT_TRUE(cb_invoked_); |
| 86 } | 92 } |
| 87 | 93 |
| 88 TEST_F(CreatePresentationConnectionRequestTest, ErrorCallback) { | 94 TEST_F(CreatePresentationConnectionRequestTest, ErrorCallback) { |
| 89 content::PresentationError error( | 95 content::PresentationError error( |
| 90 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, | 96 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, |
| 91 "This is an error message"); | 97 "This is an error message"); |
| 92 CreatePresentationConnectionRequest request( | 98 CreatePresentationConnectionRequest request( |
| 93 render_frame_host_id_, kPresentationUrl, GURL(kFrameUrl), | 99 render_frame_host_id_, presentation_url_, GURL(kFrameUrl), |
| 94 base::Bind(&CreatePresentationConnectionRequestTest::FailOnSuccess, | 100 base::Bind(&CreatePresentationConnectionRequestTest::FailOnSuccess, |
| 95 base::Unretained(this)), | 101 base::Unretained(this)), |
| 96 base::Bind(&CreatePresentationConnectionRequestTest::OnError, | 102 base::Bind(&CreatePresentationConnectionRequestTest::OnError, |
| 97 base::Unretained(this), error)); | 103 base::Unretained(this), error)); |
| 98 request.InvokeErrorCallback(error); | 104 request.InvokeErrorCallback(error); |
| 99 EXPECT_TRUE(cb_invoked_); | 105 EXPECT_TRUE(cb_invoked_); |
| 100 } | 106 } |
| 101 | 107 |
| 102 } // namespace media_router | 108 } // namespace media_router |
| OLD | NEW |