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