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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "chrome/browser/extensions/api/cast_channel/cast_channel_api.h" 8 #include "chrome/browser/extensions/api/cast_channel/cast_channel_api.h"
9 #include "chrome/browser/extensions/api/cast_channel/cast_socket.h" 9 #include "chrome/browser/extensions/api/cast_channel/cast_socket.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/common/extensions/api/cast_channel.h" 12 #include "chrome/common/extensions/api/cast_channel.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "extensions/common/switches.h" 14 #include "extensions/common/switches.h"
15 #include "net/base/capturing_net_log.h" 15 #include "net/base/capturing_net_log.h"
16 #include "net/base/completion_callback.h" 16 #include "net/base/completion_callback.h"
17 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
18 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gmock_mutant.h"
19 20
20 namespace cast_channel = extensions::api::cast_channel; 21 namespace cast_channel = extensions::api::cast_channel;
21 using cast_channel::CastSocket; 22 using cast_channel::CastSocket;
22 using cast_channel::ChannelError; 23 using cast_channel::ChannelError;
23 using cast_channel::MessageInfo; 24 using cast_channel::MessageInfo;
24 using cast_channel::ReadyState; 25 using cast_channel::ReadyState;
25 26
27 using ::testing::_;
26 using ::testing::A; 28 using ::testing::A;
27 using ::testing::_; 29 using ::testing::DoAll;
28 using ::testing::Invoke; 30 using ::testing::Invoke;
29 using ::testing::InSequence; 31 using ::testing::InSequence;
30 using ::testing::Return; 32 using ::testing::Return;
31 33
32 namespace { 34 namespace {
33 35
34 const char kTestExtensionId[] = "ddchlicdkolnonkihahngkmmmjnjlkkf"; 36 const char kTestExtensionId[] = "ddchlicdkolnonkihahngkmmmjnjlkkf";
35 37
36 static void FillMessageInfo(MessageInfo* message_info, 38 static void FillMessageInfo(MessageInfo* message_info,
37 const std::string& message) { 39 const std::string& message) {
38 message_info->namespace_ = "foo"; 40 message_info->namespace_ = "foo";
39 message_info->source_id = "src"; 41 message_info->source_id = "src";
40 message_info->destination_id = "dest"; 42 message_info->destination_id = "dest";
41 message_info->data.reset(new base::StringValue(message)); 43 message_info->data.reset(new base::StringValue(message));
42 } 44 }
43 45
44 ACTION_TEMPLATE(InvokeCompletionCallback, 46 ACTION_TEMPLATE(InvokeCompletionCallback,
45 HAS_1_TEMPLATE_PARAMS(int, k), 47 HAS_1_TEMPLATE_PARAMS(int, k),
46 AND_1_VALUE_PARAMS(result)) { 48 AND_1_VALUE_PARAMS(result)) {
47 ::std::tr1::get<k>(args).Run(result); 49 ::std::tr1::get<k>(args).Run(result);
48 } 50 }
49 51
52 ACTION_P2(InvokeDelegateOnError, api_test, api) {
53 api_test->CallOnError(api);
54 }
55
50 class MockCastSocket : public CastSocket { 56 class MockCastSocket : public CastSocket {
51 public: 57 public:
52 explicit MockCastSocket(CastSocket::Delegate* delegate, 58 explicit MockCastSocket(CastSocket::Delegate* delegate,
53 net::IPEndPoint ip_endpoint, 59 net::IPEndPoint ip_endpoint,
54 net::NetLog* net_log) 60 net::NetLog* net_log)
55 : CastSocket(kTestExtensionId, ip_endpoint, 61 : CastSocket(kTestExtensionId, ip_endpoint,
56 cast_channel::CHANNEL_AUTH_TYPE_SSL, delegate, net_log) {} 62 cast_channel::CHANNEL_AUTH_TYPE_SSL, delegate, net_log) {}
57 virtual ~MockCastSocket() {} 63 virtual ~MockCastSocket() {}
58 64
59 virtual bool CalledOnValidThread() const OVERRIDE { 65 virtual bool CalledOnValidThread() const OVERRIDE {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 101
96 // Set expectations on error_state(). 102 // Set expectations on error_state().
97 EXPECT_CALL(*mock_cast_socket_, error_state()) 103 EXPECT_CALL(*mock_cast_socket_, error_state())
98 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE)); 104 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE));
99 } 105 }
100 106
101 extensions::CastChannelAPI* GetApi() { 107 extensions::CastChannelAPI* GetApi() {
102 return extensions::CastChannelAPI::Get(profile()); 108 return extensions::CastChannelAPI::Get(profile());
103 } 109 }
104 110
111 void CallOnError(extensions::CastChannelAPI* api) {
112 api->OnError(mock_cast_socket_,
113 cast_channel::CHANNEL_ERROR_CONNECT_ERROR);
114 }
115
105 protected: 116 protected:
106 void CallOnMessage(const std::string& message) { 117 void CallOnMessage(const std::string& message) {
107 content::BrowserThread::PostTask( 118 content::BrowserThread::PostTask(
108 content::BrowserThread::IO, 119 content::BrowserThread::IO,
109 FROM_HERE, 120 FROM_HERE,
110 base::Bind(&CastChannelAPITest::DoCallOnMessage, this, 121 base::Bind(&CastChannelAPITest::DoCallOnMessage, this,
111 GetApi(), mock_cast_socket_, message)); 122 GetApi(), mock_cast_socket_, message));
112 } 123 }
113 124
114 void DoCallOnMessage(extensions::CastChannelAPI* api, 125 void DoCallOnMessage(extensions::CastChannelAPI* api,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 224 }
214 225
215 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", 226 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
216 "test_open_receive_close.html")); 227 "test_open_receive_close.html"));
217 228
218 ResultCatcher catcher; 229 ResultCatcher catcher;
219 CallOnMessage("some-message"); 230 CallOnMessage("some-message");
220 CallOnMessage("some-message"); 231 CallOnMessage("some-message");
221 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 232 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
222 } 233 }
234
235 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest
236 // always return true without actually running the test. Remove when fixed.
237 #if defined(OS_WIN) && !defined(NDEBUG)
238 #define MAYBE_TestOpenError DISABLED_TestOpenError
239 #else
240 #define MAYBE_TestOpenError TestOpenError
241 #endif
242 // Test the case when socket open results in an error.
243 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenError) {
244 SetUpMockCastSocket();
245
246 EXPECT_CALL(*mock_cast_socket_, Connect(_))
247 .WillOnce(DoAll(
248 InvokeDelegateOnError(this, GetApi()),
249 InvokeCompletionCallback<0>(net::ERR_FAILED)));
250 EXPECT_CALL(*mock_cast_socket_, ready_state())
251 .WillRepeatedly(Return(cast_channel::READY_STATE_CLOSED));
252 EXPECT_CALL(*mock_cast_socket_, Close(_));
253
254 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
255 "test_open_error.html"));
256
257 ResultCatcher catcher;
258 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
259 }
260
OLDNEW
« 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