| OLD | NEW | 
|    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::Id& route_id) { |   37                  const MediaRoute::Id& route_id) { | 
|   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_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::Id& route_id) { |   52                      const MediaRoute::Id& route_id) { | 
|   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   request.InvokeSuccessCallback(kPresentationId, kRouteId); |   93   request.InvokeSuccessCallback(kPresentationId, presentation_url_, kRouteId); | 
|   91   EXPECT_TRUE(cb_invoked_); |   94   EXPECT_TRUE(cb_invoked_); | 
|   92 } |   95 } | 
|   93  |   96  | 
|   94 TEST_F(CreatePresentationConnectionRequestTest, ErrorCallback) { |   97 TEST_F(CreatePresentationConnectionRequestTest, ErrorCallback) { | 
|   95   content::PresentationError error( |   98   content::PresentationError error( | 
|   96       content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, |   99       content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, | 
|   97       "This is an error message"); |  100       "This is an error message"); | 
|   98   CreatePresentationConnectionRequest request( |  101   CreatePresentationConnectionRequest request( | 
|   99       render_frame_host_id_, presentation_url_, GURL(kFrameUrl), |  102       render_frame_host_id_, presentation_urls_, GURL(kFrameUrl), | 
|  100       base::Bind(&CreatePresentationConnectionRequestTest::FailOnSuccess, |  103       base::Bind(&CreatePresentationConnectionRequestTest::FailOnSuccess, | 
|  101                  base::Unretained(this)), |  104                  base::Unretained(this)), | 
|  102       base::Bind(&CreatePresentationConnectionRequestTest::OnError, |  105       base::Bind(&CreatePresentationConnectionRequestTest::OnError, | 
|  103                  base::Unretained(this), error)); |  106                  base::Unretained(this), error)); | 
|  104   request.InvokeErrorCallback(error); |  107   request.InvokeErrorCallback(error); | 
|  105   EXPECT_TRUE(cb_invoked_); |  108   EXPECT_TRUE(cb_invoked_); | 
|  106 } |  109 } | 
|  107  |  110  | 
|  108 }  // namespace media_router |  111 }  // namespace media_router | 
| OLD | NEW |