Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: chrome/browser/media/router/create_presentation_connection_request_unittest.cc

Issue 2547703002: [Media Router] Handle multiple Presentation URLs when creating routes (Closed)
Patch Set: fix unittests Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 kPresentationUrl1[] = "http://www.example.com/presentation.html";
16 const char kPresentationUrl2[] = "http://www.example.net/alternate.html";
16 const char kFrameUrl[] = "http://google.com"; 17 const char kFrameUrl[] = "http://google.com";
17 const char kPresentationId[] = "presentationId"; 18 const char kPresentationId[] = "presentationId";
18 const char kRouteId[] = 19 const char kRouteId[] =
19 "urn:x-org.chromium:media:route:presentationId/cast-sink1/http://foo.com"; 20 "urn:x-org.chromium:media:route:presentationId/cast-sink1/"
21 "http://www.example.com/presentation.html";
20 22
21 } // namespace 23 } // namespace
22 24
23 class CreatePresentationConnectionRequestTest : public ::testing::Test { 25 class CreatePresentationConnectionRequestTest : public ::testing::Test {
24 public: 26 public:
25 CreatePresentationConnectionRequestTest() 27 CreatePresentationConnectionRequestTest()
26 : cb_invoked_(false), 28 : cb_invoked_(false),
27 render_frame_host_id_(1, 2), 29 render_frame_host_id_(1, 2),
28 presentation_url_(kPresentationUrl), 30 presentation_url_(kPresentationUrl1),
29 presentation_urls_({presentation_url_}) {} 31 presentation_urls_({presentation_url_, GURL(kPresentationUrl2)}) {}
30 32
31 ~CreatePresentationConnectionRequestTest() override {} 33 ~CreatePresentationConnectionRequestTest() override {}
32 34
33 void OnSuccess(const content::PresentationSessionInfo& expected_info, 35 void OnSuccess(const content::PresentationSessionInfo& expected_info,
34 const content::PresentationSessionInfo& actual_info, 36 const content::PresentationSessionInfo& actual_info,
35 const MediaRoute& route) { 37 const MediaRoute& route) {
36 cb_invoked_ = true; 38 cb_invoked_ = true;
37 EXPECT_EQ(expected_info.presentation_url, actual_info.presentation_url); 39 EXPECT_EQ(expected_info.presentation_url, actual_info.presentation_url);
38 EXPECT_EQ(expected_info.presentation_id, actual_info.presentation_id); 40 EXPECT_EQ(expected_info.presentation_id, actual_info.presentation_id);
41 EXPECT_EQ(route.media_route_id(), kRouteId);
39 } 42 }
40 43
41 void OnError(const content::PresentationError& expected_error, 44 void OnError(const content::PresentationError& expected_error,
42 const content::PresentationError& actual_error) { 45 const content::PresentationError& actual_error) {
43 cb_invoked_ = true; 46 cb_invoked_ = true;
44 EXPECT_EQ(expected_error.error_type, actual_error.error_type); 47 EXPECT_EQ(expected_error.error_type, actual_error.error_type);
45 EXPECT_EQ(expected_error.message, actual_error.message); 48 EXPECT_EQ(expected_error.message, actual_error.message);
46 } 49 }
47 50
48 void FailOnSuccess(const content::PresentationSessionInfo& info, 51 void FailOnSuccess(const content::PresentationSessionInfo& info,
49 const MediaRoute& route) { 52 const MediaRoute& route) {
50 FAIL() << "Success callback should not have been called."; 53 FAIL() << "Success callback should not have been called.";
51 } 54 }
52 55
53 void FailOnError(const content::PresentationError& error) { 56 void FailOnError(const content::PresentationError& error) {
54 FAIL() << "Error should not have been called."; 57 FAIL() << "Error should not have been called.";
55 } 58 }
56 59
57 bool cb_invoked_; 60 bool cb_invoked_;
58 const RenderFrameHostId render_frame_host_id_; 61 const RenderFrameHostId render_frame_host_id_;
59 GURL presentation_url_; 62 GURL presentation_url_;
60 std::vector<GURL> presentation_urls_; 63 std::vector<GURL> presentation_urls_;
61 }; 64 };
62 65
63 // Test that the object's getters match the constructor parameters. 66 // Test that the object's getters match the constructor parameters.
64 TEST_F(CreatePresentationConnectionRequestTest, Getters) { 67 TEST_F(CreatePresentationConnectionRequestTest, Getters) {
65 content::PresentationError error(content::PRESENTATION_ERROR_UNKNOWN, 68 content::PresentationError error(content::PRESENTATION_ERROR_UNKNOWN,
66 "Unknown error."); 69 "Unknown error.");
67 CreatePresentationConnectionRequest request( 70 CreatePresentationConnectionRequest request(
68 render_frame_host_id_, presentation_url_, GURL(kFrameUrl), 71 render_frame_host_id_, presentation_urls_, GURL(kFrameUrl),
69 base::Bind(&CreatePresentationConnectionRequestTest::FailOnSuccess, 72 base::Bind(&CreatePresentationConnectionRequestTest::FailOnSuccess,
70 base::Unretained(this)), 73 base::Unretained(this)),
71 base::Bind(&CreatePresentationConnectionRequestTest::OnError, 74 base::Bind(&CreatePresentationConnectionRequestTest::OnError,
72 base::Unretained(this), error)); 75 base::Unretained(this), error));
73 76
74 PresentationRequest presentation_request(render_frame_host_id_, 77 PresentationRequest presentation_request(render_frame_host_id_,
75 presentation_urls_, GURL(kFrameUrl)); 78 presentation_urls_, GURL(kFrameUrl));
76 EXPECT_TRUE(request.presentation_request().Equals(presentation_request)); 79 EXPECT_TRUE(request.presentation_request().Equals(presentation_request));
77 // 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
78 // invoked when |request| is destroyed. 81 // invoked when |request| is destroyed.
79 } 82 }
80 83
81 TEST_F(CreatePresentationConnectionRequestTest, SuccessCallback) { 84 TEST_F(CreatePresentationConnectionRequestTest, SuccessCallback) {
82 content::PresentationSessionInfo session_info(presentation_url_, 85 content::PresentationSessionInfo session_info(presentation_url_,
83 kPresentationId); 86 kPresentationId);
84 CreatePresentationConnectionRequest request( 87 CreatePresentationConnectionRequest request(
85 render_frame_host_id_, presentation_url_, GURL(kFrameUrl), 88 render_frame_host_id_, {presentation_url_}, GURL(kFrameUrl),
86 base::Bind(&CreatePresentationConnectionRequestTest::OnSuccess, 89 base::Bind(&CreatePresentationConnectionRequestTest::OnSuccess,
87 base::Unretained(this), session_info), 90 base::Unretained(this), session_info),
88 base::Bind(&CreatePresentationConnectionRequestTest::FailOnError, 91 base::Bind(&CreatePresentationConnectionRequestTest::FailOnError,
89 base::Unretained(this))); 92 base::Unretained(this)));
90 MediaRoute route(kRouteId, MediaSourceForTab(1), "sinkId", "Description", 93 MediaRoute route(kRouteId, MediaSourceForTab(1), "sinkId", "Description",
91 false, "", false); 94 false, "", false);
92 request.InvokeSuccessCallback(kPresentationId, route); 95 request.InvokeSuccessCallback(kPresentationId, presentation_url_, route);
93 EXPECT_TRUE(cb_invoked_); 96 EXPECT_TRUE(cb_invoked_);
94 } 97 }
95 98
96 TEST_F(CreatePresentationConnectionRequestTest, ErrorCallback) { 99 TEST_F(CreatePresentationConnectionRequestTest, ErrorCallback) {
97 content::PresentationError error( 100 content::PresentationError error(
98 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, 101 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED,
99 "This is an error message"); 102 "This is an error message");
100 CreatePresentationConnectionRequest request( 103 CreatePresentationConnectionRequest request(
101 render_frame_host_id_, presentation_url_, GURL(kFrameUrl), 104 render_frame_host_id_, presentation_urls_, GURL(kFrameUrl),
102 base::Bind(&CreatePresentationConnectionRequestTest::FailOnSuccess, 105 base::Bind(&CreatePresentationConnectionRequestTest::FailOnSuccess,
103 base::Unretained(this)), 106 base::Unretained(this)),
104 base::Bind(&CreatePresentationConnectionRequestTest::OnError, 107 base::Bind(&CreatePresentationConnectionRequestTest::OnError,
105 base::Unretained(this), error)); 108 base::Unretained(this), error));
106 request.InvokeErrorCallback(error); 109 request.InvokeErrorCallback(error);
107 EXPECT_TRUE(cb_invoked_); 110 EXPECT_TRUE(cb_invoked_);
108 } 111 }
109 112
110 } // namespace media_router 113 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698