| 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_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://fooUrl"; | 15 const char kPresentationUrl[] = "http://foo.com"; |
| 16 const char kPresentationId[] = "presentationId"; | 16 const char kPresentationId[] = "presentationId"; |
| 17 const char kRouteId[] = |
| 18 "urn:x-org.chromium:media:route:presentationId/cast-sink1/http://foo.com"; |
| 17 | 19 |
| 18 } // namespace | 20 } // namespace |
| 19 | 21 |
| 20 class CreateSessionRequestTest : public ::testing::Test { | 22 class CreateSessionRequestTest : public ::testing::Test { |
| 21 public: | 23 public: |
| 22 CreateSessionRequestTest() : cb_invoked_(false) {} | 24 CreateSessionRequestTest() : cb_invoked_(false) {} |
| 23 ~CreateSessionRequestTest() override {} | 25 ~CreateSessionRequestTest() override {} |
| 24 | 26 |
| 25 void OnSuccess(const content::PresentationSessionInfo& expected_info, | 27 void OnSuccess(const content::PresentationSessionInfo& expected_info, |
| 26 const content::PresentationSessionInfo& actual_info, | 28 const content::PresentationSessionInfo& actual_info, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 TEST_F(CreateSessionRequestTest, SuccessCallback) { | 74 TEST_F(CreateSessionRequestTest, SuccessCallback) { |
| 73 GURL frame_url("http://frameUrl"); | 75 GURL frame_url("http://frameUrl"); |
| 74 content::PresentationSessionInfo session_info(kPresentationUrl, | 76 content::PresentationSessionInfo session_info(kPresentationUrl, |
| 75 kPresentationId); | 77 kPresentationId); |
| 76 CreateSessionRequest context( | 78 CreateSessionRequest context( |
| 77 kPresentationUrl, kPresentationId, frame_url, | 79 kPresentationUrl, kPresentationId, frame_url, |
| 78 base::Bind(&CreateSessionRequestTest::OnSuccess, base::Unretained(this), | 80 base::Bind(&CreateSessionRequestTest::OnSuccess, base::Unretained(this), |
| 79 session_info), | 81 session_info), |
| 80 base::Bind(&CreateSessionRequestTest::FailOnError, | 82 base::Bind(&CreateSessionRequestTest::FailOnError, |
| 81 base::Unretained(this))); | 83 base::Unretained(this))); |
| 82 context.MaybeInvokeSuccessCallback("routeid"); | 84 context.MaybeInvokeSuccessCallback(kRouteId); |
| 83 // No-op since success callback is already invoked. | 85 // No-op since success callback is already invoked. |
| 84 context.MaybeInvokeErrorCallback(content::PresentationError( | 86 context.MaybeInvokeErrorCallback(content::PresentationError( |
| 85 content::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "Error message")); | 87 content::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "Error message")); |
| 86 EXPECT_TRUE(cb_invoked_); | 88 EXPECT_TRUE(cb_invoked_); |
| 87 } | 89 } |
| 88 | 90 |
| 89 TEST_F(CreateSessionRequestTest, ErrorCallback) { | 91 TEST_F(CreateSessionRequestTest, ErrorCallback) { |
| 90 GURL frame_url("http://frameUrl"); | 92 GURL frame_url("http://frameUrl"); |
| 91 content::PresentationSessionInfo session_info(kPresentationUrl, | 93 content::PresentationSessionInfo session_info(kPresentationUrl, |
| 92 kPresentationId); | 94 kPresentationId); |
| 93 content::PresentationError error( | 95 content::PresentationError error( |
| 94 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, | 96 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, |
| 95 "This is an error message"); | 97 "This is an error message"); |
| 96 CreateSessionRequest context( | 98 CreateSessionRequest context( |
| 97 kPresentationUrl, kPresentationId, frame_url, | 99 kPresentationUrl, kPresentationId, frame_url, |
| 98 base::Bind(&CreateSessionRequestTest::FailOnSuccess, | 100 base::Bind(&CreateSessionRequestTest::FailOnSuccess, |
| 99 base::Unretained(this)), | 101 base::Unretained(this)), |
| 100 base::Bind(&CreateSessionRequestTest::OnError, base::Unretained(this), | 102 base::Bind(&CreateSessionRequestTest::OnError, base::Unretained(this), |
| 101 error)); | 103 error)); |
| 102 context.MaybeInvokeErrorCallback(error); | 104 context.MaybeInvokeErrorCallback(error); |
| 103 // No-op since error callback is already invoked. | 105 // No-op since error callback is already invoked. |
| 104 context.MaybeInvokeSuccessCallback("routeid"); | 106 context.MaybeInvokeSuccessCallback(kRouteId); |
| 105 EXPECT_TRUE(cb_invoked_); | 107 EXPECT_TRUE(cb_invoked_); |
| 106 } | 108 } |
| 107 | 109 |
| 108 } // namespace media_router | 110 } // namespace media_router |
| OLD | NEW |