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

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

Issue 1406013003: [Presentation API / Media Router] Clean up default pres URL logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile Created 5 years, 1 month 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_session_request.h" 6 #include "chrome/browser/media/router/create_presentation_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://foo.com"; 15 const char kPresentationUrl[] = "http://foo.com";
16 const char kFrameUrl[] = "http://frameUrl";
mark a. foltz 2015/11/04 02:07:24 Please use a fully qualified URL as test data. Ot
imcheng 2015/11/04 20:35:19 Done.
16 const char kPresentationId[] = "presentationId"; 17 const char kPresentationId[] = "presentationId";
17 const char kRouteId[] = 18 const char kRouteId[] =
18 "urn:x-org.chromium:media:route:presentationId/cast-sink1/http://foo.com"; 19 "urn:x-org.chromium:media:route:presentationId/cast-sink1/http://foo.com";
19 20
20 } // namespace 21 } // namespace
21 22
22 class CreatePresentationSessionRequestTest : public ::testing::Test { 23 class CreatePresentationSessionRequestTest : public ::testing::Test {
23 public: 24 public:
24 CreatePresentationSessionRequestTest() : cb_invoked_(false) {} 25 CreatePresentationSessionRequestTest()
26 : cb_invoked_(false), render_frame_host_id_(1, 2) {}
25 ~CreatePresentationSessionRequestTest() override {} 27 ~CreatePresentationSessionRequestTest() override {}
26 28
27 void OnSuccess(const content::PresentationSessionInfo& expected_info, 29 void OnSuccess(const content::PresentationSessionInfo& expected_info,
28 const content::PresentationSessionInfo& actual_info, 30 const content::PresentationSessionInfo& actual_info,
29 const MediaRoute::Id& route_id) { 31 const MediaRoute::Id& route_id) {
30 cb_invoked_ = true; 32 cb_invoked_ = true;
31 EXPECT_EQ(expected_info.presentation_url, actual_info.presentation_url); 33 EXPECT_EQ(expected_info.presentation_url, actual_info.presentation_url);
32 EXPECT_EQ(expected_info.presentation_id, actual_info.presentation_id); 34 EXPECT_EQ(expected_info.presentation_id, actual_info.presentation_id);
33 } 35 }
34 36
35 void OnError(const content::PresentationError& expected_error, 37 void OnError(const content::PresentationError& expected_error,
36 const content::PresentationError& actual_error) { 38 const content::PresentationError& actual_error) {
37 cb_invoked_ = true; 39 cb_invoked_ = true;
38 EXPECT_EQ(expected_error.error_type, actual_error.error_type); 40 EXPECT_EQ(expected_error.error_type, actual_error.error_type);
39 EXPECT_EQ(expected_error.message, actual_error.message); 41 EXPECT_EQ(expected_error.message, actual_error.message);
40 } 42 }
41 43
42 void FailOnSuccess(const content::PresentationSessionInfo& info, 44 void FailOnSuccess(const content::PresentationSessionInfo& info,
43 const MediaRoute::Id& route_id) { 45 const MediaRoute::Id& route_id) {
44 FAIL() << "Success callback should not have been called."; 46 FAIL() << "Success callback should not have been called.";
45 } 47 }
46 48
47 void FailOnError(const content::PresentationError& error) { 49 void FailOnError(const content::PresentationError& error) {
48 FAIL() << "Error should not have been called."; 50 FAIL() << "Error should not have been called.";
49 } 51 }
50 52
51 bool cb_invoked_; 53 bool cb_invoked_;
54 const RenderFrameHostId render_frame_host_id_;
52 }; 55 };
53 56
54 // Test that the object's getters match the constructor parameters. 57 // Test that the object's getters match the constructor parameters.
55 TEST_F(CreatePresentationSessionRequestTest, Getters) { 58 TEST_F(CreatePresentationSessionRequestTest, Getters) {
56 GURL frame_url("http://frameUrl");
57 content::PresentationError error(content::PRESENTATION_ERROR_UNKNOWN, 59 content::PresentationError error(content::PRESENTATION_ERROR_UNKNOWN,
58 "Unknown error."); 60 "Unknown error.");
59 CreatePresentationSessionRequest request( 61 CreatePresentationSessionRequest request(
60 kPresentationUrl, frame_url, 62 render_frame_host_id_, kPresentationUrl, GURL(kFrameUrl),
61 base::Bind(&CreatePresentationSessionRequestTest::FailOnSuccess, 63 base::Bind(&CreatePresentationSessionRequestTest::FailOnSuccess,
62 base::Unretained(this)), 64 base::Unretained(this)),
63 base::Bind(&CreatePresentationSessionRequestTest::OnError, 65 base::Bind(&CreatePresentationSessionRequestTest::OnError,
64 base::Unretained(this), error)); 66 base::Unretained(this), error));
65 EXPECT_EQ(frame_url, request.frame_url()); 67
66 EXPECT_EQ(kPresentationUrl, 68 PresentationRequest presentation_request(render_frame_host_id_,
67 PresentationUrlFromMediaSource(request.media_source())); 69 kPresentationUrl, GURL(kFrameUrl));
70 EXPECT_TRUE(request.presentation_request().Equals(presentation_request));
68 // Since we didn't explicitly call Invoke*, the error callback will be 71 // Since we didn't explicitly call Invoke*, the error callback will be
69 // invoked when |request| is destroyed. 72 // invoked when |request| is destroyed.
70 } 73 }
71 74
72 TEST_F(CreatePresentationSessionRequestTest, SuccessCallback) { 75 TEST_F(CreatePresentationSessionRequestTest, SuccessCallback) {
73 GURL frame_url("http://frameUrl");
74 content::PresentationSessionInfo session_info(kPresentationUrl, 76 content::PresentationSessionInfo session_info(kPresentationUrl,
75 kPresentationId); 77 kPresentationId);
76 CreatePresentationSessionRequest request( 78 CreatePresentationSessionRequest request(
77 kPresentationUrl, frame_url, 79 render_frame_host_id_, kPresentationUrl, GURL(kFrameUrl),
78 base::Bind(&CreatePresentationSessionRequestTest::OnSuccess, 80 base::Bind(&CreatePresentationSessionRequestTest::OnSuccess,
79 base::Unretained(this), session_info), 81 base::Unretained(this), session_info),
80 base::Bind(&CreatePresentationSessionRequestTest::FailOnError, 82 base::Bind(&CreatePresentationSessionRequestTest::FailOnError,
81 base::Unretained(this))); 83 base::Unretained(this)));
82 request.InvokeSuccessCallback(kPresentationId, kRouteId); 84 request.InvokeSuccessCallback(kPresentationId, kRouteId);
83 EXPECT_TRUE(cb_invoked_); 85 EXPECT_TRUE(cb_invoked_);
84 } 86 }
85 87
86 TEST_F(CreatePresentationSessionRequestTest, ErrorCallback) { 88 TEST_F(CreatePresentationSessionRequestTest, ErrorCallback) {
87 GURL frame_url("http://frameUrl");
88 content::PresentationSessionInfo session_info(kPresentationUrl,
89 kPresentationId);
90 content::PresentationError error( 89 content::PresentationError error(
91 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, 90 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED,
92 "This is an error message"); 91 "This is an error message");
93 CreatePresentationSessionRequest request( 92 CreatePresentationSessionRequest request(
94 kPresentationUrl, frame_url, 93 render_frame_host_id_, kPresentationUrl, GURL(kFrameUrl),
95 base::Bind(&CreatePresentationSessionRequestTest::FailOnSuccess, 94 base::Bind(&CreatePresentationSessionRequestTest::FailOnSuccess,
96 base::Unretained(this)), 95 base::Unretained(this)),
97 base::Bind(&CreatePresentationSessionRequestTest::OnError, 96 base::Bind(&CreatePresentationSessionRequestTest::OnError,
98 base::Unretained(this), error)); 97 base::Unretained(this), error));
99 request.InvokeErrorCallback(error); 98 request.InvokeErrorCallback(error);
100 EXPECT_TRUE(cb_invoked_); 99 EXPECT_TRUE(cb_invoked_);
101 } 100 }
102 101
103 } // namespace media_router 102 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698