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

Unified Diff: extensions/browser/api/cast_channel/cast_channel_apitest.cc

Issue 2925053005: [cast_channel] Implement CastSocketService::OpenSocket() (Closed)
Patch Set: resolve code review comments from Mark Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/cast_channel/cast_channel_apitest.cc
diff --git a/extensions/browser/api/cast_channel/cast_channel_apitest.cc b/extensions/browser/api/cast_channel/cast_channel_apitest.cc
index 13293a28b2c2ced7ffdb9f9fc119525b364648ad..eee1018c0ee49de867366198306491dd6194bcce 100644
--- a/extensions/browser/api/cast_channel/cast_channel_apitest.cc
+++ b/extensions/browser/api/cast_channel/cast_channel_apitest.cc
@@ -56,6 +56,7 @@ using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::ReturnPointee;
using ::testing::SaveArg;
+using ::testing::WithArgs;
namespace {
@@ -92,27 +93,25 @@ class CastChannelAPITest : public ExtensionApiTest {
extensions::CastChannelAPI* api = GetApi();
net::IPEndPoint ip_endpoint(net::IPAddress(192, 168, 1, 1), 8009);
- mock_cast_socket_ = new MockCastSocket;
+ mock_cast_socket_ = new MockCastSocket();
+ mock_cast_socket_->SetIPEndpoint(ip_endpoint_);
+ mock_cast_socket_->SetKeepAlive(false);
// Transfers ownership of the socket.
api->SetSocketForTest(base::WrapUnique<CastSocket>(mock_cast_socket_));
- ON_CALL(*mock_cast_socket_, set_id(_))
- .WillByDefault(SaveArg<0>(&channel_id_));
- ON_CALL(*mock_cast_socket_, id())
- .WillByDefault(ReturnPointee(&channel_id_));
- ON_CALL(*mock_cast_socket_, ip_endpoint())
- .WillByDefault(ReturnRef(ip_endpoint_));
- ON_CALL(*mock_cast_socket_, keep_alive()).WillByDefault(Return(false));
}
void SetUpOpenSendClose() {
SetUpMockCastSocket();
- EXPECT_CALL(*mock_cast_socket_, error_state())
- .WillRepeatedly(Return(ChannelError::NONE));
+ mock_cast_socket_->SetErrorState(ChannelError::NONE);
{
InSequence sequence;
+ EXPECT_CALL(*mock_cast_socket_, AddObserver(_));
EXPECT_CALL(*mock_cast_socket_, Connect(_))
- .WillOnce(InvokeCompletionCallback<0>(ChannelError::NONE));
+ .WillOnce(WithArgs<0>(
+ Invoke([&](const CastSocket::OnOpenCallback& callback) {
+ callback.Run(mock_cast_socket_->id(), ChannelError::NONE);
+ })));
EXPECT_CALL(*mock_cast_socket_, ready_state())
.WillOnce(Return(ReadyState::OPEN));
EXPECT_CALL(*mock_cast_socket_->mock_transport(),
@@ -129,15 +128,17 @@ class CastChannelAPITest : public ExtensionApiTest {
void SetUpOpenPingTimeout() {
SetUpMockCastSocket();
- EXPECT_CALL(*mock_cast_socket_, error_state())
- .WillRepeatedly(Return(ChannelError::NONE));
- EXPECT_CALL(*mock_cast_socket_, keep_alive()).WillRepeatedly(Return(true));
+ mock_cast_socket_->SetErrorState(ChannelError::NONE);
+ mock_cast_socket_->SetKeepAlive(true);
{
InSequence sequence;
EXPECT_CALL(*mock_cast_socket_, AddObserver(_))
.WillOnce(SaveArg<0>(&message_observer_));
EXPECT_CALL(*mock_cast_socket_, Connect(_))
- .WillOnce(InvokeCompletionCallback<0>(ChannelError::NONE));
+ .WillOnce(WithArgs<0>(
+ Invoke([&](const CastSocket::OnOpenCallback& callback) {
+ callback.Run(mock_cast_socket_->id(), ChannelError::NONE);
+ })));
EXPECT_CALL(*mock_cast_socket_, ready_state())
.WillOnce(Return(ReadyState::OPEN))
.RetiresOnSaturation();
@@ -288,15 +289,17 @@ IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestPingTimeoutSslVerified) {
// writing, reading, and closing.
IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenReceiveClose) {
SetUpMockCastSocket();
- EXPECT_CALL(*mock_cast_socket_, error_state())
- .WillRepeatedly(Return(ChannelError::NONE));
+ mock_cast_socket_->SetErrorState(ChannelError::NONE);
{
InSequence sequence;
EXPECT_CALL(*mock_cast_socket_, AddObserver(_))
.WillOnce(SaveArg<0>(&message_observer_));
EXPECT_CALL(*mock_cast_socket_, Connect(_))
- .WillOnce(InvokeCompletionCallback<0>(ChannelError::NONE));
+ .WillOnce(
+ WithArgs<0>(Invoke([&](const CastSocket::OnOpenCallback& callback) {
+ callback.Run(mock_cast_socket_->id(), ChannelError::NONE);
+ })));
EXPECT_CALL(*mock_cast_socket_, ready_state())
.Times(3)
.WillRepeatedly(Return(ReadyState::OPEN));
@@ -330,9 +333,11 @@ IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenError) {
.WillOnce(DoAll(SaveArg<0>(&message_observer_),
InvokeObserverOnError(this, GetApi())));
EXPECT_CALL(*mock_cast_socket_, Connect(_))
- .WillOnce(InvokeCompletionCallback<0>(ChannelError::CONNECT_ERROR));
- EXPECT_CALL(*mock_cast_socket_, error_state())
- .WillRepeatedly(Return(ChannelError::CONNECT_ERROR));
+ .WillOnce(
+ WithArgs<0>(Invoke([&](const CastSocket::OnOpenCallback& callback) {
+ callback.Run(mock_cast_socket_->id(), ChannelError::CONNECT_ERROR);
+ })));
+ mock_cast_socket_->SetErrorState(ChannelError::CONNECT_ERROR);
EXPECT_CALL(*mock_cast_socket_, ready_state())
.WillRepeatedly(Return(ReadyState::CLOSED));
EXPECT_CALL(*mock_cast_socket_, Close(_))

Powered by Google App Engine
This is Rietveld 408576698