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 "base/memory/scoped_ptr.h" |
| 6 #include "ui/app_list/shower/app_list_shower_delegate_factory.h" |
| 7 #include "ui/app_list/shower/app_list_shower_impl.h" |
| 8 #include "ui/app_list/shower/test/app_list_shower_impl_test_api.h" |
| 9 #include "ui/app_list/test/app_list_test_view_delegate.h" |
| 10 #include "ui/app_list/views/app_list_view.h" |
| 11 #include "ui/aura/client/focus_client.h" |
| 12 #include "ui/aura/test/aura_test_base.h" |
| 13 #include "ui/aura/window.h" |
| 14 #include "ui/wm/core/default_activation_client.h" |
| 15 #include "ui/wm/core/window_util.h" |
| 16 |
| 17 namespace app_list { |
| 18 |
| 19 namespace { |
| 20 |
| 21 // Test stub for AppListShowerDelegate |
| 22 class AppListShowerDelegateTest : public AppListShowerDelegate { |
| 23 public: |
| 24 AppListShowerDelegateTest(aura::Window* container, |
| 25 test::AppListTestViewDelegate* view_delegate) |
| 26 : container_(container), view_delegate_(view_delegate) {} |
| 27 ~AppListShowerDelegateTest() override {} |
| 28 |
| 29 bool init_called() const { return init_called_; } |
| 30 bool on_shown_called() const { return on_shown_called_; } |
| 31 bool on_dismissed_called() const { return on_dismissed_called_; } |
| 32 bool update_bounds_called() const { return update_bounds_called_; } |
| 33 |
| 34 private: |
| 35 // AppListShowerDelegate: |
| 36 AppListViewDelegate* GetViewDelegate() override { return view_delegate_; } |
| 37 void Init(AppListView* view, |
| 38 aura::Window* root_window, |
| 39 int current_apps_page) override { |
| 40 init_called_ = true; |
| 41 view_ = view; |
| 42 view->InitAsFramelessWindow(container_, current_apps_page, |
| 43 gfx::Rect(100, 50, 300, 200)); |
| 44 } |
| 45 void OnShown(aura::Window*) override { on_shown_called_ = true; } |
| 46 void OnDismissed() override { on_dismissed_called_ = true; } |
| 47 void UpdateBounds() override { update_bounds_called_ = true; } |
| 48 gfx::Vector2d GetVisibilityAnimationOffset(aura::Window*) override { |
| 49 return gfx::Vector2d(0, 0); |
| 50 } |
| 51 |
| 52 private: |
| 53 aura::Window* container_; |
| 54 test::AppListTestViewDelegate* view_delegate_; |
| 55 AppListView* view_ = nullptr; |
| 56 bool init_called_ = false; |
| 57 bool on_shown_called_ = false; |
| 58 bool on_dismissed_called_ = false; |
| 59 bool update_bounds_called_ = false; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(AppListShowerDelegateTest); |
| 62 }; |
| 63 |
| 64 // Test fake for AppListShowerDelegateFactory, creates instances of |
| 65 // AppListShowerDelegateTest. |
| 66 class AppListShowerDelegateFactoryTest : public AppListShowerDelegateFactory { |
| 67 public: |
| 68 explicit AppListShowerDelegateFactoryTest(aura::Window* container) |
| 69 : container_(container) {} |
| 70 ~AppListShowerDelegateFactoryTest() override {} |
| 71 |
| 72 AppListShowerDelegateTest* current_delegate() { return current_delegate_; } |
| 73 |
| 74 // AppListShowerDelegateFactory: |
| 75 scoped_ptr<AppListShowerDelegate> GetDelegate( |
| 76 AppListShower* shower) override { |
| 77 current_delegate_ = |
| 78 new AppListShowerDelegateTest(container_, &app_list_view_delegate_); |
| 79 return make_scoped_ptr(current_delegate_); |
| 80 } |
| 81 |
| 82 private: |
| 83 aura::Window* container_; |
| 84 AppListShowerDelegateTest* current_delegate_ = nullptr; |
| 85 test::AppListTestViewDelegate app_list_view_delegate_; |
| 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(AppListShowerDelegateFactoryTest); |
| 88 }; |
| 89 |
| 90 } // namespace |
| 91 |
| 92 class AppListShowerImplTest : public aura::test::AuraTestBase { |
| 93 public: |
| 94 AppListShowerImplTest(); |
| 95 ~AppListShowerImplTest() override; |
| 96 |
| 97 AppListShowerImpl* shower() { return shower_.get(); } |
| 98 aura::Window* container() { return container_.get(); } |
| 99 |
| 100 // Don't cache the return of this method - a new delegate is created every |
| 101 // time the app list is shown. |
| 102 AppListShowerDelegateTest* delegate() { return factory_->current_delegate(); } |
| 103 |
| 104 // aura::test::AuraTestBase: |
| 105 void SetUp() override; |
| 106 void TearDown() override; |
| 107 |
| 108 private: |
| 109 scoped_ptr<AppListShowerDelegateFactoryTest> factory_; |
| 110 scoped_ptr<AppListShowerImpl> shower_; |
| 111 scoped_ptr<aura::Window> container_; |
| 112 |
| 113 DISALLOW_COPY_AND_ASSIGN(AppListShowerImplTest); |
| 114 }; |
| 115 |
| 116 AppListShowerImplTest::AppListShowerImplTest() {} |
| 117 |
| 118 AppListShowerImplTest::~AppListShowerImplTest() {} |
| 119 |
| 120 void AppListShowerImplTest::SetUp() { |
| 121 AuraTestBase::SetUp(); |
| 122 new wm::DefaultActivationClient(root_window()); |
| 123 container_.reset(CreateNormalWindow(0, root_window(), nullptr)); |
| 124 factory_.reset(new AppListShowerDelegateFactoryTest(container_.get())); |
| 125 shower_.reset(new AppListShowerImpl(factory_.get())); |
| 126 } |
| 127 |
| 128 void AppListShowerImplTest::TearDown() { |
| 129 container_.reset(); |
| 130 AuraTestBase::TearDown(); |
| 131 } |
| 132 |
| 133 // Tests that app launcher is dismissed when focus moves to a window which is |
| 134 // not app list window's sibling and that appropriate delegate callbacks are |
| 135 // executed when the app launcher is shown and then when the app launcher is |
| 136 // dismissed. |
| 137 TEST_F(AppListShowerImplTest, HideOnFocusOut) { |
| 138 aura::client::FocusClient* focus_client = |
| 139 aura::client::GetFocusClient(root_window()); |
| 140 shower()->Show(container()); |
| 141 EXPECT_TRUE(delegate()->init_called()); |
| 142 EXPECT_TRUE(delegate()->on_shown_called()); |
| 143 EXPECT_FALSE(delegate()->on_dismissed_called()); |
| 144 EXPECT_FALSE(delegate()->update_bounds_called()); |
| 145 focus_client->FocusWindow(shower()->GetWindow()); |
| 146 EXPECT_TRUE(shower()->GetTargetVisibility()); |
| 147 |
| 148 scoped_ptr<aura::Window> window( |
| 149 CreateNormalWindow(1, root_window(), nullptr)); |
| 150 focus_client->FocusWindow(window.get()); |
| 151 |
| 152 EXPECT_TRUE(delegate()->on_dismissed_called()); |
| 153 EXPECT_FALSE(delegate()->update_bounds_called()); |
| 154 EXPECT_FALSE(shower()->GetTargetVisibility()); |
| 155 } |
| 156 |
| 157 // Tests that app launcher remains visible when focus moves to a window which |
| 158 // is app list window's sibling and that appropriate delegate callbacks are |
| 159 // executed when the app launcher is shown. |
| 160 TEST_F(AppListShowerImplTest, RemainVisibleWhenFocusingToSibling) { |
| 161 aura::client::FocusClient* focus_client = |
| 162 aura::client::GetFocusClient(root_window()); |
| 163 shower()->Show(container()); |
| 164 focus_client->FocusWindow(shower()->GetWindow()); |
| 165 EXPECT_TRUE(shower()->GetTargetVisibility()); |
| 166 EXPECT_TRUE(delegate()->init_called()); |
| 167 EXPECT_TRUE(delegate()->on_shown_called()); |
| 168 EXPECT_FALSE(delegate()->on_dismissed_called()); |
| 169 EXPECT_FALSE(delegate()->update_bounds_called()); |
| 170 |
| 171 // Create a sibling window. |
| 172 scoped_ptr<aura::Window> window(CreateNormalWindow(1, container(), nullptr)); |
| 173 focus_client->FocusWindow(window.get()); |
| 174 |
| 175 EXPECT_TRUE(shower()->GetTargetVisibility()); |
| 176 EXPECT_FALSE(delegate()->on_dismissed_called()); |
| 177 EXPECT_FALSE(delegate()->update_bounds_called()); |
| 178 } |
| 179 |
| 180 // Tests that UpdateBounds is called on the delegate when the root window |
| 181 // is resized. |
| 182 TEST_F(AppListShowerImplTest, RootWindowResize) { |
| 183 shower()->Show(container()); |
| 184 EXPECT_FALSE(delegate()->update_bounds_called()); |
| 185 gfx::Rect bounds = root_window()->bounds(); |
| 186 bounds.Inset(-10, 0); |
| 187 root_window()->SetBounds(bounds); |
| 188 EXPECT_TRUE(delegate()->update_bounds_called()); |
| 189 } |
| 190 |
| 191 // Tests that the app list is dismissed and the delegate is destroyed when the |
| 192 // app list's widget is destroyed. |
| 193 TEST_F(AppListShowerImplTest, WidgetDestroyed) { |
| 194 shower()->Show(container()); |
| 195 EXPECT_TRUE(shower()->GetTargetVisibility()); |
| 196 shower()->GetView()->GetWidget()->CloseNow(); |
| 197 EXPECT_FALSE(shower()->GetTargetVisibility()); |
| 198 test::AppListShowerImplTestApi shower_test_api(shower()); |
| 199 EXPECT_FALSE(shower_test_api.shower_delegate()); |
| 200 } |
| 201 |
| 202 } // namespace app_list |
OLD | NEW |