OLD | NEW |
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 Loading... |
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 dummy; |
| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest | 216 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest |
198 // always return true without actually running the test. Remove when fixed. | 217 // always return true without actually running the test. Remove when fixed. |
199 #if defined(OS_WIN) && !defined(NDEBUG) | 218 #if defined(OS_WIN) && !defined(NDEBUG) |
200 #define MAYBE_TestOpenSendCloseWithUrl DISABLED_TestOpenSendCloseWithUrl | 219 #define MAYBE_TestOpenSendCloseWithUrl DISABLED_TestOpenSendCloseWithUrl |
201 #else | 220 #else |
202 #define MAYBE_TestOpenSendCloseWithUrl TestOpenSendCloseWithUrl | 221 #define MAYBE_TestOpenSendCloseWithUrl TestOpenSendCloseWithUrl |
203 #endif | 222 #endif |
204 // Test loading extension, opening a channel with a URL, adding a listener, | 223 // Test loading extension, opening a channel with a URL, adding a listener, |
205 // writing, reading, and closing. | 224 // writing, reading, and closing. |
206 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenSendCloseWithUrl) { | 225 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenSendCloseWithUrl) { |
207 SetUpMockCastSocket(); | 226 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 | 227 |
225 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", | 228 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", |
226 "test_open_send_close_url.html")); | 229 "test_open_send_close_url.html")); |
227 } | 230 } |
228 | 231 |
229 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest | 232 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest |
230 // always return true without actually running the test. Remove when fixed. | 233 // always return true without actually running the test. Remove when fixed. |
231 #if defined(OS_WIN) && !defined(NDEBUG) | 234 #if defined(OS_WIN) && !defined(NDEBUG) |
232 #define MAYBE_TestOpenReceiveClose DISABLED_TestOpenReceiveClose | 235 #define MAYBE_TestOpenReceiveClose DISABLED_TestOpenReceiveClose |
233 #else | 236 #else |
(...skipping 19 matching lines...) Expand all Loading... |
253 | 256 |
254 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", | 257 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", |
255 "test_open_receive_close.html")); | 258 "test_open_receive_close.html")); |
256 | 259 |
257 ResultCatcher catcher; | 260 ResultCatcher catcher; |
258 CallOnMessage("some-message"); | 261 CallOnMessage("some-message"); |
259 CallOnMessage("some-message"); | 262 CallOnMessage("some-message"); |
260 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 263 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
261 } | 264 } |
262 | 265 |
| 266 // TODO(imcheng): Win Dbg has a workaround that makes RunExtensionSubtest |
| 267 // always return true without actually running the test. Remove when fixed. |
| 268 #if defined(OS_WIN) && !defined(NDEBUG) |
| 269 #define MAYBE_TestGetLogs DISABLED_TestGetLogs |
| 270 #else |
| 271 #define MAYBE_TestGetLogs TestGetLogs |
| 272 #endif |
| 273 // Test loading extension, execute a open-send-close sequence, then get logs. |
| 274 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestGetLogs) { |
| 275 SetUpOpenSendClose(); |
| 276 |
| 277 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", "test_get_logs.html")); |
| 278 } |
| 279 |
263 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest | 280 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest |
264 // always return true without actually running the test. Remove when fixed. | 281 // always return true without actually running the test. Remove when fixed. |
265 // Flaky on mac: crbug.com/393969 | 282 // Flaky on mac: crbug.com/393969 |
266 #if (defined(OS_WIN) && !defined(NDEBUG)) || defined(OS_MACOSX) | 283 #if (defined(OS_WIN) && !defined(NDEBUG)) || defined(OS_MACOSX) |
267 #define MAYBE_TestOpenError DISABLED_TestOpenError | 284 #define MAYBE_TestOpenError DISABLED_TestOpenError |
268 #else | 285 #else |
269 #define MAYBE_TestOpenError TestOpenError | 286 #define MAYBE_TestOpenError TestOpenError |
270 #endif | 287 #endif |
271 // Test the case when socket open results in an error. | 288 // Test the case when socket open results in an error. |
272 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenError) { | 289 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenError) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 cast_channel_send_function.get(), | 397 cast_channel_send_function.get(), |
381 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", " | 398 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", " |
382 "\"connectInfo\": " | 399 "\"connectInfo\": " |
383 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, " | 400 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, " |
384 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, " | 401 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, " |
385 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", " | 402 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", " |
386 "\"destinationId\": \"\", \"data\": \"data\"}]", | 403 "\"destinationId\": \"\", \"data\": \"data\"}]", |
387 browser()); | 404 browser()); |
388 EXPECT_EQ(error, "message_info.destination_id is required"); | 405 EXPECT_EQ(error, "message_info.destination_id is required"); |
389 } | 406 } |
OLD | NEW |