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

Side by Side Diff: chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus_unittest.cc

Issue 2364173002: Add app_list_presenterr pointer in app_list_presenter_delegate_mus to use dismiss function (Closed)
Patch Set: remove unnecessary includes Created 4 years, 2 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 2013 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 "chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus.h"
6
7 #include <memory>
8 #include <string>
9
10 #include "base/command_line.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/ptr_util.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h"
15 #include "base/synchronization/waitable_event.h"
16 #include "base/threading/simple_thread.h"
17 #include "base/threading/thread.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/app_list/app_list_service_impl.h"
20 #include "chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus.h"
21 #include "services/shell/background/background_shell.h"
22 #include "services/shell/public/cpp/connector.h"
23 #include "services/shell/public/cpp/service.h"
24 #include "services/shell/public/cpp/service_context.h"
25
26 #include "services/ui/public/cpp/tests/window_tree_client_private.h"
27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/app_list/app_list_switches.h"
29 #include "ui/app_list/presenter/app_list_presenter_delegate_factory.h"
30 #include "ui/app_list/presenter/app_list_presenter_impl.h"
31 #include "ui/app_list/presenter/app_list_view_delegate_factory.h"
32 #include "ui/app_list/presenter/test/app_list_presenter_impl_test_api.h"
33 #include "ui/app_list/test/app_list_test_view_delegate.h"
34 #include "ui/app_list/views/app_list_main_view.h"
35 #include "ui/app_list/views/app_list_view.h"
36 #include "ui/app_list/views/contents_view.h"
37 #include "ui/events/event.h"
38 #include "ui/events/test/test_event_handler.h"
39 #include "ui/views/controls/native/native_view_host.h"
40 #include "ui/views/mus/native_widget_mus.h"
41 #include "ui/views/mus/views_mus_test_suite.h"
42 #include "ui/views/mus/window_manager_connection.h"
43 #include "ui/views/pointer_watcher.h"
44 #include "ui/views/test/focus_manager_test.h"
45 #include "ui/views/test/platform_test_helper.h"
46 #include "ui/views/test/scoped_views_test_helper.h"
47 #include "ui/views/test/views_test_base.h"
48 #include "ui/views/views_delegate.h"
49 #include "ui/views/views_test_suite.h"
50 #include "ui/views/widget/widget.h"
51 #include "ui/views/widget/widget_delegate.h"
52 #include "ui/views/widget/widget_observer.h"
53 #include "ui/wm/core/default_activation_client.h"
54 #include "ui/wm/core/window_util.h"
55
56 #include "ui/views/views_delegate.h"
57 #include "ui/views/test/test_views_delegate.h"
58
59 namespace views {
60
61 class AppListTestViewDelegateFactory
62 : public app_list::AppListViewDelegateFactory {
63 public:
64 AppListTestViewDelegateFactory() {
65 app_list_view_delegate_.reset(
66 new app_list::test::AppListTestViewDelegate());
67 }
68 ~AppListTestViewDelegateFactory() override {}
69
70 // app_list::AppListViewDelegateFactory:
71 app_list::AppListViewDelegate* GetDelegate() override {
72 return app_list_view_delegate_.get();
73 }
74
75 private:
76 std::unique_ptr<app_list::AppListViewDelegate> app_list_view_delegate_;
77
78 DISALLOW_COPY_AND_ASSIGN(AppListTestViewDelegateFactory);
79 };
80
81 class AppListPresenterDelegateFactoryMus
82 : public app_list::AppListPresenterDelegateFactory {
83 public:
84 AppListPresenterDelegateFactoryMus() {}
85
86 ~AppListPresenterDelegateFactoryMus() override {}
87
88 std::unique_ptr<app_list::AppListPresenterDelegate> GetDelegate(
89 app_list::AppListPresenter* presenter) override {
90 return base::MakeUnique<AppListPresenterDelegateMus>(
91 presenter, view_delegate_factory_);
92 }
93
94 app_list::AppListViewDelegateFactory* view_delegate_factory_;
95
96 private:
97 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateFactoryMus);
98 };
99
100 // class AppListPresenterDelegateMusTest : public ViewsTestBase {
101 class AppListPresenterDelegateMusTest : public testing::Test {
102 public:
103 AppListPresenterDelegateMusTest() {
104 app_list_presenter_delegate_factory_mus_ =
105 new AppListPresenterDelegateFactoryMus();
106
107 app_list_presenter_delegate_factory_mus_->view_delegate_factory_ =
108 new AppListTestViewDelegateFactory;
109
110 app_list_presenter_ = new app_list::AppListPresenterImpl(
111 app_list_presenter_delegate_factory_mus_);
112 }
113
114 void SetUp() override {
115 LOG(ERROR) << "\n\n\n Create SetUp AppListPresenterDelegateMusTest \n\n\n";
116 testing::Test::SetUp();
117 LOG(ERROR) << "\n\n\n End SetUp AppListPresenterDelegateMusTest \n\n\n";
118 }
119
120 void TearDown() override {
121 LOG(ERROR)
122 << "\n\n\n Create TearDown AppListPresenterDelegateMusTest \n\n\n";
123 testing::Test::TearDown();
124 LOG(ERROR)
125 << "\n\n\n End TearDown AppListPresenterDelegateMusTest SetUp \n\n\n";
126 }
127 ~AppListPresenterDelegateMusTest() override {}
128
129 // Creates a test widget. Takes ownership of |delegate|.
130 // std::unique_ptr<Widget> CreateWidget(WidgetDelegate* delegate) {
131 // std::unique_ptr<Widget> widget(new Widget());
132 // Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW) ;
133 // params.delegate = delegate;
134 // params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
135 // params.bounds = initial_bounds();
136 // widget->Init(params);
137 // return widget;
138 // }
139
140 int ack_callback_count() { return ack_callback_count_; }
141
142 // Returns a mouse pressed event inside the widget. Tests that place views
143 // within the widget that respond to the event must be constructed within the
144 // widget coordinate space such that they respond correctly.
145 std::unique_ptr<ui::MouseEvent> CreateMouseEvent() {
146 return base::MakeUnique<ui::MouseEvent>(
147 ui::ET_MOUSE_PRESSED, gfx::Point(50, 50), gfx::Point(50, 50),
148 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
149 }
150
151 protected:
152 gfx::Rect initial_bounds() { return gfx::Rect(0, 0, 100, 100); }
153 AppListPresenterDelegateFactoryMus* app_list_presenter_delegate_factory_mus_;
154 app_list::AppListPresenterImpl* app_list_presenter_;
155
156
157 private:
158 int ack_callback_count_ = 0;
159 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateMusTest);
160 };
161
162 // A view that reports any mouse press as handled.
163 class HandleMousePressView : public View {
164 public:
165 HandleMousePressView() {}
166 ~HandleMousePressView() override {}
167
168 // View:
169 bool OnMousePressed(const ui::MouseEvent& event) override { return true; }
170
171 private:
172 DISALLOW_COPY_AND_ASSIGN(HandleMousePressView);
173 };
174
175 TEST_F(AppListPresenterDelegateMusTest, HideOnFocusOut) {
176
177 // PlatformTestHelper* platform_test_helper = new PlatformTestHelper();
178
179 // platform_test_helper->SetIsMus();
180
181 // PlatformTestHelper::SetIsMus();
182 // Let other mojo apps know that we're running in tests. Do this with a
183 // command line flag to avoid making blocking calls to other processes for
184 // setup for tests (e.g. to unlock the screen in the window manager).
185 // EnsureCommandLineSwitch(ui::switches::kUseTestConfig);
186
187
188
189 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
190
191 // LOG(ERROR) << "About to create ScopedViewsTestHelper which should call Crea tePlatformTestHelper";
192
193 // ViewsMusTestSuite *views_mus_test_suite_ = new ViewsMusTestSuite(0,0);
194
195 // TestViewsDelegate test_views_delegate_;
196 // shell_connections_ = base::MakeUnique<ShellConnection>();
197 ScopedViewsTestHelper test_helper_;
198
199
200 // LOG(ERROR) << "End create ScopedViewsTestHelper which should call CreatePla tformTestHelper";
201 // AppListPresenterDelegateMus *app_list_presenter_delegate_mus_ =
202 // new AppListPresenterDelegateMus(app_list_presenter_,
203 // app_list_presenter_delegate_factory_mus_->view_delegate_factory_);
204
205 // app_list::AppListView* app_list_view_ = app_list_presenter_->GetView();
206
207 // app_list_view_ = nullptr;
208 // app_list_presenter_delegate_mus_ = nullptr;
209 // app_list_presenter_delegate_mus_->Init(app_list_view_, 0, 0);
210
211 // app_list_presenter_delegate_mus_.Init(content, )
212
213 // std::unique_ptr<Widget> widget(CreateWidget(nullptr));
214 // widget->Show();
215
216 // View* content = new HandleMousePressView;
217 // content->SetBounds(0, 0, 100, 100);
218 // widget->GetContentsView()->AddChildView(content);
219
220 // ui::test::TestEventHandler handler;
221 // content->AddPreTargetHandler(&handler);
222
223 // std::unique_ptr<ui::MouseEvent> mouse = CreateMouseEvent();
224 // NativeWidgetMus* native_widget =
225 // static_cast<NativeWidgetMus*>(widget->native_widget_private());
226 // ui::WindowTreeClientPrivate test_api(native_widget->window());
227 // test_api.CallOnWindowInputEvent(native_widget->window(),
228 // std::move(mouse));
229 // EXPECT_EQ(1, handler.num_mouse_events());
230
231 // widget->Show();
232
233 // Deactivate the Widget, which deactivates the NativeWidgetMus.
234 // widget->Deactivate();
235
236 // Re-activate the Widget, which actives the NativeWidgetMus.
237 // widget->Activate();
238
239 // ASSERTION STILL BREAKS HERE -> Test fails
240 ASSERT_TRUE(WindowManagerConnection::Exists());
241 }
242 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698