| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 const RenderFrameHostId render_frame_host_id_; | 61 const RenderFrameHostId render_frame_host_id_; |
| 62 GURL presentation_url_; | 62 GURL presentation_url_; |
| 63 std::vector<GURL> presentation_urls_; | 63 std::vector<GURL> presentation_urls_; |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 // Test that the object's getters match the constructor parameters. | 66 // Test that the object's getters match the constructor parameters. |
| 67 TEST_F(CreatePresentationConnectionRequestTest, Getters) { | 67 TEST_F(CreatePresentationConnectionRequestTest, Getters) { |
| 68 content::PresentationError error(content::PRESENTATION_ERROR_UNKNOWN, | 68 content::PresentationError error(content::PRESENTATION_ERROR_UNKNOWN, |
| 69 "Unknown error."); | 69 "Unknown error."); |
| 70 CreatePresentationConnectionRequest request( | 70 CreatePresentationConnectionRequest request( |
| 71 render_frame_host_id_, presentation_urls_, GURL(kFrameUrl), | 71 render_frame_host_id_, presentation_urls_, url::Origin(GURL(kFrameUrl)), |
| 72 base::Bind(&CreatePresentationConnectionRequestTest::FailOnSuccess, | 72 base::Bind(&CreatePresentationConnectionRequestTest::FailOnSuccess, |
| 73 base::Unretained(this)), | 73 base::Unretained(this)), |
| 74 base::Bind(&CreatePresentationConnectionRequestTest::OnError, | 74 base::Bind(&CreatePresentationConnectionRequestTest::OnError, |
| 75 base::Unretained(this), error)); | 75 base::Unretained(this), error)); |
| 76 | 76 |
| 77 PresentationRequest presentation_request(render_frame_host_id_, | 77 PresentationRequest presentation_request( |
| 78 presentation_urls_, 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::PresentationSessionInfo session_info(presentation_url_, |
| 86 kPresentationId); | 86 kPresentationId); |
| 87 CreatePresentationConnectionRequest request( | 87 CreatePresentationConnectionRequest request( |
| 88 render_frame_host_id_, {presentation_url_}, 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), session_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_SESSION_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_, 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 |