| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <sstream> | 5 #include <sstream> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "blimp/common/logging.h" | 10 #include "blimp/common/logging.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 LoggingTest() {} | 36 LoggingTest() {} |
| 37 ~LoggingTest() override {} | 37 ~LoggingTest() override {} |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 // Deletes the singleton on test termination. | 40 // Deletes the singleton on test termination. |
| 41 base::ShadowingAtExitManager at_exit_; | 41 base::ShadowingAtExitManager at_exit_; |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 TEST_F(LoggingTest, Compositor) { | 44 TEST_F(LoggingTest, Compositor) { |
| 45 BlimpMessage base_msg; | 45 BlimpMessage base_msg; |
| 46 base_msg.set_type(BlimpMessage::COMPOSITOR); | 46 base_msg.mutable_compositor(); |
| 47 base_msg.set_target_tab_id(kTargetTab); | 47 base_msg.set_target_tab_id(kTargetTab); |
| 48 VerifyLogOutput("type=COMPOSITOR render_widget_id=0 target_tab_id=123", | 48 VerifyLogOutput("type=COMPOSITOR render_widget_id=0 target_tab_id=123", |
| 49 base_msg); | 49 base_msg); |
| 50 } | 50 } |
| 51 | 51 |
| 52 TEST_F(LoggingTest, Input) { | 52 TEST_F(LoggingTest, Input) { |
| 53 const char* fragment_format = | 53 const char* fragment_format = |
| 54 "type=INPUT render_widget_id=1 timestamp_seconds=2.000000 subtype=%s" | 54 "type=INPUT render_widget_id=1 timestamp_seconds=2.000000 subtype=%s" |
| 55 " target_tab_id=123"; | 55 " target_tab_id=123"; |
| 56 | 56 |
| 57 BlimpMessage base_msg; | 57 BlimpMessage base_msg; |
| 58 base_msg.set_type(BlimpMessage::INPUT); | |
| 59 base_msg.set_target_tab_id(kTargetTab); | 58 base_msg.set_target_tab_id(kTargetTab); |
| 60 base_msg.mutable_input()->set_type(InputMessage::Type_GestureScrollBegin); | 59 base_msg.mutable_input()->set_type(InputMessage::Type_GestureScrollBegin); |
| 61 base_msg.mutable_input()->set_render_widget_id(1); | 60 base_msg.mutable_input()->set_render_widget_id(1); |
| 62 base_msg.mutable_input()->set_timestamp_seconds(2); | 61 base_msg.mutable_input()->set_timestamp_seconds(2); |
| 63 VerifyLogOutput(base::StringPrintf(fragment_format, "GestureScrollBegin"), | 62 VerifyLogOutput(base::StringPrintf(fragment_format, "GestureScrollBegin"), |
| 64 base_msg); | 63 base_msg); |
| 65 | 64 |
| 66 base_msg.mutable_input()->set_type(InputMessage::Type_GestureScrollEnd); | 65 base_msg.mutable_input()->set_type(InputMessage::Type_GestureScrollEnd); |
| 67 VerifyLogOutput(base::StringPrintf(fragment_format, "GestureScrollEnd"), | 66 VerifyLogOutput(base::StringPrintf(fragment_format, "GestureScrollEnd"), |
| 68 base_msg); | 67 base_msg); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 95 ->mutable_gesture_fling_cancel() | 94 ->mutable_gesture_fling_cancel() |
| 96 ->set_prevent_boosting(true); | 95 ->set_prevent_boosting(true); |
| 97 VerifyLogOutput( | 96 VerifyLogOutput( |
| 98 "type=INPUT render_widget_id=1 timestamp_seconds=2.000000 " | 97 "type=INPUT render_widget_id=1 timestamp_seconds=2.000000 " |
| 99 "subtype=GestureFlingCancel prevent_boosting=true target_tab_id=123", | 98 "subtype=GestureFlingCancel prevent_boosting=true target_tab_id=123", |
| 100 base_msg); | 99 base_msg); |
| 101 } | 100 } |
| 102 | 101 |
| 103 TEST_F(LoggingTest, Navigation) { | 102 TEST_F(LoggingTest, Navigation) { |
| 104 BlimpMessage base_msg; | 103 BlimpMessage base_msg; |
| 105 base_msg.set_type(BlimpMessage::NAVIGATION); | |
| 106 base_msg.set_target_tab_id(kTargetTab); | 104 base_msg.set_target_tab_id(kTargetTab); |
| 107 | 105 |
| 108 BlimpMessage navigation_state_msg = base_msg; | 106 BlimpMessage navigation_state_msg = base_msg; |
| 109 navigation_state_msg.mutable_navigation()->set_type( | 107 navigation_state_msg.mutable_navigation()->set_type( |
| 110 NavigationMessage::NAVIGATION_STATE_CHANGED); | 108 NavigationMessage::NAVIGATION_STATE_CHANGED); |
| 111 navigation_state_msg.mutable_navigation() | 109 navigation_state_msg.mutable_navigation() |
| 112 ->mutable_navigation_state_changed() | 110 ->mutable_navigation_state_changed() |
| 113 ->set_url("http://foo.com"); | 111 ->set_url("http://foo.com"); |
| 114 navigation_state_msg.mutable_navigation() | 112 navigation_state_msg.mutable_navigation() |
| 115 ->mutable_navigation_state_changed() | 113 ->mutable_navigation_state_changed() |
| (...skipping 29 matching lines...) Expand all Loading... |
| 145 go_forward_msg); | 143 go_forward_msg); |
| 146 | 144 |
| 147 BlimpMessage reload_msg = base_msg; | 145 BlimpMessage reload_msg = base_msg; |
| 148 reload_msg.mutable_navigation()->set_type(NavigationMessage::RELOAD); | 146 reload_msg.mutable_navigation()->set_type(NavigationMessage::RELOAD); |
| 149 VerifyLogOutput("type=NAVIGATION subtype=RELOAD target_tab_id=123", | 147 VerifyLogOutput("type=NAVIGATION subtype=RELOAD target_tab_id=123", |
| 150 reload_msg); | 148 reload_msg); |
| 151 } | 149 } |
| 152 | 150 |
| 153 TEST_F(LoggingTest, TabControl) { | 151 TEST_F(LoggingTest, TabControl) { |
| 154 BlimpMessage base_msg; | 152 BlimpMessage base_msg; |
| 155 base_msg.set_type(BlimpMessage::TAB_CONTROL); | |
| 156 base_msg.set_target_tab_id(kTargetTab); | 153 base_msg.set_target_tab_id(kTargetTab); |
| 157 | 154 |
| 158 BlimpMessage create_tab_msg = base_msg; | 155 BlimpMessage create_tab_msg = base_msg; |
| 159 create_tab_msg.mutable_tab_control()->set_type(TabControlMessage::CREATE_TAB); | 156 create_tab_msg.mutable_tab_control()->set_type(TabControlMessage::CREATE_TAB); |
| 160 VerifyLogOutput("type=TAB_CONTROL subtype=CREATE_TAB target_tab_id=123", | 157 VerifyLogOutput("type=TAB_CONTROL subtype=CREATE_TAB target_tab_id=123", |
| 161 create_tab_msg); | 158 create_tab_msg); |
| 162 | 159 |
| 163 BlimpMessage close_tab_msg = base_msg; | 160 BlimpMessage close_tab_msg = base_msg; |
| 164 close_tab_msg.mutable_tab_control()->set_type(TabControlMessage::CLOSE_TAB); | 161 close_tab_msg.mutable_tab_control()->set_type(TabControlMessage::CLOSE_TAB); |
| 165 VerifyLogOutput("type=TAB_CONTROL subtype=CLOSE_TAB target_tab_id=123", | 162 VerifyLogOutput("type=TAB_CONTROL subtype=CLOSE_TAB target_tab_id=123", |
| 166 close_tab_msg); | 163 close_tab_msg); |
| 167 | 164 |
| 168 BlimpMessage size_msg = base_msg; | 165 BlimpMessage size_msg = base_msg; |
| 169 size_msg.mutable_tab_control()->set_type(TabControlMessage::SIZE); | 166 size_msg.mutable_tab_control()->set_type(TabControlMessage::SIZE); |
| 170 size_msg.mutable_tab_control()->mutable_size()->set_width(640); | 167 size_msg.mutable_tab_control()->mutable_size()->set_width(640); |
| 171 size_msg.mutable_tab_control()->mutable_size()->set_height(480); | 168 size_msg.mutable_tab_control()->mutable_size()->set_height(480); |
| 172 size_msg.mutable_tab_control()->mutable_size()->set_device_pixel_ratio(2); | 169 size_msg.mutable_tab_control()->mutable_size()->set_device_pixel_ratio(2); |
| 173 VerifyLogOutput( | 170 VerifyLogOutput( |
| 174 "type=TAB_CONTROL subtype=SIZE size=640x480:2.00 target_tab_id=123", | 171 "type=TAB_CONTROL subtype=SIZE size=640x480:2.00 target_tab_id=123", |
| 175 size_msg); | 172 size_msg); |
| 176 } | 173 } |
| 177 | 174 |
| 178 TEST_F(LoggingTest, ProtocolControl) { | 175 TEST_F(LoggingTest, ProtocolControl) { |
| 179 BlimpMessage base_msg; | 176 BlimpMessage base_msg; |
| 180 base_msg.set_type(BlimpMessage::PROTOCOL_CONTROL); | |
| 181 | 177 |
| 182 BlimpMessage start_connection_msg = base_msg; | 178 BlimpMessage start_connection_msg = base_msg; |
| 183 start_connection_msg.mutable_protocol_control()->set_type( | 179 start_connection_msg.mutable_protocol_control()->set_type( |
| 184 ProtocolControlMessage::START_CONNECTION); | 180 ProtocolControlMessage::START_CONNECTION); |
| 185 start_connection_msg.mutable_protocol_control() | 181 start_connection_msg.mutable_protocol_control() |
| 186 ->mutable_start_connection() | 182 ->mutable_start_connection() |
| 187 ->set_client_token("token"); | 183 ->set_client_token("token"); |
| 188 start_connection_msg.mutable_protocol_control() | 184 start_connection_msg.mutable_protocol_control() |
| 189 ->mutable_start_connection() | 185 ->mutable_start_connection() |
| 190 ->set_protocol_version(2); | 186 ->set_protocol_version(2); |
| 191 VerifyLogOutput( | 187 VerifyLogOutput( |
| 192 "type=PROTOCOL_CONTROL subtype=START_CONNECTION " | 188 "type=PROTOCOL_CONTROL subtype=START_CONNECTION " |
| 193 "client_token=\"token\" protocol_version=2", | 189 "client_token=\"token\" protocol_version=2", |
| 194 start_connection_msg); | 190 start_connection_msg); |
| 195 | 191 |
| 196 BlimpMessage checkpoint_msg = base_msg; | |
| 197 start_connection_msg.mutable_protocol_control()->set_type( | 192 start_connection_msg.mutable_protocol_control()->set_type( |
| 198 ProtocolControlMessage::CHECKPOINT_ACK); | 193 ProtocolControlMessage::CHECKPOINT_ACK); |
| 199 start_connection_msg.mutable_protocol_control() | 194 start_connection_msg.mutable_protocol_control() |
| 200 ->mutable_checkpoint_ack() | 195 ->mutable_checkpoint_ack() |
| 201 ->set_checkpoint_id(123); | 196 ->set_checkpoint_id(123); |
| 202 VerifyLogOutput( | 197 VerifyLogOutput( |
| 203 "type=PROTOCOL_CONTROL subtype=CHECKPOINT_ACK " | 198 "type=PROTOCOL_CONTROL subtype=CHECKPOINT_ACK " |
| 204 "checkpoint_id=123", | 199 "checkpoint_id=123", |
| 205 start_connection_msg); | 200 start_connection_msg); |
| 206 } | 201 } |
| 207 | 202 |
| 208 TEST_F(LoggingTest, RenderWidget) { | 203 TEST_F(LoggingTest, RenderWidget) { |
| 209 BlimpMessage base_msg; | 204 BlimpMessage base_msg; |
| 210 base_msg.set_type(BlimpMessage::RENDER_WIDGET); | |
| 211 base_msg.mutable_render_widget()->set_render_widget_id(123); | 205 base_msg.mutable_render_widget()->set_render_widget_id(123); |
| 212 | 206 |
| 213 BlimpMessage initialize_msg = base_msg; | 207 BlimpMessage initialize_msg = base_msg; |
| 214 initialize_msg.mutable_render_widget()->set_type( | 208 initialize_msg.mutable_render_widget()->set_type( |
| 215 RenderWidgetMessage::INITIALIZE); | 209 RenderWidgetMessage::INITIALIZE); |
| 216 VerifyLogOutput("type=RENDER_WIDGET subtype=INITIALIZE render_widget_id=123", | 210 VerifyLogOutput("type=RENDER_WIDGET subtype=INITIALIZE render_widget_id=123", |
| 217 initialize_msg); | 211 initialize_msg); |
| 218 | 212 |
| 219 BlimpMessage created_msg = base_msg; | 213 BlimpMessage created_msg = base_msg; |
| 220 created_msg.mutable_render_widget()->set_type( | 214 created_msg.mutable_render_widget()->set_type( |
| 221 RenderWidgetMessage::CREATED); | 215 RenderWidgetMessage::CREATED); |
| 222 VerifyLogOutput("type=RENDER_WIDGET subtype=CREATED render_widget_id=123", | 216 VerifyLogOutput("type=RENDER_WIDGET subtype=CREATED render_widget_id=123", |
| 223 created_msg); | 217 created_msg); |
| 224 | 218 |
| 225 BlimpMessage deleted_msg = base_msg; | 219 BlimpMessage deleted_msg = base_msg; |
| 226 deleted_msg.mutable_render_widget()->set_type(RenderWidgetMessage::DELETED); | 220 deleted_msg.mutable_render_widget()->set_type(RenderWidgetMessage::DELETED); |
| 227 VerifyLogOutput("type=RENDER_WIDGET subtype=DELETED render_widget_id=123", | 221 VerifyLogOutput("type=RENDER_WIDGET subtype=DELETED render_widget_id=123", |
| 228 deleted_msg); | 222 deleted_msg); |
| 229 } | 223 } |
| 230 | 224 |
| 231 TEST_F(LoggingTest, Settings) { | 225 TEST_F(LoggingTest, Settings) { |
| 232 BlimpMessage message; | 226 BlimpMessage message; |
| 233 message.set_type(BlimpMessage::SETTINGS); | |
| 234 message.mutable_settings() | 227 message.mutable_settings() |
| 235 ->mutable_engine_settings() | 228 ->mutable_engine_settings() |
| 236 ->set_record_whole_document(true); | 229 ->set_record_whole_document(true); |
| 237 message.mutable_settings()->mutable_engine_settings()->set_client_os_info( | 230 message.mutable_settings()->mutable_engine_settings()->set_client_os_info( |
| 238 "wibble"); | 231 "wibble"); |
| 239 VerifyLogOutput( | 232 VerifyLogOutput( |
| 240 "type=SETTINGS subtype=ENGINE_SETTINGS record_whole_document=true " | 233 "type=SETTINGS subtype=ENGINE_SETTINGS record_whole_document=true " |
| 241 "client_os_info=\"wibble\"", | 234 "client_os_info=\"wibble\"", |
| 242 message); | 235 message); |
| 243 } | 236 } |
| 244 | 237 |
| 245 } // namespace | 238 } // namespace |
| 246 } // namespace blimp | 239 } // namespace blimp |
| OLD | NEW |