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

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: Original patch 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
(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_presentation_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 CreatePresentationSessionRequestTest : public ::testing::Test {
23 public:
24 CreatePresentationSessionRequestTest() : cb_invoked_(false) {}
25 ~CreatePresentationSessionRequestTest() 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(CreatePresentationSessionRequestTest, Getters) {
56 GURL frame_url("http://frameUrl");
57 content::PresentationError error(content::PRESENTATION_ERROR_UNKNOWN,
58 "Unknown error.");
59 CreatePresentationSessionRequest request(
60 kPresentationUrl, frame_url,
61 base::Bind(&CreatePresentationSessionRequestTest::FailOnSuccess,
62 base::Unretained(this)),
63 base::Bind(&CreatePresentationSessionRequestTest::OnError,
64 base::Unretained(this), error));
65 EXPECT_EQ(frame_url, request.frame_url());
66 EXPECT_EQ(kPresentationUrl,
67 PresentationUrlFromMediaSource(request.media_source()));
68 // Since we didn't explicitly call Invoke*, the error callback will be
69 // invoked when |request| is destroyed.
70 }
71
72 TEST_F(CreatePresentationSessionRequestTest, SuccessCallback) {
73 GURL frame_url("http://frameUrl");
74 content::PresentationSessionInfo session_info(kPresentationUrl,
75 kPresentationId);
76 CreatePresentationSessionRequest request(
77 kPresentationUrl, frame_url,
78 base::Bind(&CreatePresentationSessionRequestTest::OnSuccess,
79 base::Unretained(this), session_info),
80 base::Bind(&CreatePresentationSessionRequestTest::FailOnError,
81 base::Unretained(this)));
82 request.InvokeSuccessCallback(kPresentationId, kRouteId);
83 EXPECT_TRUE(cb_invoked_);
84 }
85
86 TEST_F(CreatePresentationSessionRequestTest, ErrorCallback) {
87 GURL frame_url("http://frameUrl");
88 content::PresentationSessionInfo session_info(kPresentationUrl,
89 kPresentationId);
90 content::PresentationError error(
91 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED,
92 "This is an error message");
93 CreatePresentationSessionRequest request(
94 kPresentationUrl, frame_url,
95 base::Bind(&CreatePresentationSessionRequestTest::FailOnSuccess,
96 base::Unretained(this)),
97 base::Bind(&CreatePresentationSessionRequestTest::OnError,
98 base::Unretained(this), error));
99 request.InvokeErrorCallback(error);
100 EXPECT_TRUE(cb_invoked_);
101 }
102
103 } // namespace media_router
OLDNEW
« no previous file with comments | « chrome/browser/media/router/create_presentation_session_request.cc ('k') | chrome/browser/media/router/media_router.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698