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

Side by Side Diff: ui/views/mus/drag_interactive_uitest.cc

Issue 2759463002: aura-mus: create an interactive ui test for drag and drop. (Closed)
Patch Set: General cleanup. Created 3 years, 9 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/strings/utf_string_conversions.h"
6 #include "services/ui/public/interfaces/window_server_test.mojom.h"
7 #include "services/ui/public/interfaces/window_tree_constants.mojom.h"
8 #include "ui/aura/mus/in_flight_change.h"
9 #include "ui/aura/mus/window_tree_host_mus.h"
10 #include "ui/aura/test/mus/change_completion_waiter.h"
11 #include "ui/events/event.h"
12 #include "ui/events/event_utils.h"
13 #include "ui/views/mus/mus_client.h"
14 #include "ui/views/test/widget_test.h"
15 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
16 #include "ui/views/widget/widget.h"
17
18 namespace views {
19 namespace test {
20 namespace {
21
22 class DraggableView : public views::View {
sky 2017/03/17 00:02:21 Please add comments for classes.
23 public:
24 DraggableView() {}
25 ~DraggableView() override {}
26
27 // views::View overrides:
28 int GetDragOperations(const gfx::Point& press_pt) override {
29 return ui::DragDropTypes::DRAG_MOVE;
30 }
31 void WriteDragData(const gfx::Point& press_pt,
32 OSExchangeData* data) override {
33 data->SetString(base::UTF8ToUTF16("test"));
34 }
35
36 private:
37 DISALLOW_COPY_AND_ASSIGN(DraggableView);
38 };
39
40 class TargetView : public views::View {
41 public:
42 TargetView() : dropped_(false) {}
43 ~TargetView() override {}
44
45 void WaitForDropped(base::Closure quit_closure) {
46 if (dropped_) {
47 quit_closure.Run();
48 return;
49 }
50
51 quit_closure_ = quit_closure;
52 }
53
54 // views::View overrides:
55 bool GetDropFormats(
56 int* formats,
57 std::set<ui::Clipboard::FormatType>* format_types) override {
58 *formats = ui::OSExchangeData::STRING;
59 return true;
60 }
61 bool AreDropTypesRequired() override { return false; }
62 bool CanDrop(const OSExchangeData& data) override { return true; }
63 int OnDragUpdated(const ui::DropTargetEvent& event) override {
64 return ui::DragDropTypes::DRAG_MOVE;
65 }
66 int OnPerformDrop(const ui::DropTargetEvent& event) override {
67 dropped_ = true;
68 if (quit_closure_)
69 quit_closure_.Run();
70 return ui::DragDropTypes::DRAG_MOVE;
71 }
72
73 bool dropped() const { return dropped_; }
74
75 private:
76 bool dropped_;
77
78 base::Closure quit_closure_;
79
80 DISALLOW_COPY_AND_ASSIGN(TargetView);
81 };
82
83 std::unique_ptr<ui::PointerEvent> CreateMouseMoveEvent(int x, int y) {
84 return base::MakeUnique<ui::PointerEvent>(ui::MouseEvent(
85 ui::ET_MOUSE_MOVED, gfx::Point(x, y), gfx::Point(x, y),
86 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_NONE));
87 }
88
89 std::unique_ptr<ui::PointerEvent> CreateMouseDownEvent(int x, int y) {
90 return base::MakeUnique<ui::PointerEvent>(
91 ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(x, y), gfx::Point(x, y),
92 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
93 ui::EF_LEFT_MOUSE_BUTTON));
94 }
95
96 std::unique_ptr<ui::PointerEvent> CreateMouseUpEvent(int x, int y) {
97 return base::MakeUnique<ui::PointerEvent>(
98 ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(x, y), gfx::Point(x, y),
99 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
100 ui::EF_LEFT_MOUSE_BUTTON));
101 }
102
103 } // namespace
104
105 using DragTestInteractive = WidgetTest;
106
107 void DragTest_Part3(int64_t display_id,
sky 2017/03/17 00:02:21 Please comment on why you need separate functions
Elliot Glaysher 2017/03/17 17:43:12 Done.
108 base::Closure quit_closure,
sky 2017/03/17 00:02:21 const base::Closure& on these?
Elliot Glaysher 2017/03/17 17:43:12 Done.
109 bool result) {
110 EXPECT_TRUE(result);
111 quit_closure.Run();
112 }
113
114 void DragTest_Part2(int64_t display_id,
115 base::Closure quit_closure,
116 bool result) {
117 EXPECT_TRUE(result);
118 if (!result)
119 quit_closure.Run();
120
121 ui::mojom::WindowServerTest* server_test =
122 MusClient::Get()->GetTestingInterface();
123 server_test->DispatchEvent(
124 display_id, CreateMouseUpEvent(30, 30),
125 base::Bind(&DragTest_Part3, display_id, quit_closure));
126 }
127
128 void DragTest_Part1(int64_t display_id,
129 base::Closure quit_closure,
130 bool result) {
131 EXPECT_TRUE(result);
132 if (!result)
133 quit_closure.Run();
134
135 ui::mojom::WindowServerTest* server_test =
136 MusClient::Get()->GetTestingInterface();
137 server_test->DispatchEvent(
138 display_id, CreateMouseMoveEvent(30, 30),
139 base::Bind(&DragTest_Part2, display_id, quit_closure));
140 }
141
142 TEST_F(DragTestInteractive, DragTest) {
143 Widget* source_widget = CreateTopLevelFramelessPlatformWidget();
144 View* source_view = new DraggableView;
145 source_widget->SetContentsView(source_view);
146 source_widget->Show();
147
148 aura::test::ChangeCompletionWaiter source_waiter(
149 MusClient::Get()->window_tree_client(), aura::ChangeType::BOUNDS, true);
150 source_widget->SetBounds(gfx::Rect(0, 0, 20, 20));
151 source_waiter.Wait();
152
153 Widget* target_widget = CreateTopLevelFramelessPlatformWidget();
154 TargetView* target_view = new TargetView;
155 target_widget->SetContentsView(target_view);
156 target_widget->Show();
157
158 aura::test::ChangeCompletionWaiter target_waiter(
159 MusClient::Get()->window_tree_client(), aura::ChangeType::BOUNDS, true);
160 target_widget->SetBounds(gfx::Rect(20, 20, 20, 20));
161 target_waiter.Wait();
162
163 auto* dnwa =
164 static_cast<DesktopNativeWidgetAura*>(source_widget->native_widget());
165 ASSERT_TRUE(dnwa);
166 auto* wth = static_cast<aura::WindowTreeHostMus*>(dnwa->host());
167 ASSERT_TRUE(wth);
168 int64_t display_id = wth->display_id();
169
170 {
171 base::RunLoop run_loop;
172 ui::mojom::WindowServerTest* server_test =
173 MusClient::Get()->GetTestingInterface();
174 server_test->DispatchEvent(
175 display_id, CreateMouseDownEvent(10, 10),
176 base::Bind(&DragTest_Part1, display_id, run_loop.QuitClosure()));
177
178 run_loop.Run();
179 }
180
181 // Wait for the event dispatch to cause the final drop signal.
182 {
183 base::RunLoop run_loop;
184 target_view->WaitForDropped(run_loop.QuitClosure());
185 run_loop.Run();
186 }
187
188 EXPECT_TRUE(target_view->dropped());
189
190 target_widget->Close();
191 source_widget->Close();
192 RunPendingMessages();
193 }
194
195 } // namespace test
196 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698