Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1179)

Side by Side Diff: ash/host/ash_window_tree_host_x11_unittest.cc

Issue 201573015: Introdcue AshWindowTreeHost and move ash/chrome specific code in WTH to ash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/host/ash_window_tree_host_x11.cc ('k') | ash/host/root_window_transformer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "ash/host/ash_window_tree_host_x11.h"
6
7 #undef None
8 #undef Bool
5 9
6 #include "base/sys_info.h" 10 #include "base/sys_info.h"
7 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/aura/test/aura_test_base.h" 12 #include "ui/aura/test/aura_test_base.h"
9 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
10 #include "ui/aura/window_event_dispatcher.h" 14 #include "ui/aura/window_event_dispatcher.h"
11 #include "ui/aura/window_tree_host_x11.h"
12 #include "ui/events/event_processor.h" 15 #include "ui/events/event_processor.h"
13 #include "ui/events/event_target.h" 16 #include "ui/events/event_target.h"
14 #include "ui/events/event_target_iterator.h" 17 #include "ui/events/event_target_iterator.h"
15 #include "ui/events/test/events_test_utils_x11.h" 18 #include "ui/events/test/events_test_utils_x11.h"
16 19
17 namespace { 20 namespace {
18 21
19 class RootWindowEventHandler : public ui::EventHandler { 22 class RootWindowEventHandler : public ui::EventHandler {
20 public: 23 public:
21 RootWindowEventHandler() : last_touch_type_(ui::ET_UNKNOWN), 24 explicit RootWindowEventHandler(aura::WindowTreeHost* host)
22 last_touch_id_(-1), 25 : target_(host->window()),
23 last_touch_location_(0, 0) { 26 last_touch_type_(ui::ET_UNKNOWN),
27 last_touch_id_(-1),
28 last_touch_location_(0, 0) {
29 target_->AddPreTargetHandler(this);
24 } 30 }
25 virtual ~RootWindowEventHandler () {} 31 virtual ~RootWindowEventHandler() { target_->RemovePreTargetHandler(this); }
26 32
27 // ui::EventHandler: 33 // ui::EventHandler:
28 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { 34 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
29 last_touch_id_ = event->touch_id(); 35 last_touch_id_ = event->touch_id();
30 last_touch_type_ = event->type(); 36 last_touch_type_ = event->type();
31 last_touch_location_ = event->location(); 37 last_touch_location_ = event->location();
32 } 38 }
33 39
34 ui::EventType last_touch_type() { 40 ui::EventType last_touch_type() { return last_touch_type_; }
35 return last_touch_type_;
36 }
37 41
38 int last_touch_id() { 42 int last_touch_id() { return last_touch_id_; }
39 return last_touch_id_;
40 }
41 43
42 gfx::Point last_touch_location() { 44 gfx::Point last_touch_location() { return last_touch_location_; }
43 return last_touch_location_;
44 }
45 45
46 private: 46 private:
47 ui::EventTarget* target_;
47 ui::EventType last_touch_type_; 48 ui::EventType last_touch_type_;
48 int last_touch_id_; 49 int last_touch_id_;
49 gfx::Point last_touch_location_; 50 gfx::Point last_touch_location_;
50 51
51 DISALLOW_COPY_AND_ASSIGN(RootWindowEventHandler); 52 DISALLOW_COPY_AND_ASSIGN(RootWindowEventHandler);
52 }; 53 };
53 54
54 } // namespace 55 } // namespace
55 56
56 namespace aura { 57 namespace ash {
57 58
58 typedef test::AuraTestBase WindowTreeHostX11Test; 59 typedef aura::test::AuraTestBase WindowTreeHostX11Test;
59 60
60 // Send X touch events to one WindowTreeHost. The WindowTreeHost's 61 // Send X touch events to one WindowTreeHost. The WindowTreeHost's
61 // delegate will get corresponding ui::TouchEvent if the touch events 62 // delegate will get corresponding ui::TouchEvent if the touch events
62 // are winthin the bound of the WindowTreeHost. 63 // are winthin the bound of the WindowTreeHost.
63 TEST_F(WindowTreeHostX11Test, DispatchTouchEventToOneRootWindow) { 64 TEST_F(WindowTreeHostX11Test, DispatchTouchEventToOneRootWindow) {
64 #if defined(OS_CHROMEOS)
65 // Fake a ChromeOS running env. 65 // Fake a ChromeOS running env.
66 const char* kLsbRelease = "CHROMEOS_RELEASE_NAME=Chromium OS\n"; 66 const char* kLsbRelease = "CHROMEOS_RELEASE_NAME=Chromium OS\n";
67 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); 67 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time());
68 #endif // defined(OS_CHROMEOS)
69 68
70 scoped_ptr<WindowTreeHostX11> window_tree_host( 69 scoped_ptr<AshWindowTreeHostX11> window_tree_host(
71 new WindowTreeHostX11(gfx::Rect(0, 0, 2560, 1700))); 70 new AshWindowTreeHostX11(gfx::Rect(0, 0, 2560, 1700)));
72 window_tree_host->InitHost(); 71 window_tree_host->InitHost();
73 scoped_ptr<RootWindowEventHandler> handler(new RootWindowEventHandler()); 72 scoped_ptr<RootWindowEventHandler> handler(
74 window_tree_host->window()->AddPreTargetHandler(handler.get()); 73 new RootWindowEventHandler(window_tree_host.get()));
75 74
76 std::vector<unsigned int> devices; 75 std::vector<unsigned int> devices;
77 devices.push_back(0); 76 devices.push_back(0);
78 ui::SetUpTouchDevicesForTest(devices); 77 ui::SetUpTouchDevicesForTest(devices);
79 std::vector<ui::Valuator> valuators; 78 std::vector<ui::Valuator> valuators;
80 79
81 EXPECT_EQ(ui::ET_UNKNOWN, handler->last_touch_type()); 80 EXPECT_EQ(ui::ET_UNKNOWN, handler->last_touch_type());
82 EXPECT_EQ(-1, handler->last_touch_id()); 81 EXPECT_EQ(-1, handler->last_touch_id());
83 82
84 ui::ScopedXI2Event scoped_xevent; 83 ui::ScopedXI2Event scoped_xevent;
85 #if defined(OS_CHROMEOS)
86 // This touch is out of bounds. 84 // This touch is out of bounds.
87 scoped_xevent.InitTouchEvent( 85 scoped_xevent.InitTouchEvent(
88 0, XI_TouchBegin, 5, gfx::Point(1500, 2500), valuators); 86 0, XI_TouchBegin, 5, gfx::Point(1500, 2500), valuators);
89 window_tree_host->DispatchEvent(scoped_xevent); 87 window_tree_host->DispatchEvent(scoped_xevent);
90 EXPECT_EQ(ui::ET_UNKNOWN, handler->last_touch_type()); 88 EXPECT_EQ(ui::ET_UNKNOWN, handler->last_touch_type());
91 EXPECT_EQ(-1, handler->last_touch_id()); 89 EXPECT_EQ(-1, handler->last_touch_id());
92 EXPECT_EQ(gfx::Point(0, 0), handler->last_touch_location()); 90 EXPECT_EQ(gfx::Point(0, 0), handler->last_touch_location());
93 #endif // defined(OS_CHROMEOS)
94 91
95 // Following touchs are within bounds and are passed to delegate. 92 // Following touchs are within bounds and are passed to delegate.
96 scoped_xevent.InitTouchEvent( 93 scoped_xevent.InitTouchEvent(
97 0, XI_TouchBegin, 5, gfx::Point(1500, 1500), valuators); 94 0, XI_TouchBegin, 5, gfx::Point(1500, 1500), valuators);
98 window_tree_host->DispatchEvent(scoped_xevent); 95 window_tree_host->DispatchEvent(scoped_xevent);
99 EXPECT_EQ(ui::ET_TOUCH_PRESSED, handler->last_touch_type()); 96 EXPECT_EQ(ui::ET_TOUCH_PRESSED, handler->last_touch_type());
100 EXPECT_EQ(0, handler->last_touch_id()); 97 EXPECT_EQ(0, handler->last_touch_id());
101 EXPECT_EQ(gfx::Point(1500, 1500), handler->last_touch_location()); 98 EXPECT_EQ(gfx::Point(1500, 1500), handler->last_touch_location());
102 99
103 scoped_xevent.InitTouchEvent( 100 scoped_xevent.InitTouchEvent(
104 0, XI_TouchUpdate, 5, gfx::Point(1500, 1600), valuators); 101 0, XI_TouchUpdate, 5, gfx::Point(1500, 1600), valuators);
105 window_tree_host->DispatchEvent(scoped_xevent); 102 window_tree_host->DispatchEvent(scoped_xevent);
106 EXPECT_EQ(ui::ET_TOUCH_MOVED, handler->last_touch_type()); 103 EXPECT_EQ(ui::ET_TOUCH_MOVED, handler->last_touch_type());
107 EXPECT_EQ(0, handler->last_touch_id()); 104 EXPECT_EQ(0, handler->last_touch_id());
108 EXPECT_EQ(gfx::Point(1500, 1600), handler->last_touch_location()); 105 EXPECT_EQ(gfx::Point(1500, 1600), handler->last_touch_location());
109 106
110 scoped_xevent.InitTouchEvent( 107 scoped_xevent.InitTouchEvent(
111 0, XI_TouchEnd, 5, gfx::Point(1500, 1600), valuators); 108 0, XI_TouchEnd, 5, gfx::Point(1500, 1600), valuators);
112 window_tree_host->DispatchEvent(scoped_xevent); 109 window_tree_host->DispatchEvent(scoped_xevent);
113 EXPECT_EQ(ui::ET_TOUCH_RELEASED, handler->last_touch_type()); 110 EXPECT_EQ(ui::ET_TOUCH_RELEASED, handler->last_touch_type());
114 EXPECT_EQ(0, handler->last_touch_id()); 111 EXPECT_EQ(0, handler->last_touch_id());
115 EXPECT_EQ(gfx::Point(1500, 1600), handler->last_touch_location()); 112 EXPECT_EQ(gfx::Point(1500, 1600), handler->last_touch_location());
116 113
114 handler.reset();
115
117 // Revert the CrOS testing env otherwise the following non-CrOS aura 116 // Revert the CrOS testing env otherwise the following non-CrOS aura
118 // tests will fail. 117 // tests will fail.
119 #if defined(OS_CHROMEOS)
120 // Fake a ChromeOS running env. 118 // Fake a ChromeOS running env.
121 kLsbRelease = ""; 119 kLsbRelease = "";
122 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); 120 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time());
123 #endif // defined(OS_CHROMEOS)
124 } 121 }
125 122
126 // Send X touch events to two WindowTreeHost. The WindowTreeHost which is 123 // Send X touch events to two WindowTreeHost. The WindowTreeHost which is
127 // the event target of the X touch events should generate the corresponding 124 // the event target of the X touch events should generate the corresponding
128 // ui::TouchEvent for its delegate. 125 // ui::TouchEvent for its delegate.
129 #if defined(OS_CHROMEOS)
130 TEST_F(WindowTreeHostX11Test, DispatchTouchEventToTwoRootWindow) { 126 TEST_F(WindowTreeHostX11Test, DispatchTouchEventToTwoRootWindow) {
131 // Fake a ChromeOS running env. 127 // Fake a ChromeOS running env.
132 const char* kLsbRelease = "CHROMEOS_RELEASE_NAME=Chromium OS\n"; 128 const char* kLsbRelease = "CHROMEOS_RELEASE_NAME=Chromium OS\n";
133 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); 129 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time());
134 130
135 scoped_ptr<WindowTreeHostX11> window_tree_host1( 131 scoped_ptr<AshWindowTreeHostX11> window_tree_host1(
136 new WindowTreeHostX11(gfx::Rect(0, 0, 2560, 1700))); 132 new AshWindowTreeHostX11(gfx::Rect(0, 0, 2560, 1700)));
137 window_tree_host1->InitHost(); 133 window_tree_host1->InitHost();
138 scoped_ptr<RootWindowEventHandler> handler1(new RootWindowEventHandler()); 134 scoped_ptr<RootWindowEventHandler> handler1(
139 window_tree_host1->window()->AddPreTargetHandler(handler1.get()); 135 new RootWindowEventHandler(window_tree_host1.get()));
140 136
141 int host2_y_offset = 1700; 137 int host2_y_offset = 1700;
142 scoped_ptr<WindowTreeHostX11> window_tree_host2( 138 scoped_ptr<AshWindowTreeHostX11> window_tree_host2(
143 new WindowTreeHostX11(gfx::Rect(0, host2_y_offset, 1920, 1080))); 139 new AshWindowTreeHostX11(gfx::Rect(0, host2_y_offset, 1920, 1080)));
144 window_tree_host2->InitHost(); 140 window_tree_host2->InitHost();
145 scoped_ptr<RootWindowEventHandler> handler2(new RootWindowEventHandler()); 141 scoped_ptr<RootWindowEventHandler> handler2(
146 window_tree_host2->window()->AddPreTargetHandler(handler2.get()); 142 new RootWindowEventHandler(window_tree_host2.get()));
147 143
148 std::vector<unsigned int> devices; 144 std::vector<unsigned int> devices;
149 devices.push_back(0); 145 devices.push_back(0);
150 ui::SetUpTouchDevicesForTest(devices); 146 ui::SetUpTouchDevicesForTest(devices);
151 std::vector<ui::Valuator> valuators; 147 std::vector<ui::Valuator> valuators;
152 148
153 EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type()); 149 EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type());
154 EXPECT_EQ(-1, handler1->last_touch_id()); 150 EXPECT_EQ(-1, handler1->last_touch_id());
155 EXPECT_EQ(ui::ET_UNKNOWN, handler2->last_touch_type()); 151 EXPECT_EQ(ui::ET_UNKNOWN, handler2->last_touch_type());
156 EXPECT_EQ(-1, handler2->last_touch_id()); 152 EXPECT_EQ(-1, handler2->last_touch_id());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 0, XI_TouchEnd, 5, gfx::Point(1500, 2550), valuators); 205 0, XI_TouchEnd, 5, gfx::Point(1500, 2550), valuators);
210 window_tree_host1->DispatchEvent(scoped_xevent); 206 window_tree_host1->DispatchEvent(scoped_xevent);
211 window_tree_host2->DispatchEvent(scoped_xevent); 207 window_tree_host2->DispatchEvent(scoped_xevent);
212 EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type()); 208 EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type());
213 EXPECT_EQ(-1, handler1->last_touch_id()); 209 EXPECT_EQ(-1, handler1->last_touch_id());
214 EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location()); 210 EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location());
215 EXPECT_EQ(ui::ET_TOUCH_RELEASED, handler2->last_touch_type()); 211 EXPECT_EQ(ui::ET_TOUCH_RELEASED, handler2->last_touch_type());
216 EXPECT_EQ(0, handler2->last_touch_id()); 212 EXPECT_EQ(0, handler2->last_touch_id());
217 EXPECT_EQ(gfx::Point(1500, 2550 - host2_y_offset), 213 EXPECT_EQ(gfx::Point(1500, 2550 - host2_y_offset),
218 handler2->last_touch_location()); 214 handler2->last_touch_location());
219
220 scoped_xevent.InitTouchEvent( 215 scoped_xevent.InitTouchEvent(
221 0, XI_TouchEnd, 6, gfx::Point(1600, 2650), valuators); 216 0, XI_TouchEnd, 6, gfx::Point(1600, 2650), valuators);
222 window_tree_host1->DispatchEvent(scoped_xevent); 217 window_tree_host1->DispatchEvent(scoped_xevent);
223 window_tree_host2->DispatchEvent(scoped_xevent); 218 window_tree_host2->DispatchEvent(scoped_xevent);
224 EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type()); 219 EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type());
225 EXPECT_EQ(-1, handler1->last_touch_id()); 220 EXPECT_EQ(-1, handler1->last_touch_id());
226 EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location()); 221 EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location());
227 EXPECT_EQ(ui::ET_TOUCH_RELEASED, handler2->last_touch_type()); 222 EXPECT_EQ(ui::ET_TOUCH_RELEASED, handler2->last_touch_type());
228 EXPECT_EQ(1, handler2->last_touch_id()); 223 EXPECT_EQ(1, handler2->last_touch_id());
229 EXPECT_EQ(gfx::Point(1600, 2650 - host2_y_offset), 224 EXPECT_EQ(gfx::Point(1600, 2650 - host2_y_offset),
230 handler2->last_touch_location()); 225 handler2->last_touch_location());
231 226
227 handler1.reset();
228 handler2.reset();
229
232 // Revert the CrOS testing env otherwise the following non-CrOS aura 230 // Revert the CrOS testing env otherwise the following non-CrOS aura
233 // tests will fail. 231 // tests will fail.
234 // Fake a ChromeOS running env. 232 // Fake a ChromeOS running env.
235 kLsbRelease = ""; 233 kLsbRelease = "";
236 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); 234 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time());
237 } 235 }
238 #endif // defined(OS_CHROMEOS)
239 236
240 } // namespace aura 237 } // namespace aura
OLDNEW
« no previous file with comments | « ash/host/ash_window_tree_host_x11.cc ('k') | ash/host/root_window_transformer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698