| 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 "chrome/browser/ui/webui/media_router/media_router_ui.h" |    5 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" | 
|    6  |    6  | 
|    7 #include <utility> |    7 #include <utility> | 
|    8  |    8  | 
|    9 #include "base/bind.h" |    9 #include "base/bind.h" | 
|   10 #include "base/memory/ptr_util.h" |   10 #include "base/memory/ptr_util.h" | 
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  480  |  480  | 
|  481   EXPECT_EQ("", MediaRouterUI::GetExtensionName(url, registry.get())); |  481   EXPECT_EQ("", MediaRouterUI::GetExtensionName(url, registry.get())); | 
|  482 } |  482 } | 
|  483  |  483  | 
|  484 TEST_F(MediaRouterUITest, NotFoundErrorOnCloseWithNoSinks) { |  484 TEST_F(MediaRouterUITest, NotFoundErrorOnCloseWithNoSinks) { | 
|  485   content::PresentationError expected_error( |  485   content::PresentationError expected_error( | 
|  486       content::PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, |  486       content::PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, | 
|  487       "No screens found."); |  487       "No screens found."); | 
|  488   PresentationRequestCallbacks request_callbacks(expected_error); |  488   PresentationRequestCallbacks request_callbacks(expected_error); | 
|  489   create_session_request_.reset(new CreatePresentationConnectionRequest( |  489   create_session_request_.reset(new CreatePresentationConnectionRequest( | 
|  490       RenderFrameHostId(0, 0), GURL("http://google.com/presentation"), |  490       RenderFrameHostId(0, 0), {GURL("http://google.com/presentation"), | 
 |  491                                 GURL("http://google.com/presentation2")}, | 
|  491       GURL("http://google.com"), |  492       GURL("http://google.com"), | 
|  492       base::Bind(&PresentationRequestCallbacks::Success, |  493       base::Bind(&PresentationRequestCallbacks::Success, | 
|  493                  base::Unretained(&request_callbacks)), |  494                  base::Unretained(&request_callbacks)), | 
|  494       base::Bind(&PresentationRequestCallbacks::Error, |  495       base::Bind(&PresentationRequestCallbacks::Error, | 
|  495                  base::Unretained(&request_callbacks)))); |  496                  base::Unretained(&request_callbacks)))); | 
|  496   CreateMediaRouterUI(&profile_); |  497   CreateMediaRouterUI(&profile_); | 
|  497   // Destroying the UI should return the expected error from above to the error |  498   // Destroying the UI should return the expected error from above to the error | 
|  498   // callback. |  499   // callback. | 
|  499   media_router_ui_.reset(); |  500   media_router_ui_.reset(); | 
|  500 } |  501 } | 
|  501  |  502  | 
|  502 TEST_F(MediaRouterUITest, NotFoundErrorOnCloseWithNoCompatibleSinks) { |  503 TEST_F(MediaRouterUITest, NotFoundErrorOnCloseWithNoCompatibleSinks) { | 
|  503   content::PresentationError expected_error( |  504   content::PresentationError expected_error( | 
|  504       content::PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, |  505       content::PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, | 
|  505       "No screens found."); |  506       "No screens found."); | 
|  506   PresentationRequestCallbacks request_callbacks(expected_error); |  507   PresentationRequestCallbacks request_callbacks(expected_error); | 
|  507   GURL presentation_url("http://google.com/presentation"); |  508   GURL presentation_url("http://google.com/presentation"); | 
|  508   create_session_request_.reset(new CreatePresentationConnectionRequest( |  509   create_session_request_.reset(new CreatePresentationConnectionRequest( | 
|  509       RenderFrameHostId(0, 0), presentation_url, GURL("http://google.com"), |  510       RenderFrameHostId(0, 0), {presentation_url}, GURL("http://google.com"), | 
|  510       base::Bind(&PresentationRequestCallbacks::Success, |  511       base::Bind(&PresentationRequestCallbacks::Success, | 
|  511                  base::Unretained(&request_callbacks)), |  512                  base::Unretained(&request_callbacks)), | 
|  512       base::Bind(&PresentationRequestCallbacks::Error, |  513       base::Bind(&PresentationRequestCallbacks::Error, | 
|  513                  base::Unretained(&request_callbacks)))); |  514                  base::Unretained(&request_callbacks)))); | 
|  514   CreateMediaRouterUI(&profile_); |  515   CreateMediaRouterUI(&profile_); | 
|  515  |  516  | 
|  516   // Send a sink to the UI that is compatible with sources other than the |  517   // Send a sink to the UI that is compatible with sources other than the | 
|  517   // presentation url to cause a NotFoundError. |  518   // presentation url to cause a NotFoundError. | 
|  518   std::vector<MediaSink> sinks; |  519   std::vector<MediaSink> sinks; | 
|  519   sinks.emplace_back("sink id", "sink name", MediaSink::GENERIC); |  520   sinks.emplace_back("sink id", "sink name", MediaSink::GENERIC); | 
|  520   std::vector<GURL> origins; |  521   std::vector<GURL> origins; | 
|  521   for (auto* observer : media_sinks_observers_) { |  522   for (auto* observer : media_sinks_observers_) { | 
|  522     if (observer->source().id() != presentation_url.spec()) { |  523     if (observer->source().id() != presentation_url.spec()) { | 
|  523       observer->OnSinksUpdated(sinks, origins); |  524       observer->OnSinksUpdated(sinks, origins); | 
|  524     } |  525     } | 
|  525   } |  526   } | 
|  526   // Destroying the UI should return the expected error from above to the error |  527   // Destroying the UI should return the expected error from above to the error | 
|  527   // callback. |  528   // callback. | 
|  528   media_router_ui_.reset(); |  529   media_router_ui_.reset(); | 
|  529 } |  530 } | 
|  530  |  531  | 
|  531 TEST_F(MediaRouterUITest, AbortErrorOnClose) { |  532 TEST_F(MediaRouterUITest, AbortErrorOnClose) { | 
|  532   content::PresentationError expected_error( |  533   content::PresentationError expected_error( | 
|  533       content::PresentationErrorType:: |  534       content::PresentationErrorType:: | 
|  534           PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, |  535           PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, | 
|  535       "Dialog closed."); |  536       "Dialog closed."); | 
|  536   PresentationRequestCallbacks request_callbacks(expected_error); |  537   PresentationRequestCallbacks request_callbacks(expected_error); | 
|  537   GURL presentation_url("http://google.com/presentation"); |  538   GURL presentation_url("http://google.com/presentation"); | 
|  538   create_session_request_.reset(new CreatePresentationConnectionRequest( |  539   create_session_request_.reset(new CreatePresentationConnectionRequest( | 
|  539       RenderFrameHostId(0, 0), presentation_url, GURL("http://google.com"), |  540       RenderFrameHostId(0, 0), {presentation_url}, GURL("http://google.com"), | 
|  540       base::Bind(&PresentationRequestCallbacks::Success, |  541       base::Bind(&PresentationRequestCallbacks::Success, | 
|  541                  base::Unretained(&request_callbacks)), |  542                  base::Unretained(&request_callbacks)), | 
|  542       base::Bind(&PresentationRequestCallbacks::Error, |  543       base::Bind(&PresentationRequestCallbacks::Error, | 
|  543                  base::Unretained(&request_callbacks)))); |  544                  base::Unretained(&request_callbacks)))); | 
|  544   CreateMediaRouterUI(&profile_); |  545   CreateMediaRouterUI(&profile_); | 
|  545  |  546  | 
|  546   // Send a sink to the UI that is compatible with the presentation url to avoid |  547   // Send a sink to the UI that is compatible with the presentation url to avoid | 
|  547   // a NotFoundError. |  548   // a NotFoundError. | 
|  548   std::vector<MediaSink> sinks; |  549   std::vector<MediaSink> sinks; | 
|  549   sinks.emplace_back("sink id", "sink name", MediaSink::GENERIC); |  550   sinks.emplace_back("sink id", "sink name", MediaSink::GENERIC); | 
|  550   std::vector<GURL> origins; |  551   std::vector<GURL> origins; | 
|  551   MediaSource::Id presentation_source_id = |  552   MediaSource::Id presentation_source_id = | 
|  552       MediaSourceForPresentationUrl(presentation_url).id(); |  553       MediaSourceForPresentationUrl(presentation_url).id(); | 
|  553   for (auto* observer : media_sinks_observers_) { |  554   for (auto* observer : media_sinks_observers_) { | 
|  554     if (observer->source().id() == presentation_source_id) { |  555     if (observer->source().id() == presentation_source_id) { | 
|  555       observer->OnSinksUpdated(sinks, origins); |  556       observer->OnSinksUpdated(sinks, origins); | 
|  556     } |  557     } | 
|  557   } |  558   } | 
|  558   // Destroying the UI should return the expected error from above to the error |  559   // Destroying the UI should return the expected error from above to the error | 
|  559   // callback. |  560   // callback. | 
|  560   media_router_ui_.reset(); |  561   media_router_ui_.reset(); | 
|  561 } |  562 } | 
|  562 }  // namespace media_router |  563 }  // namespace media_router | 
| OLD | NEW |