Index: chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus_unittest.cc |
diff --git a/chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus_unittest.cc b/chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..92fcb1c72a62e1f0612a2ce0fe2810beaffba471 |
--- /dev/null |
+++ b/chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus_unittest.cc |
@@ -0,0 +1,165 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus.h" |
+ |
+#include "base/memory/ptr_util.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ui/app_list/app_list_service_impl.h" |
+#include "chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus.h" |
+#include "services/ui/public/cpp/tests/window_tree_client_private.h" |
+#include "ui/views/mus/native_widget_mus.h" |
+#include "ui/app_list/app_list_switches.h" |
+#include "ui/app_list/presenter/app_list_presenter_delegate_factory.h" |
+#include "ui/app_list/presenter/app_list_presenter_impl.h" |
+#include "ui/app_list/presenter/app_list_view_delegate_factory.h" |
+#include "ui/app_list/presenter/test/app_list_presenter_impl_test_api.h" |
+#include "ui/app_list/views/app_list_view.h" |
+#include "ui/app_list/views/app_list_main_view.h" |
+#include "ui/app_list/views/contents_view.h" |
+#include "ui/app_list/test/app_list_test_view_delegate.h" |
+#include "ui/events/test/test_event_handler.h" |
+#include "ui/views/controls/native/native_view_host.h" |
+#include "ui/views/mus/window_manager_connection.h" |
+#include "ui/views/test/focus_manager_test.h" |
+#include "ui/views/test/views_test_base.h" |
+#include "ui/views/widget/widget.h" |
+#include "ui/views/widget/widget_delegate.h" |
+#include "ui/views/widget/widget_observer.h" |
+#include "ui/wm/core/default_activation_client.h" |
+#include "ui/wm/core/window_util.h" |
+ |
+#include <memory> |
+ |
+namespace views { |
+ |
+class AppListViewDelegateFactoryImpl |
mfomitchev
2016/10/11 15:49:13
I'd move this next to AppListTestViewDelegate and
|
+ : public app_list::AppListViewDelegateFactory { |
+ public: |
+ AppListViewDelegateFactoryImpl() {} |
+ ~AppListViewDelegateFactoryImpl() override {} |
+ |
+ // app_list::AppListViewDelegateFactory: |
+ app_list::AppListViewDelegate* GetDelegate() override { |
+ if (!app_list_view_delegate_.get()) |
+ app_list_view_delegate_.reset( |
+ new app_list::test::AppListTestViewDelegate()); |
+ return app_list_view_delegate_.get(); |
+ } |
+ |
+ private: |
+ std::unique_ptr<app_list::AppListViewDelegate> app_list_view_delegate_; |
+ |
+ // DISALLOW_COPY_AND_ASSIGN(AppListViewDelegateFactoryImpl); |
mfomitchev
2016/10/11 15:49:13
You want this on pretty much all classes.
|
+}; |
+ |
+class AppListPresenterDelegateFactoryMus |
+ : public app_list::AppListPresenterDelegateFactory { |
+ public: |
+ explicit AppListPresenterDelegateFactoryMus( |
+ std::unique_ptr<app_list::AppListViewDelegateFactory> |
+ view_delegate_factory) |
mfomitchev
2016/10/11 15:49:13
Rather than taking AppListViewDelegateFactory as a
|
+ : view_delegate_factory_(std::move(view_delegate_factory)) {} |
+ |
+ ~AppListPresenterDelegateFactoryMus() override {} |
+ |
+ std::unique_ptr<app_list::AppListPresenterDelegate> GetDelegate( |
+ app_list::AppListPresenter* presenter) override { |
+ return base::MakeUnique<AppListPresenterDelegateMus>( |
+ presenter, view_delegate_factory_.get()); |
+ } |
+ |
+ private: |
+ std::unique_ptr<app_list::AppListViewDelegateFactory> view_delegate_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateFactoryMus); |
+}; |
+ |
+class AppListPresenterDelegateMusTest : public ViewsTestBase { |
+ public: |
+ AppListPresenterDelegateMusTest() {} |
mfomitchev
2016/10/11 15:49:13
You can probably initialize presenter_delegate_fac
|
+ ~AppListPresenterDelegateMusTest() override {} |
+ |
+ // Creates a test widget. Takes ownership of |delegate|. |
+ std::unique_ptr<Widget> CreateWidget(WidgetDelegate* delegate) { |
+ std::unique_ptr<Widget> widget(new Widget()); |
+ Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
+ params.delegate = delegate; |
+ params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
+ params.bounds = initial_bounds(); |
+ widget->Init(params); |
+ return widget; |
+ } |
+ |
+ // Returns a mouse pressed event inside the widget. Tests that place views |
+ // within the widget that respond to the event must be constructed within the |
+ // widget coordinate space such that they respond correctly. |
+ std::unique_ptr<ui::MouseEvent> CreateMouseEvent() { |
+ return base::MakeUnique<ui::MouseEvent>( |
+ ui::ET_MOUSE_PRESSED, gfx::Point(50, 50), gfx::Point(50, 50), |
+ base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
+ } |
+ |
+ protected: |
+ gfx::Rect initial_bounds() { return gfx::Rect(10, 20, 100, 200); } |
+ std::unique_ptr<app_list::AppListPresenterDelegateFactory> |
+ presenter_delegate_factory_; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateMusTest); |
+}; |
+ |
+// A view that reports any mouse press as handled. |
+class HandleMousePressView : public View { |
+ public: |
+ HandleMousePressView() {} |
+ ~HandleMousePressView() override {} |
+ |
+ // View: |
+ bool OnMousePressed(const ui::MouseEvent& event) override { return true; } |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(HandleMousePressView); |
+}; |
+ |
+TEST_F(AppListPresenterDelegateMusTest, HideOnFocusOut) { |
+ // I'm trying to create presenter and view_delegate_factory arguments to |
+ // call constructor |
+ // AppListPresenterDelegateMus::AppListPresenterDelegateMus( |
+ // app_list::AppListPresenter* presenter, |
+ // app_list::AppListViewDelegateFactory* view_delegate_factory) |
+ |
+ // Compilation breaks if I uncomment 2 lines right below. |
+ // presenter_delegate_factory_.reset(new AppListPresenterDelegateFactoryMus( |
mfomitchev
2016/10/11 15:49:13
You probably need to std::move the unique_ptr, but
|
+ // base::MakeUnique<AppListViewDelegateFactoryImpl>(nullptr))); |
+ |
+ // presenter_delegate_factory_.reset(temp); |
mfomitchev
2016/10/11 15:49:13
You actually want to create AppListPresenterImpl a
|
+ |
+ // std::unique_ptr<Widget> widget(CreateWidget(nullptr)); |
+ // widget->Show(); |
+ |
+ // View* content = new HandleMousePressView; |
+ // content->SetBounds(10, 20, 90, 180); |
mfomitchev
2016/10/11 15:49:13
Why not make the origin (0,0)? The view coord are
|
+ // widget->GetContentsView()->AddChildView(content); |
+ |
+ // ui::test::TestEventHandler handler; |
+ // content->AddPreTargetHandler(&handler); |
+ |
+ // std::unique_ptr<ui::MouseEvent> mouse = CreateMouseEvent(); |
+ // NativeWidgetMus* native_widget = |
+ // static_cast<NativeWidgetMus*>(widget->native_widget_private()); |
+ // ui::WindowTreeClientPrivate test_api(native_widget->window()); |
+ // test_api.CallOnWindowInputEvent(native_widget->window(), |
+ // std::move(mouse)); |
+ // EXPECT_EQ(1, handler.num_mouse_events()); |
+ |
+ // // widget->Show(); |
+ |
+ // // Deactivate the Widget, which deactivates the NativeWidgetMus. |
+ // // widget->Deactivate(); |
mfomitchev
2016/10/11 15:49:13
For this test, you probably don't need to activate
|
+ |
+ // // Re-activate the Widget, which actives the NativeWidgetMus. |
+ // // widget->Activate(); |
+} |
+} |