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

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

Issue 165293002: Add an API test to exersize the open error case. This is a regression test for (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 10 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: chrome/browser/extensions/api/cast_channel/cast_channel_apitest.cc
===================================================================
--- chrome/browser/extensions/api/cast_channel/cast_channel_apitest.cc (revision 250590)
+++ chrome/browser/extensions/api/cast_channel/cast_channel_apitest.cc (working copy)
@@ -16,14 +16,17 @@
#include "net/base/completion_callback.h"
#include "net/base/net_errors.h"
#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gmock_mutant.h"
namespace cast_channel = extensions::api::cast_channel;
using cast_channel::CastSocket;
+using cast_channel::ChannelError;
using cast_channel::ChannelInfo;
using cast_channel::MessageInfo;
+using ::testing::_;
using ::testing::A;
-using ::testing::_;
+using ::testing::DoAll;
using ::testing::Invoke;
using ::testing::Return;
@@ -46,6 +49,18 @@
::std::tr1::get<k>(args).Run(result);
}
+// mfoltz,wez: Please see this and suggest how to make ACTION_TEMPLATE
+// to work. I have currently used testing::CreateFunctor, but it will be
+// better to use ACTION_TEMPLATE for consistency with InvokeCompletionCallback
mark a. foltz 2014/02/24 06:14:05 This looks like it should work, but I am far from
Munjal (Google) 2014/02/26 20:46:33 I figured out a way to use ACTION_P macro.
+/*
+ACTION_TEMPLATE(InvokeDelegateOnError,
+ HAS_2_TEMPLATE_PARAMS(extensions::CastChannelAPI*, api,
+ MockCastSocket*, cast_socket),
+ AND_1_VALUE_PARAMS(callback)) {
+ ::std::tr1::get<api, cast_socket>(args).Run(callback);
+}
+*/
+
class MockCastSocket : public CastSocket {
public:
explicit MockCastSocket(CastSocket::Delegate* delegate,
@@ -103,21 +118,38 @@
channel_info->error_state = cast_channel::CHANNEL_ERROR_NONE;
}
+ void CallOnError(extensions::CastChannelAPI* api,
+ const net::CompletionCallback& callback) {
+ api->OnError(mock_cast_socket_, cast_channel::CHANNEL_ERROR_CONNECT_ERROR);
mark a. foltz 2014/02/24 06:14:05 Will api ever != GetApi()? Can we use the GetApi(
Munjal (Google) 2014/02/26 20:46:33 The issue is that if GetAPI is called here then a
+
+ /*
mark a. foltz 2014/02/24 06:14:05 Delete commented out code and method it calls
Munjal (Google) 2014/02/26 20:46:33 Done.
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&CastChannelAPITest::DoCallOnError, this,
+ api, mock_cast_socket_));
+ */
+ }
+
+ void DoCallOnError(extensions::CastChannelAPI* api,
+ MockCastSocket* cast_socket) {
+ api->OnError(cast_socket, cast_channel::CHANNEL_ERROR_CONNECT_ERROR);
+ }
+
protected:
void CallOnMessage(const std::string& message) {
content::BrowserThread::PostTask(
content::BrowserThread::IO,
FROM_HERE,
base::Bind(&CastChannelAPITest::DoCallOnMessage, this,
- GetApi(), mock_cast_socket_, message));
+ mock_cast_socket_, message));
}
- void DoCallOnMessage(extensions::CastChannelAPI* api,
- MockCastSocket* cast_socket,
+ void DoCallOnMessage(MockCastSocket* cast_socket,
const std::string& message) {
MessageInfo message_info;
FillMessageInfo(&message_info, message);
- api->OnMessage(cast_socket, message_info);
+ GetApi()->OnMessage(cast_socket, message_info);
}
MockCastSocket* mock_cast_socket_;
@@ -182,3 +214,31 @@
CallOnMessage("some-message");
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
}
+
+// TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest
+// always return true without actually running the test. Remove when fixed.
+#if defined(OS_WIN) && !defined(NDEBUG)
+#define MAYBE_TestOpenError DISABLED_TestOpenError
+#else
+#define MAYBE_TestOpenError TestOpenError
+#endif
+// Test the case when socket open results in an error.
+IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenError) {
+ SetUpMockCastSocket();
+
+ EXPECT_CALL(*mock_cast_socket_, Connect(_))
+ .WillOnce(DoAll(
+ Invoke(testing::CreateFunctor(
+ this, &CastChannelAPITest::CallOnError, GetApi())),
+ InvokeCompletionCallback<0>(net::ERR_FAILED)));
+ EXPECT_CALL(*mock_cast_socket_, FillChannelInfo(_))
+ .WillOnce(Invoke(FillChannelInfoForClosedState))
+ .WillOnce(Invoke(FillChannelInfoForClosedState));
mark a. foltz 2014/02/24 06:14:05 Is it a typo to invoke FIllChannelInfoForClosedSta
Munjal (Google) 2014/02/26 20:46:33 No, it is actually called twice.
+ EXPECT_CALL(*mock_cast_socket_, Close(_));
+
+ EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
mark a. foltz 2014/02/24 06:14:05 Can we convert these to use RunExtensionTest inste
Munjal (Google) 2014/02/26 20:46:33 Let me handle this separately.
+ "test_open_error.html"));
+
+ ResultCatcher catcher;
+ EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
+}

Powered by Google App Engine
This is Rietveld 408576698