| 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_session_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://fooUrl"; |
| 16 const char kPresentationId[] = "presentationId"; |
| 17 |
| 18 } // namespace |
| 19 |
| 20 class CreateSessionRequestTest : public ::testing::Test { |
| 21 public: |
| 22 CreateSessionRequestTest() : cb_invoked_(false) {} |
| 23 ~CreateSessionRequestTest() override {} |
| 24 |
| 25 void OnSuccess(const content::PresentationSessionInfo& expected_info, |
| 26 const content::PresentationSessionInfo& actual_info) { |
| 27 cb_invoked_ = true; |
| 28 EXPECT_EQ(expected_info.presentation_url, actual_info.presentation_url); |
| 29 EXPECT_EQ(expected_info.presentation_id, actual_info.presentation_id); |
| 30 } |
| 31 |
| 32 void OnError(const content::PresentationError& expected_error, |
| 33 const content::PresentationError& actual_error) { |
| 34 cb_invoked_ = true; |
| 35 EXPECT_EQ(expected_error.error_type, actual_error.error_type); |
| 36 EXPECT_EQ(expected_error.message, actual_error.message); |
| 37 } |
| 38 |
| 39 void FailOnSuccess(const content::PresentationSessionInfo& info) { |
| 40 FAIL() << "Success callback should not have been called."; |
| 41 } |
| 42 |
| 43 void FailOnError(const content::PresentationError& error) { |
| 44 FAIL() << "Error should not have been called."; |
| 45 } |
| 46 |
| 47 bool cb_invoked_; |
| 48 }; |
| 49 |
| 50 // Test that the object's getters match the constructor parameters. |
| 51 TEST_F(CreateSessionRequestTest, Getters) { |
| 52 GURL frame_url("http://frameUrl"); |
| 53 |
| 54 content::PresentationSessionInfo session_info(kPresentationUrl, |
| 55 kPresentationId); |
| 56 |
| 57 CreateSessionRequest context( |
| 58 kPresentationUrl, kPresentationId, frame_url, |
| 59 CreateSessionRequest::PresentationSessionSuccessCallback(), |
| 60 CreateSessionRequest::PresentationSessionErrorCallback()); |
| 61 EXPECT_TRUE(MediaSourceForPresentationUrl(kPresentationUrl) |
| 62 .Equals(context.GetMediaSource())); |
| 63 EXPECT_EQ(frame_url, context.frame_url()); |
| 64 content::PresentationSessionInfo actual_session_info( |
| 65 context.presentation_info()); |
| 66 EXPECT_EQ(kPresentationUrl, actual_session_info.presentation_url); |
| 67 EXPECT_EQ(kPresentationId, actual_session_info.presentation_id); |
| 68 } |
| 69 |
| 70 TEST_F(CreateSessionRequestTest, SuccessCallback) { |
| 71 GURL frame_url("http://frameUrl"); |
| 72 content::PresentationSessionInfo session_info(kPresentationUrl, |
| 73 kPresentationId); |
| 74 CreateSessionRequest context( |
| 75 kPresentationUrl, kPresentationId, frame_url, |
| 76 base::Bind(&CreateSessionRequestTest::OnSuccess, base::Unretained(this), |
| 77 session_info), |
| 78 base::Bind(&CreateSessionRequestTest::FailOnError, |
| 79 base::Unretained(this))); |
| 80 context.MaybeInvokeSuccessCallback(); |
| 81 // No-op since success callback is already invoked. |
| 82 context.MaybeInvokeErrorCallback(content::PresentationError( |
| 83 content::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "Error message")); |
| 84 EXPECT_TRUE(cb_invoked_); |
| 85 } |
| 86 |
| 87 TEST_F(CreateSessionRequestTest, ErrorCallback) { |
| 88 GURL frame_url("http://frameUrl"); |
| 89 content::PresentationSessionInfo session_info(kPresentationUrl, |
| 90 kPresentationId); |
| 91 content::PresentationError error( |
| 92 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, |
| 93 "This is an error message"); |
| 94 CreateSessionRequest context( |
| 95 kPresentationUrl, kPresentationId, frame_url, |
| 96 base::Bind(&CreateSessionRequestTest::FailOnSuccess, |
| 97 base::Unretained(this)), |
| 98 base::Bind(&CreateSessionRequestTest::OnError, base::Unretained(this), |
| 99 error)); |
| 100 context.MaybeInvokeErrorCallback(error); |
| 101 // No-op since error callback is already invoked. |
| 102 context.MaybeInvokeSuccessCallback(); |
| 103 EXPECT_TRUE(cb_invoked_); |
| 104 } |
| 105 |
| 106 } // namespace media_router |
| OLD | NEW |