Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "base/memory/ptr_util.h" | |
| 8 #include "chrome/browser/profiles/profile.h" | |
| 9 #include "chrome/browser/ui/app_list/app_list_service_impl.h" | |
| 10 #include "chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus.h" | |
| 11 #include "services/ui/public/cpp/tests/window_tree_client_private.h" | |
| 12 #include "ui/views/mus/native_widget_mus.h" | |
| 13 #include "ui/app_list/app_list_switches.h" | |
| 14 #include "ui/app_list/presenter/app_list_presenter_delegate_factory.h" | |
| 15 #include "ui/app_list/presenter/app_list_presenter_impl.h" | |
| 16 #include "ui/app_list/presenter/app_list_view_delegate_factory.h" | |
| 17 #include "ui/app_list/presenter/test/app_list_presenter_impl_test_api.h" | |
| 18 #include "ui/app_list/views/app_list_view.h" | |
| 19 #include "ui/app_list/views/app_list_main_view.h" | |
| 20 #include "ui/app_list/views/contents_view.h" | |
| 21 #include "ui/app_list/test/app_list_test_view_delegate.h" | |
| 22 #include "ui/events/test/test_event_handler.h" | |
| 23 #include "ui/views/controls/native/native_view_host.h" | |
| 24 #include "ui/views/mus/window_manager_connection.h" | |
| 25 #include "ui/views/test/focus_manager_test.h" | |
| 26 #include "ui/views/test/views_test_base.h" | |
| 27 #include "ui/views/widget/widget.h" | |
| 28 #include "ui/views/widget/widget_delegate.h" | |
| 29 #include "ui/views/widget/widget_observer.h" | |
| 30 #include "ui/wm/core/default_activation_client.h" | |
| 31 #include "ui/wm/core/window_util.h" | |
| 32 | |
| 33 #include <memory> | |
| 34 | |
| 35 namespace views { | |
| 36 | |
| 37 class AppListViewDelegateFactoryImpl | |
|
mfomitchev
2016/10/11 15:49:13
I'd move this next to AppListTestViewDelegate and
| |
| 38 : public app_list::AppListViewDelegateFactory { | |
| 39 public: | |
| 40 AppListViewDelegateFactoryImpl() {} | |
| 41 ~AppListViewDelegateFactoryImpl() override {} | |
| 42 | |
| 43 // app_list::AppListViewDelegateFactory: | |
| 44 app_list::AppListViewDelegate* GetDelegate() override { | |
| 45 if (!app_list_view_delegate_.get()) | |
| 46 app_list_view_delegate_.reset( | |
| 47 new app_list::test::AppListTestViewDelegate()); | |
| 48 return app_list_view_delegate_.get(); | |
| 49 } | |
| 50 | |
| 51 private: | |
| 52 std::unique_ptr<app_list::AppListViewDelegate> app_list_view_delegate_; | |
| 53 | |
| 54 // DISALLOW_COPY_AND_ASSIGN(AppListViewDelegateFactoryImpl); | |
|
mfomitchev
2016/10/11 15:49:13
You want this on pretty much all classes.
| |
| 55 }; | |
| 56 | |
| 57 class AppListPresenterDelegateFactoryMus | |
| 58 : public app_list::AppListPresenterDelegateFactory { | |
| 59 public: | |
| 60 explicit AppListPresenterDelegateFactoryMus( | |
| 61 std::unique_ptr<app_list::AppListViewDelegateFactory> | |
| 62 view_delegate_factory) | |
|
mfomitchev
2016/10/11 15:49:13
Rather than taking AppListViewDelegateFactory as a
| |
| 63 : view_delegate_factory_(std::move(view_delegate_factory)) {} | |
| 64 | |
| 65 ~AppListPresenterDelegateFactoryMus() override {} | |
| 66 | |
| 67 std::unique_ptr<app_list::AppListPresenterDelegate> GetDelegate( | |
| 68 app_list::AppListPresenter* presenter) override { | |
| 69 return base::MakeUnique<AppListPresenterDelegateMus>( | |
| 70 presenter, view_delegate_factory_.get()); | |
| 71 } | |
| 72 | |
| 73 private: | |
| 74 std::unique_ptr<app_list::AppListViewDelegateFactory> view_delegate_factory_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateFactoryMus); | |
| 77 }; | |
| 78 | |
| 79 class AppListPresenterDelegateMusTest : public ViewsTestBase { | |
| 80 public: | |
| 81 AppListPresenterDelegateMusTest() {} | |
|
mfomitchev
2016/10/11 15:49:13
You can probably initialize presenter_delegate_fac
| |
| 82 ~AppListPresenterDelegateMusTest() override {} | |
| 83 | |
| 84 // Creates a test widget. Takes ownership of |delegate|. | |
| 85 std::unique_ptr<Widget> CreateWidget(WidgetDelegate* delegate) { | |
| 86 std::unique_ptr<Widget> widget(new Widget()); | |
| 87 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | |
| 88 params.delegate = delegate; | |
| 89 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 90 params.bounds = initial_bounds(); | |
| 91 widget->Init(params); | |
| 92 return widget; | |
| 93 } | |
| 94 | |
| 95 // Returns a mouse pressed event inside the widget. Tests that place views | |
| 96 // within the widget that respond to the event must be constructed within the | |
| 97 // widget coordinate space such that they respond correctly. | |
| 98 std::unique_ptr<ui::MouseEvent> CreateMouseEvent() { | |
| 99 return base::MakeUnique<ui::MouseEvent>( | |
| 100 ui::ET_MOUSE_PRESSED, gfx::Point(50, 50), gfx::Point(50, 50), | |
| 101 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | |
| 102 } | |
| 103 | |
| 104 protected: | |
| 105 gfx::Rect initial_bounds() { return gfx::Rect(10, 20, 100, 200); } | |
| 106 std::unique_ptr<app_list::AppListPresenterDelegateFactory> | |
| 107 presenter_delegate_factory_; | |
| 108 | |
| 109 private: | |
| 110 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateMusTest); | |
| 111 }; | |
| 112 | |
| 113 // A view that reports any mouse press as handled. | |
| 114 class HandleMousePressView : public View { | |
| 115 public: | |
| 116 HandleMousePressView() {} | |
| 117 ~HandleMousePressView() override {} | |
| 118 | |
| 119 // View: | |
| 120 bool OnMousePressed(const ui::MouseEvent& event) override { return true; } | |
| 121 | |
| 122 private: | |
| 123 DISALLOW_COPY_AND_ASSIGN(HandleMousePressView); | |
| 124 }; | |
| 125 | |
| 126 TEST_F(AppListPresenterDelegateMusTest, HideOnFocusOut) { | |
| 127 // I'm trying to create presenter and view_delegate_factory arguments to | |
| 128 // call constructor | |
| 129 // AppListPresenterDelegateMus::AppListPresenterDelegateMus( | |
| 130 // app_list::AppListPresenter* presenter, | |
| 131 // app_list::AppListViewDelegateFactory* view_delegate_factory) | |
| 132 | |
| 133 // Compilation breaks if I uncomment 2 lines right below. | |
| 134 // presenter_delegate_factory_.reset(new AppListPresenterDelegateFactoryMus( | |
|
mfomitchev
2016/10/11 15:49:13
You probably need to std::move the unique_ptr, but
| |
| 135 // base::MakeUnique<AppListViewDelegateFactoryImpl>(nullptr))); | |
| 136 | |
| 137 // presenter_delegate_factory_.reset(temp); | |
|
mfomitchev
2016/10/11 15:49:13
You actually want to create AppListPresenterImpl a
| |
| 138 | |
| 139 // std::unique_ptr<Widget> widget(CreateWidget(nullptr)); | |
| 140 // widget->Show(); | |
| 141 | |
| 142 // View* content = new HandleMousePressView; | |
| 143 // content->SetBounds(10, 20, 90, 180); | |
|
mfomitchev
2016/10/11 15:49:13
Why not make the origin (0,0)? The view coord are
| |
| 144 // widget->GetContentsView()->AddChildView(content); | |
| 145 | |
| 146 // ui::test::TestEventHandler handler; | |
| 147 // content->AddPreTargetHandler(&handler); | |
| 148 | |
| 149 // std::unique_ptr<ui::MouseEvent> mouse = CreateMouseEvent(); | |
| 150 // NativeWidgetMus* native_widget = | |
| 151 // static_cast<NativeWidgetMus*>(widget->native_widget_private()); | |
| 152 // ui::WindowTreeClientPrivate test_api(native_widget->window()); | |
| 153 // test_api.CallOnWindowInputEvent(native_widget->window(), | |
| 154 // std::move(mouse)); | |
| 155 // EXPECT_EQ(1, handler.num_mouse_events()); | |
| 156 | |
| 157 // // widget->Show(); | |
| 158 | |
| 159 // // Deactivate the Widget, which deactivates the NativeWidgetMus. | |
| 160 // // widget->Deactivate(); | |
|
mfomitchev
2016/10/11 15:49:13
For this test, you probably don't need to activate
| |
| 161 | |
| 162 // // Re-activate the Widget, which actives the NativeWidgetMus. | |
| 163 // // widget->Activate(); | |
| 164 } | |
| 165 } | |
| OLD | NEW |