OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <utility> | 5 #include <utility> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 namespace test { | 24 namespace test { |
25 | 25 |
26 class EventProcessorTest : public testing::Test { | 26 class EventProcessorTest : public testing::Test { |
27 public: | 27 public: |
28 EventProcessorTest() {} | 28 EventProcessorTest() {} |
29 ~EventProcessorTest() override {} | 29 ~EventProcessorTest() override {} |
30 | 30 |
31 protected: | 31 protected: |
32 // testing::Test: | 32 // testing::Test: |
33 void SetUp() override { | 33 void SetUp() override { |
34 processor_.SetRoot(base::WrapUnique(new TestEventTarget())); | 34 processor_.SetRoot(base::MakeUnique<TestEventTarget>()); |
35 processor_.Reset(); | 35 processor_.Reset(); |
36 root()->SetEventTargeter( | 36 root()->SetEventTargeter( |
37 base::WrapUnique(new TestEventTargeter(root(), false))); | 37 base::MakeUnique<TestEventTargeter>(root(), false)); |
38 } | 38 } |
39 | 39 |
40 TestEventTarget* root() { | 40 TestEventTarget* root() { |
41 return static_cast<TestEventTarget*>(processor_.GetRootTarget()); | 41 return static_cast<TestEventTarget*>(processor_.GetRootTarget()); |
42 } | 42 } |
43 | 43 |
44 TestEventProcessor* processor() { | 44 TestEventProcessor* processor() { |
45 return &processor_; | 45 return &processor_; |
46 } | 46 } |
47 | 47 |
48 void DispatchEvent(Event* event) { | 48 void DispatchEvent(Event* event) { |
49 processor_.OnEventFromSource(event); | 49 processor_.OnEventFromSource(event); |
50 } | 50 } |
51 | 51 |
52 void SetTarget(TestEventTarget* target) { | 52 void SetTarget(TestEventTarget* target) { |
53 static_cast<TestEventTargeter*>(root()->GetEventTargeter()) | 53 static_cast<TestEventTargeter*>(root()->GetEventTargeter()) |
54 ->set_target(target); | 54 ->set_target(target); |
55 } | 55 } |
56 | 56 |
57 private: | 57 private: |
58 TestEventProcessor processor_; | 58 TestEventProcessor processor_; |
59 | 59 |
60 DISALLOW_COPY_AND_ASSIGN(EventProcessorTest); | 60 DISALLOW_COPY_AND_ASSIGN(EventProcessorTest); |
61 }; | 61 }; |
62 | 62 |
63 TEST_F(EventProcessorTest, Basic) { | 63 TEST_F(EventProcessorTest, Basic) { |
64 std::unique_ptr<TestEventTarget> child(new TestEventTarget()); | 64 std::unique_ptr<TestEventTarget> child(new TestEventTarget()); |
65 child->SetEventTargeter( | 65 child->SetEventTargeter( |
66 base::WrapUnique(new TestEventTargeter(child.get(), false))); | 66 base::MakeUnique<TestEventTargeter>(child.get(), false)); |
67 SetTarget(child.get()); | 67 SetTarget(child.get()); |
68 root()->AddChild(std::move(child)); | 68 root()->AddChild(std::move(child)); |
69 | 69 |
70 MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), | 70 MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), |
71 EventTimeForNow(), EF_NONE, EF_NONE); | 71 EventTimeForNow(), EF_NONE, EF_NONE); |
72 DispatchEvent(&mouse); | 72 DispatchEvent(&mouse); |
73 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); | 73 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); |
74 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); | 74 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); |
75 | 75 |
76 SetTarget(root()); | 76 SetTarget(root()); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 DispatchEvent(&mouse); | 368 DispatchEvent(&mouse); |
369 | 369 |
370 std::string expected[] = { "PreR", "PreC", "PreG", "G", "PostG", "PostC", | 370 std::string expected[] = { "PreR", "PreC", "PreG", "G", "PostG", "PostC", |
371 "PostR", "PreR", "PreC", "C", "PostC", "PostR", "PreR", "R", "PostR" }; | 371 "PostR", "PreR", "PreC", "C", "PostC", "PostR", "PreR", "R", "PostR" }; |
372 EXPECT_EQ(std::vector<std::string>( | 372 EXPECT_EQ(std::vector<std::string>( |
373 expected, expected + arraysize(expected)), recorder); | 373 expected, expected + arraysize(expected)), recorder); |
374 } | 374 } |
375 | 375 |
376 } // namespace test | 376 } // namespace test |
377 } // namespace ui | 377 } // namespace ui |
OLD | NEW |