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

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

Issue 1173753003: [Media Router] Implement JoinRoute + update CreateRoute API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Compile fix again x2 Created 5 years, 6 months 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
« no previous file with comments | « no previous file | chrome/browser/media/router/media_router.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/media/router/media_router.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698