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

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

Issue 298993005: Cast Channel API test for open error case. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
diff --git a/chrome/browser/extensions/api/cast_channel/cast_channel_apitest.cc b/chrome/browser/extensions/api/cast_channel/cast_channel_apitest.cc
index 58485bfe27d069a2311332ede6cab64f7a852f46..fe478bff1af849582925fb56fd6f4828e68290c3 100644
--- a/chrome/browser/extensions/api/cast_channel/cast_channel_apitest.cc
+++ b/chrome/browser/extensions/api/cast_channel/cast_channel_apitest.cc
@@ -16,6 +16,7 @@
#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;
@@ -23,8 +24,9 @@ using cast_channel::ChannelError;
using cast_channel::MessageInfo;
using cast_channel::ReadyState;
-using ::testing::A;
using ::testing::_;
+using ::testing::A;
+using ::testing::DoAll;
using ::testing::Invoke;
using ::testing::InSequence;
using ::testing::Return;
@@ -47,6 +49,10 @@ ACTION_TEMPLATE(InvokeCompletionCallback,
::std::tr1::get<k>(args).Run(result);
}
+ACTION_P2(InvokeDelegateOnError, api_test, api) {
+ api_test->CallOnError(api);
+}
+
class MockCastSocket : public CastSocket {
public:
explicit MockCastSocket(CastSocket::Delegate* delegate,
@@ -102,6 +108,11 @@ class CastChannelAPITest : public ExtensionApiTest {
return extensions::CastChannelAPI::Get(profile());
}
+ void CallOnError(extensions::CastChannelAPI* api) {
+ api->OnError(mock_cast_socket_,
+ cast_channel::CHANNEL_ERROR_CONNECT_ERROR);
+ }
+
protected:
void CallOnMessage(const std::string& message) {
content::BrowserThread::PostTask(
@@ -220,3 +231,30 @@ IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenReceiveClose) {
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(
+ InvokeDelegateOnError(this, GetApi()),
+ InvokeCompletionCallback<0>(net::ERR_FAILED)));
+ EXPECT_CALL(*mock_cast_socket_, ready_state())
+ .WillRepeatedly(Return(cast_channel::READY_STATE_CLOSED));
+ EXPECT_CALL(*mock_cast_socket_, Close(_));
+
+ 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