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

Side by Side Diff: extensions/browser/api/cast_channel/cast_channel_apitest.cc

Issue 456213002: Cast channel: Add cast.channel.getLogs extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 6 years, 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/extensions/extension_function_test_utils.h" 9 #include "chrome/browser/extensions/extension_function_test_utils.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 api, ip_endpoint, &capturing_net_log_, api->GetLogger()); 109 api, ip_endpoint, &capturing_net_log_, api->GetLogger());
110 // Transfers ownership of the socket. 110 // Transfers ownership of the socket.
111 api->SetSocketForTest( 111 api->SetSocketForTest(
112 make_scoped_ptr<CastSocket>(mock_cast_socket_).Pass()); 112 make_scoped_ptr<CastSocket>(mock_cast_socket_).Pass());
113 113
114 // Set expectations on error_state(). 114 // Set expectations on error_state().
115 EXPECT_CALL(*mock_cast_socket_, error_state()) 115 EXPECT_CALL(*mock_cast_socket_, error_state())
116 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE)); 116 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE));
117 } 117 }
118 118
119 void SetUpOpenSendClose() {
120 SetUpMockCastSocket();
121 {
122 InSequence sequence;
123 EXPECT_CALL(*mock_cast_socket_, Connect(_))
124 .WillOnce(InvokeCompletionCallback<0>(net::OK));
125 EXPECT_CALL(*mock_cast_socket_, ready_state())
126 .WillOnce(Return(cast_channel::READY_STATE_OPEN));
127 EXPECT_CALL(*mock_cast_socket_, SendMessage(A<const MessageInfo&>(), _))
128 .WillOnce(InvokeCompletionCallback<1>(net::OK));
129 EXPECT_CALL(*mock_cast_socket_, ready_state())
130 .WillOnce(Return(cast_channel::READY_STATE_OPEN));
131 EXPECT_CALL(*mock_cast_socket_, Close(_))
132 .WillOnce(InvokeCompletionCallback<0>(net::OK));
133 EXPECT_CALL(*mock_cast_socket_, ready_state())
134 .WillOnce(Return(cast_channel::READY_STATE_CLOSED));
135 }
136 }
137
119 extensions::CastChannelAPI* GetApi() { 138 extensions::CastChannelAPI* GetApi() {
120 return extensions::CastChannelAPI::Get(profile()); 139 return extensions::CastChannelAPI::Get(profile());
121 } 140 }
122 141
123 void CallOnError(extensions::CastChannelAPI* api) { 142 void CallOnError(extensions::CastChannelAPI* api) {
124 api->OnError(mock_cast_socket_, 143 api->OnError(mock_cast_socket_,
125 cast_channel::CHANNEL_ERROR_CONNECT_ERROR); 144 cast_channel::CHANNEL_ERROR_CONNECT_ERROR);
126 } 145 }
127 146
128 protected: 147 protected:
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest 184 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest
166 // always return true without actually running the test. Remove when fixed. 185 // always return true without actually running the test. Remove when fixed.
167 #if defined(OS_WIN) && !defined(NDEBUG) 186 #if defined(OS_WIN) && !defined(NDEBUG)
168 #define MAYBE_TestOpenSendClose DISABLED_TestOpenSendClose 187 #define MAYBE_TestOpenSendClose DISABLED_TestOpenSendClose
169 #else 188 #else
170 #define MAYBE_TestOpenSendClose TestOpenSendClose 189 #define MAYBE_TestOpenSendClose TestOpenSendClose
171 #endif 190 #endif
172 // Test loading extension, opening a channel with ConnectInfo, adding a 191 // Test loading extension, opening a channel with ConnectInfo, adding a
173 // listener, writing, reading, and closing. 192 // listener, writing, reading, and closing.
174 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenSendClose) { 193 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenSendClose) {
175 SetUpMockCastSocket(); 194 SetUpOpenSendClose();
176
177 {
178 InSequence dummy;
179 EXPECT_CALL(*mock_cast_socket_, Connect(_))
180 .WillOnce(InvokeCompletionCallback<0>(net::OK));
181 EXPECT_CALL(*mock_cast_socket_, ready_state())
182 .WillOnce(Return(cast_channel::READY_STATE_OPEN));
183 EXPECT_CALL(*mock_cast_socket_, SendMessage(A<const MessageInfo&>(), _))
184 .WillOnce(InvokeCompletionCallback<1>(net::OK));
185 EXPECT_CALL(*mock_cast_socket_, ready_state())
186 .WillOnce(Return(cast_channel::READY_STATE_OPEN));
187 EXPECT_CALL(*mock_cast_socket_, Close(_))
188 .WillOnce(InvokeCompletionCallback<0>(net::OK));
189 EXPECT_CALL(*mock_cast_socket_, ready_state())
190 .WillOnce(Return(cast_channel::READY_STATE_CLOSED));
191 }
192 195
193 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", 196 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
194 "test_open_send_close.html")); 197 "test_open_send_close.html"));
195 } 198 }
196 199
197 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest 200 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest
198 // always return true without actually running the test. Remove when fixed. 201 // always return true without actually running the test. Remove when fixed.
199 #if defined(OS_WIN) && !defined(NDEBUG) 202 #if defined(OS_WIN) && !defined(NDEBUG)
200 #define MAYBE_TestOpenSendCloseWithUrl DISABLED_TestOpenSendCloseWithUrl 203 #define MAYBE_TestOpenSendCloseWithUrl DISABLED_TestOpenSendCloseWithUrl
201 #else 204 #else
202 #define MAYBE_TestOpenSendCloseWithUrl TestOpenSendCloseWithUrl 205 #define MAYBE_TestOpenSendCloseWithUrl TestOpenSendCloseWithUrl
203 #endif 206 #endif
204 // Test loading extension, opening a channel with a URL, adding a listener, 207 // Test loading extension, opening a channel with a URL, adding a listener,
205 // writing, reading, and closing. 208 // writing, reading, and closing.
206 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenSendCloseWithUrl) { 209 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenSendCloseWithUrl) {
207 SetUpMockCastSocket(); 210 SetUpOpenSendClose();
208
209 {
210 InSequence dummy;
211 EXPECT_CALL(*mock_cast_socket_, Connect(_))
212 .WillOnce(InvokeCompletionCallback<0>(net::OK));
213 EXPECT_CALL(*mock_cast_socket_, ready_state())
214 .WillOnce(Return(cast_channel::READY_STATE_OPEN));
215 EXPECT_CALL(*mock_cast_socket_, SendMessage(A<const MessageInfo&>(), _))
216 .WillOnce(InvokeCompletionCallback<1>(net::OK));
217 EXPECT_CALL(*mock_cast_socket_, ready_state())
218 .WillOnce(Return(cast_channel::READY_STATE_OPEN));
219 EXPECT_CALL(*mock_cast_socket_, Close(_))
220 .WillOnce(InvokeCompletionCallback<0>(net::OK));
221 EXPECT_CALL(*mock_cast_socket_, ready_state())
222 .WillOnce(Return(cast_channel::READY_STATE_CLOSED));
223 }
224 211
225 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", 212 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
226 "test_open_send_close_url.html")); 213 "test_open_send_close_url.html"));
227 } 214 }
228 215
229 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest 216 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest
230 // always return true without actually running the test. Remove when fixed. 217 // always return true without actually running the test. Remove when fixed.
231 #if defined(OS_WIN) && !defined(NDEBUG) 218 #if defined(OS_WIN) && !defined(NDEBUG)
232 #define MAYBE_TestOpenReceiveClose DISABLED_TestOpenReceiveClose 219 #define MAYBE_TestOpenReceiveClose DISABLED_TestOpenReceiveClose
233 #else 220 #else
234 #define MAYBE_TestOpenReceiveClose TestOpenReceiveClose 221 #define MAYBE_TestOpenReceiveClose TestOpenReceiveClose
235 #endif 222 #endif
236 // Test loading extension, opening a channel, adding a listener, 223 // Test loading extension, opening a channel, adding a listener,
237 // writing, reading, and closing. 224 // writing, reading, and closing.
238 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenReceiveClose) { 225 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenReceiveClose) {
239 SetUpMockCastSocket(); 226 SetUpMockCastSocket();
240 227
241 { 228 {
242 InSequence dummy; 229 InSequence sequence;
243 EXPECT_CALL(*mock_cast_socket_, Connect(_)) 230 EXPECT_CALL(*mock_cast_socket_, Connect(_))
244 .WillOnce(InvokeCompletionCallback<0>(net::OK)); 231 .WillOnce(InvokeCompletionCallback<0>(net::OK));
245 EXPECT_CALL(*mock_cast_socket_, ready_state()) 232 EXPECT_CALL(*mock_cast_socket_, ready_state())
246 .Times(3) 233 .Times(3)
247 .WillRepeatedly(Return(cast_channel::READY_STATE_OPEN)); 234 .WillRepeatedly(Return(cast_channel::READY_STATE_OPEN));
248 EXPECT_CALL(*mock_cast_socket_, Close(_)) 235 EXPECT_CALL(*mock_cast_socket_, Close(_))
249 .WillOnce(InvokeCompletionCallback<0>(net::OK)); 236 .WillOnce(InvokeCompletionCallback<0>(net::OK));
250 EXPECT_CALL(*mock_cast_socket_, ready_state()) 237 EXPECT_CALL(*mock_cast_socket_, ready_state())
251 .WillOnce(Return(cast_channel::READY_STATE_CLOSED)); 238 .WillOnce(Return(cast_channel::READY_STATE_CLOSED));
252 } 239 }
253 240
254 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", 241 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
255 "test_open_receive_close.html")); 242 "test_open_receive_close.html"));
256 243
257 ResultCatcher catcher; 244 ResultCatcher catcher;
258 CallOnMessage("some-message"); 245 CallOnMessage("some-message");
259 CallOnMessage("some-message"); 246 CallOnMessage("some-message");
260 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 247 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
261 } 248 }
262 249
250 // TODO(imcheng): Win Dbg has a workaround that makes RunExtensionSubtest
251 // always return true without actually running the test. Remove when fixed.
252 #if defined(OS_WIN) && !defined(NDEBUG)
253 #define MAYBE_TestGetLogs DISABLED_TestGetLogs
254 #else
255 #define MAYBE_TestGetLogs TestGetLogs
256 #endif
257 // Test loading extension, execute a open-send-close sequence, then get logs.
258 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestGetLogs) {
259 SetUpOpenSendClose();
260
261 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", "test_get_logs.html"));
262 }
263
263 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest 264 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest
264 // always return true without actually running the test. Remove when fixed. 265 // always return true without actually running the test. Remove when fixed.
265 // Flaky on mac: crbug.com/393969 266 // Flaky on mac: crbug.com/393969
266 #if (defined(OS_WIN) && !defined(NDEBUG)) || defined(OS_MACOSX) 267 #if (defined(OS_WIN) && !defined(NDEBUG)) || defined(OS_MACOSX)
267 #define MAYBE_TestOpenError DISABLED_TestOpenError 268 #define MAYBE_TestOpenError DISABLED_TestOpenError
268 #else 269 #else
269 #define MAYBE_TestOpenError TestOpenError 270 #define MAYBE_TestOpenError TestOpenError
270 #endif 271 #endif
271 // Test the case when socket open results in an error. 272 // Test the case when socket open results in an error.
272 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenError) { 273 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenError) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 cast_channel_send_function.get(), 381 cast_channel_send_function.get(),
381 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", " 382 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", "
382 "\"connectInfo\": " 383 "\"connectInfo\": "
383 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, " 384 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
384 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, " 385 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
385 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", " 386 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", "
386 "\"destinationId\": \"\", \"data\": \"data\"}]", 387 "\"destinationId\": \"\", \"data\": \"data\"}]",
387 browser()); 388 browser());
388 EXPECT_EQ(error, "message_info.destination_id is required"); 389 EXPECT_EQ(error, "message_info.destination_id is required");
389 } 390 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698