| 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 "blimp/net/browser_connection_handler.h" | 5 #include "blimp/net/browser_connection_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 std::string expected_serialized; | 42 std::string expected_serialized; |
| 43 std::string actual_serialized; | 43 std::string actual_serialized; |
| 44 expected_message.SerializeToString(&expected_serialized); | 44 expected_message.SerializeToString(&expected_serialized); |
| 45 actual_message.SerializeToString(&actual_serialized); | 45 actual_message.SerializeToString(&actual_serialized); |
| 46 return expected_serialized == actual_serialized; | 46 return expected_serialized == actual_serialized; |
| 47 } | 47 } |
| 48 | 48 |
| 49 class FakeFeature { | 49 class FakeFeature { |
| 50 public: | 50 public: |
| 51 FakeFeature(BlimpMessage::Type type, | 51 FakeFeature(BlimpMessage::FeatureCase type, |
| 52 BrowserConnectionHandler* connection_handler) { | 52 BrowserConnectionHandler* connection_handler) { |
| 53 outgoing_message_processor_ = | 53 outgoing_message_processor_ = |
| 54 connection_handler->RegisterFeature(type, &incoming_message_processor_); | 54 connection_handler->RegisterFeature(type, &incoming_message_processor_); |
| 55 } | 55 } |
| 56 | 56 |
| 57 ~FakeFeature() {} | 57 ~FakeFeature() {} |
| 58 | 58 |
| 59 BlimpMessageProcessor* outgoing_message_processor() { | 59 BlimpMessageProcessor* outgoing_message_processor() { |
| 60 return outgoing_message_processor_.get(); | 60 return outgoing_message_processor_.get(); |
| 61 } | 61 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 callback.Run(net::OK); | 106 callback.Run(net::OK); |
| 107 } | 107 } |
| 108 | 108 |
| 109 FakeBlimpConnection* other_end_ = nullptr; | 109 FakeBlimpConnection* other_end_ = nullptr; |
| 110 ConnectionErrorObserver* error_observer_ = nullptr; | 110 ConnectionErrorObserver* error_observer_ = nullptr; |
| 111 BlimpMessageProcessor* incoming_message_processor_ = nullptr; | 111 BlimpMessageProcessor* incoming_message_processor_ = nullptr; |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 std::unique_ptr<BlimpMessage> CreateInputMessage(int tab_id) { | 114 std::unique_ptr<BlimpMessage> CreateInputMessage(int tab_id) { |
| 115 std::unique_ptr<BlimpMessage> output(new BlimpMessage); | 115 std::unique_ptr<BlimpMessage> output(new BlimpMessage); |
| 116 output->set_type(BlimpMessage::INPUT); | 116 output->mutable_input(); |
| 117 output->set_target_tab_id(tab_id); | 117 output->set_target_tab_id(tab_id); |
| 118 return output; | 118 return output; |
| 119 } | 119 } |
| 120 | 120 |
| 121 std::unique_ptr<BlimpMessage> CreateControlMessage(int tab_id) { | 121 std::unique_ptr<BlimpMessage> CreateControlMessage(int tab_id) { |
| 122 std::unique_ptr<BlimpMessage> output(new BlimpMessage); | 122 std::unique_ptr<BlimpMessage> output(new BlimpMessage); |
| 123 output->set_type(BlimpMessage::TAB_CONTROL); | 123 output->mutable_tab_control(); |
| 124 output->set_target_tab_id(tab_id); | 124 output->set_target_tab_id(tab_id); |
| 125 return output; | 125 return output; |
| 126 } | 126 } |
| 127 | 127 |
| 128 class BrowserConnectionHandlerTest : public testing::Test { | 128 class BrowserConnectionHandlerTest : public testing::Test { |
| 129 public: | 129 public: |
| 130 BrowserConnectionHandlerTest() | 130 BrowserConnectionHandlerTest() |
| 131 : client_connection_handler_(new BrowserConnectionHandler), | 131 : client_connection_handler_(new BrowserConnectionHandler), |
| 132 engine_connection_handler_(new BrowserConnectionHandler) { | 132 engine_connection_handler_(new BrowserConnectionHandler) { |
| 133 SetupConnections(); | 133 SetupConnections(); |
| 134 | 134 |
| 135 client_input_feature_.reset( | 135 client_input_feature_.reset(new FakeFeature( |
| 136 new FakeFeature(BlimpMessage::INPUT, client_connection_handler_.get())); | 136 BlimpMessage::kInput, client_connection_handler_.get())); |
| 137 engine_input_feature_.reset( | 137 engine_input_feature_.reset(new FakeFeature( |
| 138 new FakeFeature(BlimpMessage::INPUT, engine_connection_handler_.get())); | 138 BlimpMessage::kInput, engine_connection_handler_.get())); |
| 139 client_control_feature_.reset(new FakeFeature( | 139 client_control_feature_.reset(new FakeFeature( |
| 140 BlimpMessage::TAB_CONTROL, client_connection_handler_.get())); | 140 BlimpMessage::kTabControl, client_connection_handler_.get())); |
| 141 engine_control_feature_.reset(new FakeFeature( | 141 engine_control_feature_.reset(new FakeFeature( |
| 142 BlimpMessage::TAB_CONTROL, engine_connection_handler_.get())); | 142 BlimpMessage::kTabControl, engine_connection_handler_.get())); |
| 143 } | 143 } |
| 144 | 144 |
| 145 ~BrowserConnectionHandlerTest() override {} | 145 ~BrowserConnectionHandlerTest() override {} |
| 146 void TearDown() override { base::RunLoop().RunUntilIdle(); } | 146 void TearDown() override { base::RunLoop().RunUntilIdle(); } |
| 147 | 147 |
| 148 protected: | 148 protected: |
| 149 void SetupConnections() { | 149 void SetupConnections() { |
| 150 client_connection_ = new FakeBlimpConnection(); | 150 client_connection_ = new FakeBlimpConnection(); |
| 151 engine_connection_ = new FakeBlimpConnection(); | 151 engine_connection_ = new FakeBlimpConnection(); |
| 152 client_connection_->set_other_end(engine_connection_); | 152 client_connection_->set_other_end(engine_connection_); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 // re-established. | 222 // re-established. |
| 223 client_input_feature_->outgoing_message_processor()->ProcessMessage( | 223 client_input_feature_->outgoing_message_processor()->ProcessMessage( |
| 224 std::move(client_input_message), net::CompletionCallback()); | 224 std::move(client_input_message), net::CompletionCallback()); |
| 225 | 225 |
| 226 // Simulates reconnection. | 226 // Simulates reconnection. |
| 227 SetupConnections(); | 227 SetupConnections(); |
| 228 } | 228 } |
| 229 | 229 |
| 230 } // namespace | 230 } // namespace |
| 231 } // namespace blimp | 231 } // namespace blimp |
| OLD | NEW |