Chromium Code Reviews| 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 | |
| 34 std::string GetExpectedFragmentOfInputMessage(const std::string& type) { | |
|
Kevin M
2016/04/05 17:59:13
We don't need to create a helper function like thi
haibinlu1
2016/04/05 18:19:57
Done.
| |
| 35 return "type=INPUT render_widget_id=1 timestamp_seconds=2.000000 subtype=" + | |
| 36 type + " target_tab_id=123"; | |
| 37 } | |
| 38 | |
| 23 class LoggingTest : public testing::Test { | 39 class LoggingTest : public testing::Test { |
| 24 public: | 40 public: |
| 25 LoggingTest() {} | 41 LoggingTest() {} |
| 26 ~LoggingTest() override {} | 42 ~LoggingTest() override {} |
| 27 | 43 |
| 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: | 44 private: |
| 41 // Deletes the singleton on test termination. | 45 // Deletes the singleton on test termination. |
| 42 base::ShadowingAtExitManager at_exit_; | 46 base::ShadowingAtExitManager at_exit_; |
| 43 }; | 47 }; |
| 44 | 48 |
| 45 TEST_F(LoggingTest, Compositor) { | 49 TEST_F(LoggingTest, Compositor) { |
| 46 BlimpMessage base_msg; | 50 BlimpMessage base_msg; |
| 47 base_msg.set_type(BlimpMessage::COMPOSITOR); | 51 base_msg.set_type(BlimpMessage::COMPOSITOR); |
| 48 base_msg.set_target_tab_id(kTargetTab); | 52 base_msg.set_target_tab_id(kTargetTab); |
| 49 VerifyLogOutput("type=COMPOSITOR render_widget_id=0 target_tab_id=123", | 53 VerifyLogOutput("type=COMPOSITOR render_widget_id=0 target_tab_id=123", |
| 50 base_msg); | 54 base_msg); |
| 51 } | 55 } |
| 52 | 56 |
| 53 TEST_F(LoggingTest, Input) { | 57 TEST_F(LoggingTest, Input) { |
| 54 BlimpMessage base_msg; | 58 BlimpMessage base_msg; |
| 55 base_msg.set_type(BlimpMessage::INPUT); | 59 base_msg.set_type(BlimpMessage::INPUT); |
| 56 base_msg.set_target_tab_id(kTargetTab); | 60 base_msg.set_target_tab_id(kTargetTab); |
| 57 VerifyLogOutput("type=INPUT render_widget_id=0 target_tab_id=123", base_msg); | 61 base_msg.mutable_input()->set_type(InputMessage::Type_GestureScrollBegin); |
| 62 base_msg.mutable_input()->set_render_widget_id(1); | |
| 63 base_msg.mutable_input()->set_timestamp_seconds(2); | |
| 64 VerifyLogOutput(GetExpectedFragmentOfInputMessage("GestureScrollBegin"), | |
| 65 base_msg); | |
| 66 | |
| 67 base_msg.mutable_input()->set_type(InputMessage::Type_GestureScrollEnd); | |
| 68 VerifyLogOutput(GetExpectedFragmentOfInputMessage("GestureScrollEnd"), | |
| 69 base_msg); | |
| 70 | |
| 71 base_msg.mutable_input()->set_type(InputMessage::Type_GestureScrollUpdate); | |
| 72 VerifyLogOutput(GetExpectedFragmentOfInputMessage("GestureScrollUpdate"), | |
| 73 base_msg); | |
| 74 | |
| 75 base_msg.mutable_input()->set_type(InputMessage::Type_GestureFlingStart); | |
| 76 VerifyLogOutput(GetExpectedFragmentOfInputMessage("GestureFlingStart"), | |
| 77 base_msg); | |
| 78 | |
| 79 base_msg.mutable_input()->set_type(InputMessage::Type_GestureTap); | |
| 80 VerifyLogOutput(GetExpectedFragmentOfInputMessage("GestureTap"), base_msg); | |
| 81 | |
| 82 base_msg.mutable_input()->set_type(InputMessage::Type_GesturePinchBegin); | |
| 83 VerifyLogOutput(GetExpectedFragmentOfInputMessage("GesturePinchBegin"), | |
| 84 base_msg); | |
| 85 | |
| 86 base_msg.mutable_input()->set_type(InputMessage::Type_GesturePinchEnd); | |
| 87 VerifyLogOutput(GetExpectedFragmentOfInputMessage("GesturePinchEnd"), | |
| 88 base_msg); | |
| 89 | |
| 90 base_msg.mutable_input()->set_type(InputMessage::Type_GesturePinchUpdate); | |
| 91 VerifyLogOutput(GetExpectedFragmentOfInputMessage("GesturePinchUpdate"), | |
| 92 base_msg); | |
| 93 | |
| 94 base_msg.mutable_input()->set_type(InputMessage::Type_GestureFlingCancel); | |
| 95 base_msg.mutable_input() | |
| 96 ->mutable_gesture_fling_cancel() | |
| 97 ->set_prevent_boosting(true); | |
| 98 VerifyLogOutput( | |
| 99 "type=INPUT render_widget_id=1 timestamp_seconds=2.000000 " | |
| 100 "subtype=GestureFlingCancel prevent_boosting=true target_tab_id=123", | |
| 101 base_msg); | |
| 58 } | 102 } |
| 59 | 103 |
| 60 TEST_F(LoggingTest, Navigation) { | 104 TEST_F(LoggingTest, Navigation) { |
| 61 BlimpMessage base_msg; | 105 BlimpMessage base_msg; |
| 62 base_msg.set_type(BlimpMessage::NAVIGATION); | 106 base_msg.set_type(BlimpMessage::NAVIGATION); |
| 63 base_msg.set_target_tab_id(kTargetTab); | 107 base_msg.set_target_tab_id(kTargetTab); |
| 64 | 108 |
| 65 BlimpMessage navigation_state_msg = base_msg; | 109 BlimpMessage navigation_state_msg = base_msg; |
| 66 navigation_state_msg.mutable_navigation()->set_type( | 110 navigation_state_msg.mutable_navigation()->set_type( |
| 67 NavigationMessage::NAVIGATION_STATE_CHANGED); | 111 NavigationMessage::NAVIGATION_STATE_CHANGED); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 created_msg); | 224 created_msg); |
| 181 | 225 |
| 182 BlimpMessage deleted_msg = base_msg; | 226 BlimpMessage deleted_msg = base_msg; |
| 183 deleted_msg.mutable_render_widget()->set_type(RenderWidgetMessage::DELETED); | 227 deleted_msg.mutable_render_widget()->set_type(RenderWidgetMessage::DELETED); |
| 184 VerifyLogOutput("type=RENDER_WIDGET subtype=DELETED render_widget_id=123", | 228 VerifyLogOutput("type=RENDER_WIDGET subtype=DELETED render_widget_id=123", |
| 185 deleted_msg); | 229 deleted_msg); |
| 186 } | 230 } |
| 187 | 231 |
| 188 } // namespace | 232 } // namespace |
| 189 } // namespace blimp | 233 } // namespace blimp |
| OLD | NEW |