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

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

Issue 1981803003: Move platform_window_mus_unittest to native_widget_mus_unittest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@native_widget_mus6
Patch Set: Show widgets before running tests that handle input events Created 4 years, 7 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
« no previous file with comments | « ui/views/mus/native_widget_mus_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/views/mus/platform_window_mus.h"
6
7 #include <memory>
8
9 #include "base/bind.h"
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/events/event.h"
15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/views/mus/native_widget_mus.h"
17 #include "ui/views/mus/window_tree_host_mus.h"
18 #include "ui/views/test/views_test_base.h"
19 #include "ui/views/widget/widget.h"
20 #include "ui/views/widget/widget_delegate.h"
21
22 using mus::mojom::EventResult;
23
24 namespace views {
25
26 class PlatformWindowMusTest : public ViewsTestBase {
27 public:
28 PlatformWindowMusTest() {}
29 ~PlatformWindowMusTest() override {}
30
31 int ack_callback_count() { return ack_callback_count_; }
32
33 void AckCallback(mus::mojom::EventResult result) {
34 ack_callback_count_++;
35 EXPECT_EQ(mus::mojom::EventResult::HANDLED, result);
36 }
37
38 // testing::Test:
39 void SetUp() override {
40 ViewsTestBase::SetUp();
41 widget_.reset(new Widget);
42 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
43 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
44 params.bounds = gfx::Rect(0, 0, 100, 100);
45 widget_->Init(params);
46 widget_->Show();
47 native_widget_ =
48 static_cast<NativeWidgetMus*>(widget_->native_widget_private());
49 platform_window_ = native_widget_->window_tree_host()->platform_window();
50 ASSERT_TRUE(platform_window_);
51 }
52
53 // Returns a mouse pressed event in the middle of the widget.
54 std::unique_ptr<ui::MouseEvent> CreateMouseEvent() {
55 return base::WrapUnique(new ui::MouseEvent(
56 ui::ET_MOUSE_PRESSED, gfx::Point(50, 50), gfx::Point(50, 50),
57 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
58 }
59
60 protected:
61 std::unique_ptr<Widget> widget_;
62
63 private:
64 NativeWidgetMus* native_widget_ = nullptr;
65 PlatformWindowMus* platform_window_ = nullptr;
66 int ack_callback_count_ = 0;
67
68 DISALLOW_COPY_AND_ASSIGN(PlatformWindowMusTest);
69 };
70
71 // TODO(markdittmer): Port these tests to native_widget_mus.
72 #if 0
73
74 // Tests that an incoming UI event is acked with the handled status.
75 TEST_F(PlatformWindowMusTest, EventAcked) {
76 View* content = new HandleMousePressView;
77 content->SetBounds(0, 0, 100, 100);
78 widget_->GetContentsView()->AddChildView(content);
79
80 // Dispatch an input event to the window and view.
81 std::unique_ptr<ui::MouseEvent> event = CreateMouseEvent();
82 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback(
83 new base::Callback<void(EventResult)>(base::Bind(
84 &PlatformWindowMusTest::AckCallback, base::Unretained(this))));
85 OnWindowInputEvent(*event, &ack_callback);
86
87 // The platform window took ownership of the callback and called it.
88 EXPECT_FALSE(ack_callback);
89 EXPECT_EQ(1, ack_callback_count());
90 }
91
92 // Tests that a window that is deleted during event handling properly acks the
93 // event.
94 TEST_F(PlatformWindowMusTest, EventAckedWithWindowDestruction) {
95 View* content = new DeleteWidgetView(&widget_);
96 content->SetBounds(0, 0, 100, 100);
97 widget_->GetContentsView()->AddChildView(content);
98
99 // Dispatch an input event to the window and view.
100 std::unique_ptr<ui::MouseEvent> event = CreateMouseEvent();
101 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback(
102 new base::Callback<void(EventResult)>(base::Bind(
103 &PlatformWindowMusTest::AckCallback, base::Unretained(this))));
104 OnWindowInputEvent(*event, &ack_callback);
105
106 // The widget was deleted.
107 EXPECT_FALSE(widget_);
108
109 // The platform window took ownership of the callback and called it.
110 EXPECT_FALSE(ack_callback);
111 EXPECT_EQ(1, ack_callback_count());
112 }
113
114 #endif // #if 0
115
116 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/native_widget_mus_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698