| 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" |
| 11 #include "blimp/common/proto/blimp_message.pb.h" | 11 #include "blimp/common/proto/blimp_message.pb.h" |
| 12 #include "blimp/net/test_common.h" | 12 #include "blimp/net/test_common.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 using testing::Return; | 16 using testing::Return; |
| 17 | 17 |
| 18 namespace blimp { | 18 namespace blimp { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const int kTargetTab = 123; | 21 const int kTargetTab = 123; |
| 22 | 22 |
| 23 // Verifies that the logged form of |msg| matches |expected|, modulo prefix |
| 24 // and suffix. |
| 25 void VerifyLogOutput(const std::string& expected_fragment, |
| 26 const BlimpMessage& msg) { |
| 27 std::string expected = "<BlimpMessage " + expected_fragment + " byte_size=" + |
| 28 std::to_string(msg.ByteSize()) + ">"; |
| 29 std::stringstream outstream; |
| 30 outstream << msg; |
| 31 EXPECT_EQ(expected, outstream.str()); |
| 32 } |
| 33 |
| 23 class LoggingTest : public testing::Test { | 34 class LoggingTest : public testing::Test { |
| 24 public: | 35 public: |
| 25 LoggingTest() {} | 36 LoggingTest() {} |
| 26 ~LoggingTest() override {} | 37 ~LoggingTest() override {} |
| 27 | 38 |
| 28 protected: | |
| 29 // Verifies that the logged form of |msg| matches |expected|, modulo prefix | |
| 30 // and suffix. | |
| 31 void VerifyLogOutput(const std::string& expected_fragment, | |
| 32 const BlimpMessage& msg) { | |
| 33 std::string expected = "<BlimpMessage " + expected_fragment + | |
| 34 " byte_size=" + std::to_string(msg.ByteSize()) + ">"; | |
| 35 std::stringstream outstream; | |
| 36 outstream << msg; | |
| 37 EXPECT_EQ(expected, outstream.str()); | |
| 38 } | |
| 39 | |
| 40 private: | 39 private: |
| 41 // Deletes the singleton on test termination. | 40 // Deletes the singleton on test termination. |
| 42 base::ShadowingAtExitManager at_exit_; | 41 base::ShadowingAtExitManager at_exit_; |
| 43 }; | 42 }; |
| 44 | 43 |
| 45 TEST_F(LoggingTest, Compositor) { | 44 TEST_F(LoggingTest, Compositor) { |
| 46 BlimpMessage base_msg; | 45 BlimpMessage base_msg; |
| 47 base_msg.set_type(BlimpMessage::COMPOSITOR); | 46 base_msg.set_type(BlimpMessage::COMPOSITOR); |
| 48 base_msg.set_target_tab_id(kTargetTab); | 47 base_msg.set_target_tab_id(kTargetTab); |
| 49 VerifyLogOutput("type=COMPOSITOR render_widget_id=0 target_tab_id=123", | 48 VerifyLogOutput("type=COMPOSITOR render_widget_id=0 target_tab_id=123", |
| 50 base_msg); | 49 base_msg); |
| 51 } | 50 } |
| 52 | 51 |
| 53 TEST_F(LoggingTest, Input) { | 52 TEST_F(LoggingTest, Input) { |
| 53 const char* fragment_format = |
| 54 "type=INPUT render_widget_id=1 timestamp_seconds=2.000000 subtype=%s" |
| 55 " target_tab_id=123"; |
| 56 |
| 54 BlimpMessage base_msg; | 57 BlimpMessage base_msg; |
| 55 base_msg.set_type(BlimpMessage::INPUT); | 58 base_msg.set_type(BlimpMessage::INPUT); |
| 56 base_msg.set_target_tab_id(kTargetTab); | 59 base_msg.set_target_tab_id(kTargetTab); |
| 57 VerifyLogOutput("type=INPUT render_widget_id=0 target_tab_id=123", base_msg); | 60 base_msg.mutable_input()->set_type(InputMessage::Type_GestureScrollBegin); |
| 61 base_msg.mutable_input()->set_render_widget_id(1); |
| 62 base_msg.mutable_input()->set_timestamp_seconds(2); |
| 63 VerifyLogOutput(base::StringPrintf(fragment_format, "GestureScrollBegin"), |
| 64 base_msg); |
| 65 |
| 66 base_msg.mutable_input()->set_type(InputMessage::Type_GestureScrollEnd); |
| 67 VerifyLogOutput(base::StringPrintf(fragment_format, "GestureScrollEnd"), |
| 68 base_msg); |
| 69 |
| 70 base_msg.mutable_input()->set_type(InputMessage::Type_GestureScrollUpdate); |
| 71 VerifyLogOutput(base::StringPrintf(fragment_format, "GestureScrollUpdate"), |
| 72 base_msg); |
| 73 |
| 74 base_msg.mutable_input()->set_type(InputMessage::Type_GestureFlingStart); |
| 75 VerifyLogOutput(base::StringPrintf(fragment_format, "GestureFlingStart"), |
| 76 base_msg); |
| 77 |
| 78 base_msg.mutable_input()->set_type(InputMessage::Type_GestureTap); |
| 79 VerifyLogOutput(base::StringPrintf(fragment_format, "GestureTap"), base_msg); |
| 80 |
| 81 base_msg.mutable_input()->set_type(InputMessage::Type_GesturePinchBegin); |
| 82 VerifyLogOutput(base::StringPrintf(fragment_format, "GesturePinchBegin"), |
| 83 base_msg); |
| 84 |
| 85 base_msg.mutable_input()->set_type(InputMessage::Type_GesturePinchEnd); |
| 86 VerifyLogOutput(base::StringPrintf(fragment_format, "GesturePinchEnd"), |
| 87 base_msg); |
| 88 |
| 89 base_msg.mutable_input()->set_type(InputMessage::Type_GesturePinchUpdate); |
| 90 VerifyLogOutput(base::StringPrintf(fragment_format, "GesturePinchUpdate"), |
| 91 base_msg); |
| 92 |
| 93 base_msg.mutable_input()->set_type(InputMessage::Type_GestureFlingCancel); |
| 94 base_msg.mutable_input() |
| 95 ->mutable_gesture_fling_cancel() |
| 96 ->set_prevent_boosting(true); |
| 97 VerifyLogOutput( |
| 98 "type=INPUT render_widget_id=1 timestamp_seconds=2.000000 " |
| 99 "subtype=GestureFlingCancel prevent_boosting=true target_tab_id=123", |
| 100 base_msg); |
| 58 } | 101 } |
| 59 | 102 |
| 60 TEST_F(LoggingTest, Navigation) { | 103 TEST_F(LoggingTest, Navigation) { |
| 61 BlimpMessage base_msg; | 104 BlimpMessage base_msg; |
| 62 base_msg.set_type(BlimpMessage::NAVIGATION); | 105 base_msg.set_type(BlimpMessage::NAVIGATION); |
| 63 base_msg.set_target_tab_id(kTargetTab); | 106 base_msg.set_target_tab_id(kTargetTab); |
| 64 | 107 |
| 65 BlimpMessage navigation_state_msg = base_msg; | 108 BlimpMessage navigation_state_msg = base_msg; |
| 66 navigation_state_msg.mutable_navigation()->set_type( | 109 navigation_state_msg.mutable_navigation()->set_type( |
| 67 NavigationMessage::NAVIGATION_STATE_CHANGED); | 110 NavigationMessage::NAVIGATION_STATE_CHANGED); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 created_msg); | 223 created_msg); |
| 181 | 224 |
| 182 BlimpMessage deleted_msg = base_msg; | 225 BlimpMessage deleted_msg = base_msg; |
| 183 deleted_msg.mutable_render_widget()->set_type(RenderWidgetMessage::DELETED); | 226 deleted_msg.mutable_render_widget()->set_type(RenderWidgetMessage::DELETED); |
| 184 VerifyLogOutput("type=RENDER_WIDGET subtype=DELETED render_widget_id=123", | 227 VerifyLogOutput("type=RENDER_WIDGET subtype=DELETED render_widget_id=123", |
| 185 deleted_msg); | 228 deleted_msg); |
| 186 } | 229 } |
| 187 | 230 |
| 188 } // namespace | 231 } // namespace |
| 189 } // namespace blimp | 232 } // namespace blimp |
| OLD | NEW |