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

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

Issue 1224093004: [Media Router] 2nd take on fix route response callback lifetime in UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit test Created 5 years, 5 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
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://foo.com";
16 const char kPresentationId[] = "presentationId";
17 const char kRouteId[] =
18 "urn:x-org.chromium:media:route:presentationId/cast-sink1/http://foo.com";
19
20 } // namespace
21
22 class CreateSessionRequestTest : public ::testing::Test {
23 public:
24 CreateSessionRequestTest() : cb_invoked_(false) {}
25 ~CreateSessionRequestTest() override {}
26
27 void OnSuccess(const content::PresentationSessionInfo& expected_info,
28 const content::PresentationSessionInfo& actual_info,
29 const MediaRoute::Id& route_id) {
30 cb_invoked_ = true;
31 EXPECT_EQ(expected_info.presentation_url, actual_info.presentation_url);
32 EXPECT_EQ(expected_info.presentation_id, actual_info.presentation_id);
33 }
34
35 void OnError(const content::PresentationError& expected_error,
36 const content::PresentationError& actual_error) {
37 cb_invoked_ = true;
38 EXPECT_EQ(expected_error.error_type, actual_error.error_type);
39 EXPECT_EQ(expected_error.message, actual_error.message);
40 }
41
42 void FailOnSuccess(const content::PresentationSessionInfo& info,
43 const MediaRoute::Id& route_id) {
44 FAIL() << "Success callback should not have been called.";
45 }
46
47 void FailOnError(const content::PresentationError& error) {
48 FAIL() << "Error should not have been called.";
49 }
50
51 bool cb_invoked_;
52 };
53
54 // Test that the object's getters match the constructor parameters.
55 TEST_F(CreateSessionRequestTest, Getters) {
56 GURL frame_url("http://frameUrl");
57
58 content::PresentationSessionInfo session_info(kPresentationUrl,
59 kPresentationId);
60
61 CreateSessionRequest context(
62 kPresentationUrl, kPresentationId, frame_url,
63 CreateSessionRequest::PresentationSessionSuccessCallback(),
64 CreateSessionRequest::PresentationSessionErrorCallback());
65 EXPECT_TRUE(MediaSourceForPresentationUrl(kPresentationUrl)
66 .Equals(context.GetMediaSource()));
67 EXPECT_EQ(frame_url, context.frame_url());
68 content::PresentationSessionInfo actual_session_info(
69 context.presentation_info());
70 EXPECT_EQ(kPresentationUrl, actual_session_info.presentation_url);
71 EXPECT_EQ(kPresentationId, actual_session_info.presentation_id);
72 }
73
74 TEST_F(CreateSessionRequestTest, SuccessCallback) {
75 GURL frame_url("http://frameUrl");
76 content::PresentationSessionInfo session_info(kPresentationUrl,
77 kPresentationId);
78 CreateSessionRequest context(
79 kPresentationUrl, kPresentationId, frame_url,
80 base::Bind(&CreateSessionRequestTest::OnSuccess, base::Unretained(this),
81 session_info),
82 base::Bind(&CreateSessionRequestTest::FailOnError,
83 base::Unretained(this)));
84 context.MaybeInvokeSuccessCallback(kRouteId);
85 // No-op since success callback is already invoked.
86 context.MaybeInvokeErrorCallback(content::PresentationError(
87 content::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "Error message"));
88 EXPECT_TRUE(cb_invoked_);
89 }
90
91 TEST_F(CreateSessionRequestTest, ErrorCallback) {
92 GURL frame_url("http://frameUrl");
93 content::PresentationSessionInfo session_info(kPresentationUrl,
94 kPresentationId);
95 content::PresentationError error(
96 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED,
97 "This is an error message");
98 CreateSessionRequest context(
99 kPresentationUrl, kPresentationId, frame_url,
100 base::Bind(&CreateSessionRequestTest::FailOnSuccess,
101 base::Unretained(this)),
102 base::Bind(&CreateSessionRequestTest::OnError, base::Unretained(this),
103 error));
104 context.MaybeInvokeErrorCallback(error);
105 // No-op since error callback is already invoked.
106 context.MaybeInvokeSuccessCallback(kRouteId);
107 EXPECT_TRUE(cb_invoked_);
108 }
109
110 } // namespace media_router
OLDNEW
« no previous file with comments | « chrome/browser/media/router/create_session_request.cc ('k') | chrome/browser/media/router/media_router.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698