summaryrefslogtreecommitdiff
path: root/chromium/content/browser/presentation
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-10-24 11:30:15 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-10-30 12:56:19 +0000
commit6036726eb981b6c4b42047513b9d3f4ac865daac (patch)
tree673593e70678e7789766d1f732eb51f613a2703b /chromium/content/browser/presentation
parent466052c4e7c052268fd931888cd58961da94c586 (diff)
downloadqtwebengine-chromium-6036726eb981b6c4b42047513b9d3f4ac865daac.tar.gz
BASELINE: Update Chromium to 70.0.3538.78
Change-Id: Ie634710bf039e26c1957f4ae45e101bd4c434ae7 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/content/browser/presentation')
-rw-r--r--chromium/content/browser/presentation/OWNERS5
-rw-r--r--chromium/content/browser/presentation/presentation_service_impl.cc71
-rw-r--r--chromium/content/browser/presentation/presentation_service_impl.h32
-rw-r--r--chromium/content/browser/presentation/presentation_service_impl_unittest.cc323
4 files changed, 168 insertions, 263 deletions
diff --git a/chromium/content/browser/presentation/OWNERS b/chromium/content/browser/presentation/OWNERS
index 4c81ef2dbac..1a85e3fd162 100644
--- a/chromium/content/browser/presentation/OWNERS
+++ b/chromium/content/browser/presentation/OWNERS
@@ -1,9 +1,4 @@
# Presentation API OWNERS
-#
-# This file also covers ownership of the following directories:
-# //content/common/presentation/
-# //content/renderer/presentation/
-
imcheng@chromium.org
mfoltz@chromium.org
mlamouri@chromium.org
diff --git a/chromium/content/browser/presentation/presentation_service_impl.cc b/chromium/content/browser/presentation/presentation_service_impl.cc
index 321adbda8a1..7d2bd5d9a73 100644
--- a/chromium/content/browser/presentation/presentation_service_impl.cc
+++ b/chromium/content/browser/presentation/presentation_service_impl.cc
@@ -21,7 +21,6 @@
#include "content/public/common/content_client.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/frame_navigate_params.h"
-#include "content/public/common/presentation_connection_message.h"
using blink::mojom::PresentationConnectionState;
using blink::mojom::PresentationError;
@@ -46,7 +45,7 @@ int GetNextRequestId() {
void InvokeNewPresentationCallbackWithError(
PresentationServiceImpl::NewPresentationCallback callback) {
std::move(callback).Run(
- PresentationInfoPtr(),
+ /** PresentationConnectionResultPtr */ nullptr,
PresentationError::New(
PresentationErrorType::PREVIOUS_START_IN_PROGRESS,
"There is already an unsettled Promise from a previous call "
@@ -211,7 +210,7 @@ void PresentationServiceImpl::StartPresentation(
DVLOG(2) << "StartPresentation";
if (!controller_delegate_) {
std::move(callback).Run(
- PresentationInfoPtr(),
+ /** PresentationConnectionResultPtr */ nullptr,
PresentationError::New(PresentationErrorType::NO_AVAILABLE_SCREENS,
"No screens found."));
return;
@@ -247,7 +246,7 @@ void PresentationServiceImpl::ReconnectPresentation(
DVLOG(2) << "ReconnectPresentation";
if (!controller_delegate_) {
std::move(callback).Run(
- PresentationInfoPtr(),
+ /** PresentationConnectionResultPtr */ nullptr,
PresentationError::New(PresentationErrorType::NO_PRESENTATION_FOUND,
"Error joining route: No matching route"));
return;
@@ -296,14 +295,15 @@ void PresentationServiceImpl::ListenForConnectionStateChange(
void PresentationServiceImpl::OnStartPresentationSucceeded(
int request_id,
- const PresentationInfo& presentation_info) {
+ blink::mojom::PresentationConnectionResultPtr result) {
if (request_id != start_presentation_request_id_)
return;
- CHECK(pending_start_presentation_cb_.get());
+ auto presentation_info = *result->presentation_info;
+ DCHECK(pending_start_presentation_cb_.get());
DCHECK(presentation_info.id.length() <= kMaxPresentationIdLength);
- pending_start_presentation_cb_->Run(PresentationInfo::New(presentation_info),
- PresentationErrorPtr());
+ pending_start_presentation_cb_->Run(std::move(result),
+ /** PresentationErrorPtr */ nullptr);
ListenForConnectionStateChange(presentation_info);
pending_start_presentation_cb_.reset();
start_presentation_request_id_ = kInvalidRequestId;
@@ -316,19 +316,19 @@ void PresentationServiceImpl::OnStartPresentationError(
return;
CHECK(pending_start_presentation_cb_.get());
- pending_start_presentation_cb_->Run(PresentationInfoPtr(),
- PresentationError::New(error));
+ pending_start_presentation_cb_->Run(
+ /** PresentationConnectionResultPtr */ nullptr,
+ PresentationError::New(error));
pending_start_presentation_cb_.reset();
start_presentation_request_id_ = kInvalidRequestId;
}
void PresentationServiceImpl::OnReconnectPresentationSucceeded(
int request_id,
- const PresentationInfo& presentation_info) {
- DCHECK(presentation_info.id.length() <= kMaxPresentationIdLength);
+ blink::mojom::PresentationConnectionResultPtr result) {
+ auto presentation_info = *result->presentation_info;
if (RunAndEraseReconnectPresentationMojoCallback(
- request_id, PresentationInfo::New(presentation_info),
- PresentationErrorPtr())) {
+ request_id, std::move(result), /** PresentationErrorPtr */ nullptr)) {
ListenForConnectionStateChange(presentation_info);
}
}
@@ -337,19 +337,20 @@ void PresentationServiceImpl::OnReconnectPresentationError(
int request_id,
const blink::mojom::PresentationError& error) {
RunAndEraseReconnectPresentationMojoCallback(
- request_id, PresentationInfoPtr(), PresentationError::New(error));
+ request_id, blink::mojom::PresentationConnectionResultPtr(),
+ PresentationError::New(error));
}
bool PresentationServiceImpl::RunAndEraseReconnectPresentationMojoCallback(
int request_id,
- PresentationInfoPtr presentation_info,
- PresentationErrorPtr error) {
+ blink::mojom::PresentationConnectionResultPtr result,
+ blink::mojom::PresentationErrorPtr error) {
auto it = pending_reconnect_presentation_cbs_.find(request_id);
if (it == pending_reconnect_presentation_cbs_.end())
return false;
DCHECK(it->second.get());
- it->second->Run(std::move(presentation_info), std::move(error));
+ it->second->Run(std::move(result), std::move(error));
pending_reconnect_presentation_cbs_.erase(it);
return true;
}
@@ -428,21 +429,7 @@ PresentationServiceImpl::GetPresentationServiceDelegate() {
: static_cast<PresentationServiceDelegate*>(controller_delegate_);
}
-void PresentationServiceImpl::SetPresentationConnection(
- PresentationInfoPtr presentation_info,
- blink::mojom::PresentationConnectionPtr controller_connection_ptr,
- blink::mojom::PresentationConnectionRequest receiver_connection_request) {
- DVLOG(2) << "SetPresentationConnection";
-
- if (!controller_delegate_)
- return;
-
- controller_delegate_->ConnectToPresentation(
- render_process_id_, render_frame_id_, *presentation_info,
- std::move(controller_connection_ptr),
- std::move(receiver_connection_request));
-}
-
+// TODO(btolsch): Convert to PresentationConnectionResultPtr.
void PresentationServiceImpl::OnReceiverConnectionAvailable(
PresentationInfoPtr presentation_info,
PresentationConnectionPtr controller_connection_ptr,
@@ -503,12 +490,14 @@ void PresentationServiceImpl::OnDelegateDestroyed() {
}
void PresentationServiceImpl::OnDefaultPresentationStarted(
- const PresentationInfo& connection) {
+ blink::mojom::PresentationConnectionResultPtr result) {
+ auto presentation_info = *result->presentation_info;
if (controller_)
- controller_->OnDefaultPresentationStarted(
- PresentationInfo::New(connection));
+ controller_->OnDefaultPresentationStarted(std::move(result));
- ListenForConnectionStateChange(connection);
+ // TODO(btolsch): Remove the state-change API in favor of direct
+ // PresentationConnection state use.
+ ListenForConnectionStateChange(presentation_info);
}
PresentationServiceImpl::ScreenAvailabilityListenerImpl::
@@ -543,7 +532,7 @@ PresentationServiceImpl::NewPresentationCallbackWrapper::
~NewPresentationCallbackWrapper() {
if (!callback_.is_null()) {
std::move(callback_).Run(
- PresentationInfoPtr(),
+ /** PresentationConnectionResultPtr */ nullptr,
PresentationError::New(
PresentationErrorType::PRESENTATION_REQUEST_CANCELLED,
"The frame is navigating or being destroyed."));
@@ -551,10 +540,10 @@ PresentationServiceImpl::NewPresentationCallbackWrapper::
}
void PresentationServiceImpl::NewPresentationCallbackWrapper::Run(
- PresentationInfoPtr presentation_info,
- PresentationErrorPtr error) {
+ blink::mojom::PresentationConnectionResultPtr result,
+ blink::mojom::PresentationErrorPtr error) {
DCHECK(!callback_.is_null());
- std::move(callback_).Run(std::move(presentation_info), std::move(error));
+ std::move(callback_).Run(std::move(result), std::move(error));
}
} // namespace content
diff --git a/chromium/content/browser/presentation/presentation_service_impl.h b/chromium/content/browser/presentation/presentation_service_impl.h
index 333d2ac479c..a9cc97e4a12 100644
--- a/chromium/content/browser/presentation/presentation_service_impl.h
+++ b/chromium/content/browser/presentation/presentation_service_impl.h
@@ -24,12 +24,11 @@
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/frame_navigate_params.h"
#include "mojo/public/cpp/bindings/binding.h"
-#include "third_party/blink/public/platform/modules/presentation/presentation.mojom.h"
+#include "third_party/blink/public/mojom/presentation/presentation.mojom.h"
#include "url/gurl.h"
namespace content {
-struct PresentationConnectionMessage;
class RenderFrameHost;
// Implementation of Mojo PresentationService.
@@ -45,7 +44,6 @@ class RenderFrameHost;
// Create()
// SetClient()
// StartPresentation()
-// SetPresentationConnection()
// ...
// TODO(crbug.com/749327): Split the controller and receiver logic into separate
// classes so that each is easier to reason about.
@@ -55,7 +53,7 @@ class CONTENT_EXPORT PresentationServiceImpl
public PresentationServiceDelegate::Observer {
public:
using NewPresentationCallback =
- base::OnceCallback<void(blink::mojom::PresentationInfoPtr,
+ base::OnceCallback<void(blink::mojom::PresentationConnectionResultPtr,
blink::mojom::PresentationErrorPtr)>;
// Creates a PresentationServiceImpl using the given RenderFrameHost.
@@ -85,11 +83,6 @@ class CONTENT_EXPORT PresentationServiceImpl
const std::string& presentation_id) override;
void Terminate(const GURL& presentation_url,
const std::string& presentation_id) override;
- void SetPresentationConnection(
- blink::mojom::PresentationInfoPtr presentation_info,
- blink::mojom::PresentationConnectionPtr controller_connection_ptr,
- blink::mojom::PresentationConnectionRequest receiver_connection_request)
- override;
private:
friend class PresentationServiceImplTest;
@@ -113,9 +106,6 @@ class CONTENT_EXPORT PresentationServiceImpl
// Maximum number of pending ReconnectPresentation requests at any given time.
static const int kMaxQueuedRequests = 10;
- using ConnectionMessagesCallback =
- base::OnceCallback<void(std::vector<PresentationConnectionMessage>)>;
-
// Listener implementation owned by PresentationServiceImpl. An instance of
// this is created when PresentationRequest.getAvailability() is resolved.
// The instance receives screen availability results from the embedder and
@@ -144,7 +134,7 @@ class CONTENT_EXPORT PresentationServiceImpl
explicit NewPresentationCallbackWrapper(NewPresentationCallback callback);
~NewPresentationCallbackWrapper();
- void Run(blink::mojom::PresentationInfoPtr presentation_info,
+ void Run(blink::mojom::PresentationConnectionResultPtr result,
blink::mojom::PresentationErrorPtr error);
private:
@@ -178,16 +168,16 @@ class CONTENT_EXPORT PresentationServiceImpl
// Passed to embedder's implementation of PresentationServiceDelegate for
// later invocation when default presentation has started.
void OnDefaultPresentationStarted(
- const blink::mojom::PresentationInfo& presentation_info);
+ blink::mojom::PresentationConnectionResultPtr result);
// Finds the callback from |pending_reconnect_presentation_cbs_| using
// |request_id|.
- // If it exists, invoke it with |presentation_info| and |error|, then erase it
+ // If it exists, invoke it with |result| and |error|, then erase it
// from |pending_reconnect_presentation_cbs_|. Returns true if the callback
// was found.
bool RunAndEraseReconnectPresentationMojoCallback(
int request_id,
- blink::mojom::PresentationInfoPtr presentation_info,
+ blink::mojom::PresentationConnectionResultPtr result,
blink::mojom::PresentationErrorPtr error);
// Removes all listeners and resets default presentation URL on this instance
@@ -199,12 +189,12 @@ class CONTENT_EXPORT PresentationServiceImpl
// invocation.
void OnStartPresentationSucceeded(
int request_id,
- const blink::mojom::PresentationInfo& presentation_info);
+ blink::mojom::PresentationConnectionResultPtr result);
void OnStartPresentationError(int request_id,
const blink::mojom::PresentationError& error);
void OnReconnectPresentationSucceeded(
int request_id,
- const blink::mojom::PresentationInfo& presentation_info);
+ blink::mojom::PresentationConnectionResultPtr result);
void OnReconnectPresentationError(
int request_id,
const blink::mojom::PresentationError& error);
@@ -214,12 +204,6 @@ class CONTENT_EXPORT PresentationServiceImpl
void ListenForConnectionStateChange(
const blink::mojom::PresentationInfo& connection);
- // Passed to embedder's implementation of PresentationServiceDelegate for
- // later invocation when connection messages arrive.
- void OnConnectionMessages(
- const blink::mojom::PresentationInfo& presentation_info,
- std::vector<content::PresentationConnectionMessage> messages);
-
// A callback registered to LocalPresentationManager when
// the PresentationServiceImpl for the presentation receiver is initialized.
// Calls |receiver_| to create a new PresentationConnection on receiver page.
diff --git a/chromium/content/browser/presentation/presentation_service_impl_unittest.cc b/chromium/content/browser/presentation/presentation_service_impl_unittest.cc
index a635d4413a8..51fd39f10ab 100644
--- a/chromium/content/browser/presentation/presentation_service_impl_unittest.cc
+++ b/chromium/content/browser/presentation/presentation_service_impl_unittest.cc
@@ -17,16 +17,24 @@
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/presentation_request.h"
#include "content/public/browser/presentation_service_delegate.h"
-#include "content/public/common/presentation_connection_message.h"
#include "content/test/test_render_frame_host.h"
#include "content/test/test_render_view_host.h"
#include "content/test/test_web_contents.h"
#include "mojo/public/cpp/bindings/interface_ptr.h"
#include "testing/gmock/include/gmock/gmock.h"
+using blink::mojom::PresentationConnection;
using blink::mojom::PresentationConnectionCloseReason;
+using blink::mojom::PresentationConnectionMessagePtr;
+using blink::mojom::PresentationConnectionPtr;
+using blink::mojom::PresentationConnectionPtrInfo;
+using blink::mojom::PresentationConnectionResult;
+using blink::mojom::PresentationConnectionResultPtr;
using blink::mojom::PresentationConnectionState;
+using blink::mojom::PresentationController;
+using blink::mojom::PresentationControllerPtr;
using blink::mojom::PresentationError;
+using blink::mojom::PresentationErrorPtr;
using blink::mojom::PresentationErrorType;
using blink::mojom::PresentationInfo;
using blink::mojom::PresentationInfoPtr;
@@ -52,6 +60,11 @@ MATCHER_P(InfoEquals, expected, "") {
return expected.url == arg.url && expected.id == arg.id;
}
+// Matches blink::mojom::PresentationInfoPtr.
+MATCHER_P(InfoPtrEquals, expected, "") {
+ return expected.url == arg->url && expected.id == arg->id;
+}
+
ACTION_TEMPLATE(SaveArgByMove,
HAS_1_TEMPLATE_PARAMS(int, k),
AND_1_VALUE_PARAMS(pointer)) {
@@ -73,7 +86,7 @@ class MockPresentationServiceDelegate
int render_frame_id,
PresentationServiceDelegate::Observer* observer));
MOCK_METHOD2(RemoveObserver,
- void(int render_process_id, int render_frame_id));
+ void(int render_process_id, int render_frame_id));
bool AddScreenAvailabilityListener(
int render_process_id,
@@ -88,41 +101,22 @@ class MockPresentationServiceDelegate
MOCK_METHOD0(AddScreenAvailabilityListener, bool());
MOCK_METHOD3(RemoveScreenAvailabilityListener,
- void(int render_process_id,
- int routing_id,
- PresentationScreenAvailabilityListener* listener));
- MOCK_METHOD2(Reset,
- void(int render_process_id,
- int routing_id));
+ void(int render_process_id,
+ int routing_id,
+ PresentationScreenAvailabilityListener* listener));
+ MOCK_METHOD2(Reset, void(int render_process_id, int routing_id));
MOCK_METHOD2(SetDefaultPresentationUrls,
void(const PresentationRequest& request,
DefaultPresentationConnectionCallback callback));
-
- // TODO(crbug.com/729950): Use MOCK_METHOD directly once GMock gets the
- // move-only type support.
- void StartPresentation(
- const PresentationRequest& request,
- PresentationConnectionCallback success_cb,
- PresentationConnectionErrorCallback error_cb) override {
- StartPresentationInternal(request, success_cb, error_cb);
- }
- MOCK_METHOD3(StartPresentationInternal,
+ MOCK_METHOD3(StartPresentation,
void(const PresentationRequest& request,
- PresentationConnectionCallback& success_cb,
- PresentationConnectionErrorCallback& error_cb));
- void ReconnectPresentation(
- const PresentationRequest& request,
- const std::string& presentation_id,
- PresentationConnectionCallback success_cb,
- PresentationConnectionErrorCallback error_cb) override {
- ReconnectPresentationInternal(request, presentation_id, success_cb,
- error_cb);
- }
- MOCK_METHOD4(ReconnectPresentationInternal,
+ PresentationConnectionCallback success_cb,
+ PresentationConnectionErrorCallback error_cb));
+ MOCK_METHOD4(ReconnectPresentation,
void(const PresentationRequest& request,
const std::string& presentation_id,
- PresentationConnectionCallback& success_cb,
- PresentationConnectionErrorCallback& error_cb));
+ PresentationConnectionCallback success_cb,
+ PresentationConnectionErrorCallback error_cb));
MOCK_METHOD3(CloseConnection,
void(int render_process_id,
int render_frame_id,
@@ -131,30 +125,17 @@ class MockPresentationServiceDelegate
void(int render_process_id,
int render_frame_id,
const std::string& presentation_id));
- MOCK_METHOD3(GetMediaController,
- std::unique_ptr<media::MediaController>(
+ MOCK_METHOD3(GetFlingingController,
+ std::unique_ptr<media::FlingingController>(
int render_process_id,
int render_frame_id,
const std::string& presentation_id));
-
- // PresentationConnectionMessage is move-only.
- // TODO(crbug.com/729950): Use MOCK_METHOD directly once GMock gets the
- // move-only type support.
- void SendMessage(int render_process_id,
- int render_frame_id,
- const PresentationInfo& presentation_info,
- PresentationConnectionMessage message,
- SendMessageCallback send_message_cb) {
- SendMessageInternal(render_process_id, render_frame_id, presentation_info,
- message, send_message_cb);
- }
- MOCK_METHOD5(SendMessageInternal,
+ MOCK_METHOD5(SendMessage,
void(int render_process_id,
int render_frame_id,
const PresentationInfo& presentation_info,
- const PresentationConnectionMessage& message,
+ PresentationConnectionMessagePtr message,
const SendMessageCallback& send_message_cb));
-
MOCK_METHOD4(
ListenForConnectionStateChange,
void(int render_process_id,
@@ -162,23 +143,6 @@ class MockPresentationServiceDelegate
const PresentationInfo& connection,
const PresentationConnectionStateChangedCallback& state_changed_cb));
- void ConnectToPresentation(
- int render_process_id,
- int render_frame_id,
- const PresentationInfo& presentation_info,
- PresentationConnectionPtr controller_conn_ptr,
- PresentationConnectionRequest receiver_conn_request) override {
- RegisterLocalPresentationConnectionRaw(render_process_id, render_frame_id,
- presentation_info,
- controller_conn_ptr.get());
- }
-
- MOCK_METHOD4(RegisterLocalPresentationConnectionRaw,
- void(int render_process_id,
- int render_frame_id,
- const PresentationInfo& presentation_info,
- blink::mojom::PresentationConnection* connection));
-
void set_screen_availability_listening_supported(bool value) {
screen_availability_listening_supported_ = value;
}
@@ -189,16 +153,10 @@ class MockPresentationServiceDelegate
class MockPresentationReceiver : public blink::mojom::PresentationReceiver {
public:
- void OnReceiverConnectionAvailable(
- PresentationInfoPtr info,
- blink::mojom::PresentationConnectionPtr controller_connection,
- blink::mojom::PresentationConnectionRequest receiver_connection_request)
- override {
- OnReceiverConnectionAvailable(*info);
- }
-
- MOCK_METHOD1(OnReceiverConnectionAvailable,
- void(const PresentationInfo& info));
+ MOCK_METHOD3(OnReceiverConnectionAvailable,
+ void(PresentationInfoPtr info,
+ PresentationConnectionPtr controller_connection,
+ PresentationConnectionRequest receiver_connection_request));
};
class MockReceiverPresentationServiceDelegate
@@ -215,16 +173,11 @@ class MockReceiverPresentationServiceDelegate
void(const ReceiverConnectionAvailableCallback&));
};
-class MockPresentationConnection : public blink::mojom::PresentationConnection {
+class MockPresentationConnection : public PresentationConnection {
public:
- // PresentationConnectionMessage is move-only.
- void OnMessage(PresentationConnectionMessage message,
- base::OnceCallback<void(bool)> send_message_cb) override {
- OnMessageInternal(message, send_message_cb);
- }
- MOCK_METHOD2(OnMessageInternal,
- void(const PresentationConnectionMessage& message,
- base::OnceCallback<void(bool)>& send_message_cb));
+ MOCK_METHOD2(OnMessage,
+ void(PresentationConnectionMessagePtr message,
+ base::OnceCallback<void(bool)> send_message_cb));
MOCK_METHOD1(DidChangeState, void(PresentationConnectionState state));
MOCK_METHOD0(RequestClose, void());
};
@@ -233,38 +186,19 @@ class MockPresentationController : public blink::mojom::PresentationController {
public:
MOCK_METHOD2(OnScreenAvailabilityUpdated,
void(const GURL& url, ScreenAvailability availability));
- void OnConnectionStateChanged(PresentationInfoPtr connection,
- PresentationConnectionState new_state) {
- OnConnectionStateChangedInternal(*connection, new_state);
- }
- MOCK_METHOD2(OnConnectionStateChangedInternal,
- void(const PresentationInfo& connection,
+ MOCK_METHOD2(OnConnectionStateChanged,
+ void(PresentationInfoPtr connection,
PresentationConnectionState new_state));
- void OnConnectionClosed(
- PresentationInfoPtr connection,
- blink::mojom::PresentationConnectionCloseReason reason,
- const std::string& message) {
- OnConnectionClosedInternal(*connection, reason, message);
- }
- MOCK_METHOD3(OnConnectionClosedInternal,
- void(const PresentationInfo& connection,
- blink::mojom::PresentationConnectionCloseReason reason,
+ MOCK_METHOD3(OnConnectionClosed,
+ void(PresentationInfoPtr connection,
+ PresentationConnectionCloseReason reason,
const std::string& message));
- // PresentationConnectionMessage is move-only.
- void OnConnectionMessagesReceived(
- PresentationInfoPtr presentation_info,
- std::vector<PresentationConnectionMessage> messages) {
- OnConnectionMessagesReceivedInternal(*presentation_info, messages);
- }
MOCK_METHOD2(
- OnConnectionMessagesReceivedInternal,
+ OnConnectionMessagesReceived,
void(const PresentationInfo& presentation_info,
- const std::vector<PresentationConnectionMessage>& messages));
- void OnDefaultPresentationStarted(PresentationInfoPtr presentation_info) {
- OnDefaultPresentationStartedInternal(*presentation_info);
- }
- MOCK_METHOD1(OnDefaultPresentationStartedInternal,
- void(const PresentationInfo& presentation_info));
+ const std::vector<PresentationConnectionMessagePtr>& messages));
+ MOCK_METHOD1(OnDefaultPresentationStarted,
+ void(PresentationConnectionResultPtr result));
};
class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
@@ -286,10 +220,9 @@ class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
service_impl_.reset(new PresentationServiceImpl(
render_frame_host, contents(), &mock_delegate_, nullptr));
- blink::mojom::PresentationControllerPtr controller_ptr;
- controller_binding_.reset(
- new mojo::Binding<blink::mojom::PresentationController>(
- &mock_controller_, mojo::MakeRequest(&controller_ptr)));
+ PresentationControllerPtr controller_ptr;
+ controller_binding_.reset(new mojo::Binding<PresentationController>(
+ &mock_controller_, mojo::MakeRequest(&controller_ptr)));
service_impl_->SetController(std::move(controller_ptr));
presentation_urls_.push_back(presentation_url1_);
@@ -318,8 +251,7 @@ class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
if (!main_frame)
rfh = rfh_tester->AppendChild("subframe");
std::unique_ptr<NavigationHandle> navigation_handle =
- NavigationHandle::CreateNavigationHandleForTesting(
- GURL(), rfh, true);
+ NavigationHandle::CreateNavigationHandleForTesting(GURL(), rfh, true);
// Destructor calls DidFinishNavigation.
}
@@ -355,17 +287,17 @@ class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
service_impl_->screen_availability_listeners_.end());
}
- void ExpectPresentationSuccess(PresentationInfoPtr info,
- blink::mojom::PresentationErrorPtr error) {
- EXPECT_FALSE(info.is_null());
- EXPECT_TRUE(error.is_null());
+ void ExpectPresentationSuccess(PresentationConnectionResultPtr result,
+ PresentationErrorPtr error) {
+ EXPECT_TRUE(result);
+ EXPECT_FALSE(error);
presentation_cb_was_run_ = true;
}
- void ExpectPresentationError(PresentationInfoPtr info,
- blink::mojom::PresentationErrorPtr error) {
- EXPECT_TRUE(info.is_null());
- EXPECT_FALSE(error.is_null());
+ void ExpectPresentationError(PresentationConnectionResultPtr result,
+ PresentationErrorPtr error) {
+ EXPECT_FALSE(result);
+ EXPECT_TRUE(error);
presentation_cb_was_run_ = true;
}
@@ -380,8 +312,7 @@ class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
std::unique_ptr<PresentationServiceImpl> service_impl_;
MockPresentationController mock_controller_;
- std::unique_ptr<mojo::Binding<blink::mojom::PresentationController>>
- controller_binding_;
+ std::unique_ptr<mojo::Binding<PresentationController>> controller_binding_;
GURL presentation_url1_;
GURL presentation_url2_;
@@ -469,11 +400,24 @@ TEST_F(PresentationServiceImplTest, SetDefaultPresentationUrls) {
PresentationInfo presentation_info(presentation_url2_, kPresentationId);
- EXPECT_CALL(mock_controller_, OnDefaultPresentationStartedInternal(
- InfoEquals(presentation_info)));
+ EXPECT_CALL(mock_controller_, OnDefaultPresentationStarted(_))
+ .WillOnce([&presentation_info](PresentationConnectionResultPtr result) {
+ EXPECT_THAT(*result->presentation_info, InfoEquals(presentation_info));
+ });
EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _));
- std::move(callback).Run(
- PresentationInfo(presentation_url2_, kPresentationId));
+
+ // Mojo requires we not send nullptr for the InterfacePtrInfo and
+ // InterfaceRequest in PresentationConnectionResult, but there's no reason to
+ // actually have them properly bound in the test. To get around this, we
+ // create mojo pipes but bind to a nullptr for the implementation.
+ PresentationConnectionPtrInfo receiver_ptr;
+ PresentationConnectionPtr controller_ptr;
+ auto request = mojo::MakeRequest(&controller_ptr);
+ mojo::Binding<PresentationConnection> binding(
+ /** impl */ nullptr, mojo::MakeRequest(&receiver_ptr));
+ std::move(callback).Run(PresentationConnectionResult::New(
+ blink::mojom::PresentationInfo::New(presentation_url2_, kPresentationId),
+ std::move(receiver_ptr), std::move(request)));
base::RunLoop().RunUntilIdle();
}
@@ -503,8 +447,8 @@ TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) {
.WillOnce(SaveArg<3>(&state_changed_cb));
service_impl_->ListenForConnectionStateChange(connection);
- EXPECT_CALL(mock_controller_, OnConnectionStateChangedInternal(
- InfoEquals(presentation_connection),
+ EXPECT_CALL(mock_controller_, OnConnectionStateChanged(
+ InfoPtrEquals(presentation_connection),
PresentationConnectionState::TERMINATED));
state_changed_cb.Run(PresentationConnectionStateChangeInfo(
PresentationConnectionState::TERMINATED));
@@ -526,10 +470,10 @@ TEST_F(PresentationServiceImplTest, ListenForConnectionClose) {
closed_info.close_reason = PresentationConnectionCloseReason::WENT_AWAY;
closed_info.message = "Foo";
- EXPECT_CALL(mock_controller_,
- OnConnectionClosedInternal(
- InfoEquals(presentation_connection),
- PresentationConnectionCloseReason::WENT_AWAY, "Foo"));
+ EXPECT_CALL(
+ mock_controller_,
+ OnConnectionClosed(InfoPtrEquals(presentation_connection),
+ PresentationConnectionCloseReason::WENT_AWAY, "Foo"));
state_changed_cb.Run(closed_info);
base::RunLoop().RunUntilIdle();
}
@@ -545,33 +489,41 @@ TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrls) {
}
TEST_F(PresentationServiceImplTest, StartPresentationSuccess) {
- base::OnceCallback<void(const PresentationInfo&)> success_cb;
- EXPECT_CALL(mock_delegate_, StartPresentationInternal(_, _, _))
- .WillOnce(SaveArgByMove<1>(&success_cb));
+ PresentationConnectionCallback saved_success_cb;
+ EXPECT_CALL(mock_delegate_, StartPresentation(_, _, _))
+ .WillOnce([&saved_success_cb](const auto& request, auto success_cb,
+ auto error_cb) {
+ saved_success_cb = std::move(success_cb);
+ });
service_impl_->StartPresentation(presentation_urls_,
std::move(expect_presentation_success_cb_));
- EXPECT_FALSE(success_cb.is_null());
+ EXPECT_FALSE(saved_success_cb.is_null());
EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _))
.Times(1);
- std::move(success_cb)
- .Run(PresentationInfo(presentation_url1_, kPresentationId));
+ std::move(saved_success_cb)
+ .Run(PresentationConnectionResult::New(
+ blink::mojom::PresentationInfo::New(presentation_url1_,
+ kPresentationId),
+ nullptr, nullptr));
ExpectPresentationCallbackWasRun();
}
TEST_F(PresentationServiceImplTest, StartPresentationError) {
- base::OnceCallback<void(const PresentationError&)> error_cb;
- EXPECT_CALL(mock_delegate_, StartPresentationInternal(_, _, _))
- .WillOnce(SaveArgByMove<2>(&error_cb));
+ base::OnceCallback<void(const PresentationError&)> saved_error_cb;
+ EXPECT_CALL(mock_delegate_, StartPresentation(_, _, _))
+ .WillOnce([&](const auto& request, auto success_cb, auto error_cb) {
+ saved_error_cb = std::move(error_cb);
+ });
service_impl_->StartPresentation(presentation_urls_,
std::move(expect_presentation_error_cb_));
- EXPECT_FALSE(error_cb.is_null());
- std::move(error_cb).Run(
- PresentationError(PresentationErrorType::UNKNOWN, "Error message"));
+ EXPECT_FALSE(saved_error_cb.is_null());
+ std::move(saved_error_cb)
+ .Run(PresentationError(PresentationErrorType::UNKNOWN, "Error message"));
ExpectPresentationCallbackWasRun();
}
TEST_F(PresentationServiceImplTest, StartPresentationInProgress) {
- EXPECT_CALL(mock_delegate_, StartPresentationInternal(_, _, _)).Times(1);
+ EXPECT_CALL(mock_delegate_, StartPresentation(_, _, _)).Times(1);
// Uninvoked callbacks must outlive |service_impl_| since they get invoked
// at |service_impl_|'s destruction.
service_impl_->StartPresentation(presentation_urls_, base::DoNothing());
@@ -584,32 +536,37 @@ TEST_F(PresentationServiceImplTest, StartPresentationInProgress) {
}
TEST_F(PresentationServiceImplTest, ReconnectPresentationSuccess) {
- base::OnceCallback<void(const PresentationInfo&)> success_cb;
- EXPECT_CALL(mock_delegate_,
- ReconnectPresentationInternal(_, kPresentationId, _, _))
- .WillOnce(SaveArgByMove<2>(&success_cb));
+ PresentationConnectionCallback saved_success_cb;
+ EXPECT_CALL(mock_delegate_, ReconnectPresentation(_, kPresentationId, _, _))
+ .WillOnce([&saved_success_cb](const auto& request, const auto& id,
+ auto success_cb, auto error_cb) {
+ saved_success_cb = std::move(success_cb);
+ });
service_impl_->ReconnectPresentation(
presentation_urls_, kPresentationId,
std::move(expect_presentation_success_cb_));
- EXPECT_FALSE(success_cb.is_null());
+ EXPECT_FALSE(saved_success_cb.is_null());
EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _))
.Times(1);
- std::move(success_cb)
- .Run(PresentationInfo(presentation_url1_, kPresentationId));
+ std::move(saved_success_cb)
+ .Run(PresentationConnectionResult::New(
+ blink::mojom::PresentationInfo::New(presentation_url1_,
+ kPresentationId),
+ nullptr, nullptr));
ExpectPresentationCallbackWasRun();
}
TEST_F(PresentationServiceImplTest, ReconnectPresentationError) {
- base::OnceCallback<void(const PresentationError&)> error_cb;
- EXPECT_CALL(mock_delegate_,
- ReconnectPresentationInternal(_, kPresentationId, _, _))
- .WillOnce(SaveArgByMove<3>(&error_cb));
+ base::OnceCallback<void(const PresentationError&)> saved_error_cb;
+ EXPECT_CALL(mock_delegate_, ReconnectPresentation(_, kPresentationId, _, _))
+ .WillOnce([&](const auto& request, const std::string& id, auto success_cb,
+ auto error_cb) { saved_error_cb = std::move(error_cb); });
service_impl_->ReconnectPresentation(
presentation_urls_, kPresentationId,
std::move(expect_presentation_error_cb_));
- EXPECT_FALSE(error_cb.is_null());
- std::move(error_cb).Run(
- PresentationError(PresentationErrorType::UNKNOWN, "Error message"));
+ EXPECT_FALSE(saved_error_cb.is_null());
+ std::move(saved_error_cb)
+ .Run(PresentationError(PresentationErrorType::UNKNOWN, "Error message"));
ExpectPresentationCallbackWasRun();
}
@@ -618,7 +575,7 @@ TEST_F(PresentationServiceImplTest, MaxPendingReconnectPresentationRequests) {
const char* presentation_id = "presentationId%d";
int num_requests = PresentationServiceImpl::kMaxQueuedRequests;
int i = 0;
- EXPECT_CALL(mock_delegate_, ReconnectPresentationInternal(_, _, _, _))
+ EXPECT_CALL(mock_delegate_, ReconnectPresentation(_, _, _, _))
.Times(num_requests);
for (; i < num_requests; ++i) {
std::vector<GURL> urls = {GURL(base::StringPrintf(presentation_url, i))};
@@ -646,25 +603,6 @@ TEST_F(PresentationServiceImplTest, Terminate) {
service_impl_->Terminate(presentation_url1_, kPresentationId);
}
-TEST_F(PresentationServiceImplTest, SetPresentationConnection) {
- PresentationInfoPtr presentation_info =
- PresentationInfo::New(presentation_url1_, kPresentationId);
-
- blink::mojom::PresentationConnectionPtr connection;
- MockPresentationConnection mock_presentation_connection;
- mojo::Binding<blink::mojom::PresentationConnection> connection_binding(
- &mock_presentation_connection, mojo::MakeRequest(&connection));
- blink::mojom::PresentationConnectionPtr receiver_connection;
- auto request = mojo::MakeRequest(&receiver_connection);
-
- PresentationInfo expected(presentation_url1_, kPresentationId);
- EXPECT_CALL(mock_delegate_, RegisterLocalPresentationConnectionRaw(
- _, _, InfoEquals(expected), _));
-
- service_impl_->SetPresentationConnection(
- std::move(presentation_info), std::move(connection), std::move(request));
-}
-
TEST_F(PresentationServiceImplTest, ReceiverPresentationServiceDelegate) {
EXPECT_CALL(mock_receiver_delegate_, AddObserver(_, _, _)).Times(1);
@@ -687,14 +625,14 @@ TEST_F(PresentationServiceImplTest, ReceiverPresentationServiceDelegate) {
PresentationInfo expected(presentation_url1_, kPresentationId);
// Client gets notified of receiver connections.
- blink::mojom::PresentationConnectionPtr controller_connection;
+ PresentationConnectionPtr controller_connection;
MockPresentationConnection mock_presentation_connection;
- mojo::Binding<blink::mojom::PresentationConnection> connection_binding(
+ mojo::Binding<PresentationConnection> connection_binding(
&mock_presentation_connection, mojo::MakeRequest(&controller_connection));
- blink::mojom::PresentationConnectionPtr receiver_connection;
+ PresentationConnectionPtr receiver_connection;
EXPECT_CALL(mock_receiver,
- OnReceiverConnectionAvailable(InfoEquals(expected)))
+ OnReceiverConnectionAvailable(InfoPtrEquals(expected), _, _))
.Times(1);
callback.Run(PresentationInfo::New(expected),
std::move(controller_connection),
@@ -716,10 +654,9 @@ TEST_F(PresentationServiceImplTest, ReceiverDelegateOnSubFrame) {
RegisterReceiverConnectionAvailableCallback(_))
.Times(0);
- blink::mojom::PresentationControllerPtr controller_ptr;
- controller_binding_.reset(
- new mojo::Binding<blink::mojom::PresentationController>(
- &mock_controller_, mojo::MakeRequest(&controller_ptr)));
+ PresentationControllerPtr controller_ptr;
+ controller_binding_.reset(new mojo::Binding<PresentationController>(
+ &mock_controller_, mojo::MakeRequest(&controller_ptr)));
service_impl.controller_delegate_ = nullptr;
service_impl.SetController(std::move(controller_ptr));