Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "extensions/browser/api/cast_channel/keep_alive_delegate.h" | 5 #include "extensions/browser/api/cast_channel/keep_alive_delegate.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/test/simple_test_clock.h" | 13 #include "base/test/simple_test_clock.h" |
| 14 #include "base/timer/mock_timer.h" | 14 #include "base/timer/mock_timer.h" |
| 15 #include "extensions/browser/api/cast_channel/cast_test_util.h" | 15 #include "extensions/browser/api/cast_channel/cast_test_util.h" |
| 16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 using testing::_; | 20 using testing::_; |
| 21 using testing::Sequence; | |
| 21 | 22 |
| 22 namespace extensions { | 23 namespace extensions { |
| 23 namespace api { | 24 namespace api { |
| 24 namespace cast_channel { | 25 namespace cast_channel { |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 const int64_t kTestPingTimeoutMillis = 1000; | 28 const int64_t kTestPingTimeoutMillis = 1000; |
| 28 const int64_t kTestLivenessTimeoutMillis = 10000; | 29 const int64_t kTestLivenessTimeoutMillis = 10000; |
| 29 | 30 |
| 30 // Extends MockTimer with a mockable method ResetTriggered() which permits | 31 // Extends MockTimer with a mockable method ResetTriggered() which permits |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 EXPECT_CALL(*inner_delegate_, OnMessage(EqualsProto(other_message))); | 158 EXPECT_CALL(*inner_delegate_, OnMessage(EqualsProto(other_message))); |
| 158 EXPECT_CALL(*inner_delegate_, Start()); | 159 EXPECT_CALL(*inner_delegate_, Start()); |
| 159 EXPECT_CALL(*ping_timer_, ResetTriggered()).Times(2); | 160 EXPECT_CALL(*ping_timer_, ResetTriggered()).Times(2); |
| 160 EXPECT_CALL(*liveness_timer_, ResetTriggered()).Times(2); | 161 EXPECT_CALL(*liveness_timer_, ResetTriggered()).Times(2); |
| 161 | 162 |
| 162 keep_alive_->Start(); | 163 keep_alive_->Start(); |
| 163 keep_alive_->OnMessage(other_message); | 164 keep_alive_->OnMessage(other_message); |
| 164 RunPendingTasks(); | 165 RunPendingTasks(); |
| 165 } | 166 } |
| 166 | 167 |
| 168 TEST_F(KeepAliveDelegateTest, TestPassthroughMessagesAfterError) { | |
| 169 CastMessage message = | |
| 170 KeepAliveDelegate::CreateKeepAliveMessage("NEITHER_PING_NOR_PONG"); | |
| 171 CastMessage message_after_error = | |
| 172 KeepAliveDelegate::CreateKeepAliveMessage("ANOTHER_NOT_PING_NOR_PONG"); | |
| 173 CastMessage late_ping_message = KeepAliveDelegate::CreateKeepAliveMessage( | |
| 174 KeepAliveDelegate::kHeartbeatPingType); | |
| 175 | |
| 176 EXPECT_CALL(*inner_delegate_, Start()).Times(1); | |
| 177 EXPECT_CALL(*ping_timer_, ResetTriggered()).Times(2); | |
| 178 EXPECT_CALL(*liveness_timer_, ResetTriggered()).Times(2); | |
| 179 EXPECT_CALL(*liveness_timer_, Stop()).Times(1); | |
| 180 EXPECT_CALL(*ping_timer_, Stop()).Times(1); | |
| 181 | |
| 182 Sequence message_and_error_sequence; | |
| 183 EXPECT_CALL(*inner_delegate_, OnMessage(EqualsProto(message))) | |
| 184 .Times(1) | |
| 185 .InSequence(message_and_error_sequence) | |
| 186 .RetiresOnSaturation(); | |
| 187 EXPECT_CALL(*inner_delegate_, OnError(CHANNEL_ERROR_INVALID_MESSAGE)) | |
| 188 .Times(1) | |
| 189 .InSequence(message_and_error_sequence); | |
| 190 EXPECT_CALL(*inner_delegate_, OnMessage(EqualsProto(message_after_error))) | |
| 191 .Times(1) | |
| 192 .InSequence(message_and_error_sequence) | |
| 193 .RetiresOnSaturation(); | |
| 194 EXPECT_CALL(*inner_delegate_, OnMessage(EqualsProto(late_ping_message))) | |
| 195 .Times(0) | |
| 196 .InSequence(message_and_error_sequence) | |
| 197 .RetiresOnSaturation(); | |
| 198 | |
| 199 // Start, process one message, then error-out. KeepAliveDelegate will | |
| 200 // automatically stop itself. | |
| 201 keep_alive_->Start(); | |
| 202 keep_alive_->OnMessage(message); | |
| 203 RunPendingTasks(); | |
| 204 keep_alive_->OnError(CHANNEL_ERROR_INVALID_MESSAGE); | |
| 205 RunPendingTasks(); | |
| 206 | |
| 207 // Process a non-PING/PONG message and expect it to pass through. | |
| 208 keep_alive_->OnMessage(message_after_error); | |
| 209 RunPendingTasks(); | |
| 210 | |
| 211 // Process a late-arriving PING/PONG message, which should have no effect.. | |
|
Wez
2017/01/13 22:37:11
nit: Trailing .
miu
2017/01/15 02:17:08
Done.
| |
| 212 keep_alive_->OnMessage(late_ping_message); | |
| 213 RunPendingTasks(); | |
| 214 } | |
| 215 | |
| 167 } // namespace | 216 } // namespace |
| 168 } // namespace cast_channel | 217 } // namespace cast_channel |
| 169 } // namespace api | 218 } // namespace api |
| 170 } // namespace extensions | 219 } // namespace extensions |
| OLD | NEW |