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

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
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/cast_channel/api/test_open_error.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
+/*
+ACTION_TEMPLATE(InvokeDelegateOnError,
+ HAS_1_TEMPLATE_PARAMS(extensions::CastChannelAPI*, api,
+ MockCastSocket*, cast_socket),
Wez 2014/02/15 01:45:52 This should be HAS_2_TEMPLATE_PARAMS.
Munjal (Google) 2014/02/20 23:27:08 Done. But I don't understand how an action templat
+ 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,34 @@
channel_info->error_state = cast_channel::CHANNEL_ERROR_NONE;
}
+ void CallOnError(extensions::CastChannelAPI* api,
+ const net::CompletionCallback& callback) {
+ 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 +210,30 @@
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.
Wez 2014/02/15 01:45:52 If it's always going to return true then why do we
Munjal (Google) 2014/02/20 23:27:08 I am not aware of the full background here. I borr
+#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(_))
Wez 2014/02/15 01:45:52 Indentation
Munjal (Google) 2014/02/20 23:27:08 Done.
+ .WillOnce(DoAll(
+ Invoke(testing::CreateFunctor(
+ this, &CastChannelAPITest::CallOnError, GetApi())),
+ InvokeCompletionCallback<0>(net::OK)));
+ EXPECT_CALL(*mock_cast_socket_, FillChannelInfo(_))
+ .WillOnce(Invoke(FillChannelInfoForClosedState))
+ .WillOnce(Invoke(FillChannelInfoForClosedState));
+
+ EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
+ "test_open_error.html"));
+
+ ResultCatcher catcher;
+ EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
+}
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/cast_channel/api/test_open_error.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698