| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/common/shelf/shelf_view.h" | 5 #include "ash/common/shelf/shelf_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "ash/common/shelf/app_list_button.h" | 12 #include "ash/common/shelf/app_list_button.h" |
| 13 #include "ash/common/shelf/overflow_bubble.h" | 13 #include "ash/common/shelf/overflow_bubble.h" |
| 14 #include "ash/common/shelf/overflow_bubble_view.h" | 14 #include "ash/common/shelf/overflow_bubble_view.h" |
| 15 #include "ash/common/shelf/shelf_button.h" | 15 #include "ash/common/shelf/shelf_button.h" |
| 16 #include "ash/common/shelf/shelf_constants.h" | 16 #include "ash/common/shelf/shelf_constants.h" |
| 17 #include "ash/common/shelf/shelf_icon_observer.h" | |
| 18 #include "ash/common/shelf/shelf_menu_model.h" | 17 #include "ash/common/shelf/shelf_menu_model.h" |
| 19 #include "ash/common/shelf/shelf_model.h" | 18 #include "ash/common/shelf/shelf_model.h" |
| 20 #include "ash/common/shelf/shelf_tooltip_manager.h" | 19 #include "ash/common/shelf/shelf_tooltip_manager.h" |
| 21 #include "ash/common/shelf/wm_shelf.h" | 20 #include "ash/common/shelf/wm_shelf.h" |
| 21 #include "ash/common/shelf/wm_shelf_observer.h" |
| 22 #include "ash/common/shell_window_ids.h" | 22 #include "ash/common/shell_window_ids.h" |
| 23 #include "ash/common/system/web_notification/web_notification_tray.h" | 23 #include "ash/common/system/web_notification/web_notification_tray.h" |
| 24 #include "ash/common/test/material_design_controller_test_api.h" | 24 #include "ash/common/test/material_design_controller_test_api.h" |
| 25 #include "ash/common/wm_root_window_controller.h" |
| 25 #include "ash/common/wm_shell.h" | 26 #include "ash/common/wm_shell.h" |
| 26 #include "ash/common/wm_window.h" | 27 #include "ash/common/wm_window.h" |
| 27 #include "ash/shelf/shelf_widget.h" | 28 #include "ash/shelf/shelf_widget.h" |
| 28 #include "ash/shell.h" | 29 #include "ash/shell.h" |
| 29 #include "ash/test/ash_test_base.h" | 30 #include "ash/test/ash_test_base.h" |
| 30 #include "ash/test/ash_test_helper.h" | 31 #include "ash/test/ash_test_helper.h" |
| 31 #include "ash/test/overflow_bubble_view_test_api.h" | 32 #include "ash/test/overflow_bubble_view_test_api.h" |
| 32 #include "ash/test/shelf_test_api.h" | 33 #include "ash/test/shelf_test_api.h" |
| 33 #include "ash/test/shelf_view_test_api.h" | 34 #include "ash/test/shelf_view_test_api.h" |
| 34 #include "ash/test/test_shelf_delegate.h" | 35 #include "ash/test/test_shelf_delegate.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 64 #include "ui/views/widget/widget_delegate.h" | 65 #include "ui/views/widget/widget_delegate.h" |
| 65 #include "ui/wm/core/coordinate_conversion.h" | 66 #include "ui/wm/core/coordinate_conversion.h" |
| 66 | 67 |
| 67 using testing::ElementsAre; | 68 using testing::ElementsAre; |
| 68 using testing::IsEmpty; | 69 using testing::IsEmpty; |
| 69 | 70 |
| 70 namespace ash { | 71 namespace ash { |
| 71 namespace test { | 72 namespace test { |
| 72 | 73 |
| 73 //////////////////////////////////////////////////////////////////////////////// | 74 //////////////////////////////////////////////////////////////////////////////// |
| 74 // ShelfIconObserver tests. | 75 // WmShelfObserver::OnShelfIconPositionsChanged tests. |
| 75 | 76 |
| 76 class TestShelfIconObserver : public ShelfIconObserver { | 77 class TestWmShelfObserver : public WmShelfObserver { |
| 77 public: | 78 public: |
| 78 explicit TestShelfIconObserver(Shelf* shelf) | 79 explicit TestWmShelfObserver(WmShelf* shelf) : shelf_(shelf) { |
| 79 : shelf_(shelf), change_notified_(false) { | 80 shelf_->AddObserver(this); |
| 80 if (shelf_) | |
| 81 shelf_->AddIconObserver(this); | |
| 82 } | 81 } |
| 83 | 82 |
| 84 ~TestShelfIconObserver() override { | 83 ~TestWmShelfObserver() override { shelf_->RemoveObserver(this); } |
| 85 if (shelf_) | 84 |
| 86 shelf_->RemoveIconObserver(this); | 85 // WmShelfObserver implementation. |
| 86 void OnShelfIconPositionsChanged() override { |
| 87 icon_positions_changed_ = true; |
| 87 } | 88 } |
| 88 | 89 |
| 89 // ShelfIconObserver implementation. | 90 bool icon_positions_changed() const { return icon_positions_changed_; } |
| 90 void OnShelfIconPositionsChanged() override { change_notified_ = true; } | 91 void Reset() { icon_positions_changed_ = false; } |
| 91 | |
| 92 int change_notified() const { return change_notified_; } | |
| 93 void Reset() { change_notified_ = false; } | |
| 94 | 92 |
| 95 private: | 93 private: |
| 96 Shelf* shelf_; | 94 WmShelf* shelf_; |
| 97 bool change_notified_; | 95 bool icon_positions_changed_ = false; |
| 98 | 96 |
| 99 DISALLOW_COPY_AND_ASSIGN(TestShelfIconObserver); | 97 DISALLOW_COPY_AND_ASSIGN(TestWmShelfObserver); |
| 100 }; | 98 }; |
| 101 | 99 |
| 102 class ShelfViewIconObserverTest : public AshTestBase { | 100 class WmShelfObserverIconTest : public AshTestBase { |
| 103 public: | 101 public: |
| 104 ShelfViewIconObserverTest() {} | 102 WmShelfObserverIconTest() {} |
| 105 ~ShelfViewIconObserverTest() override {} | 103 ~WmShelfObserverIconTest() override {} |
| 106 | 104 |
| 107 void SetUp() override { | 105 void SetUp() override { |
| 108 AshTestBase::SetUp(); | 106 AshTestBase::SetUp(); |
| 109 Shelf* shelf = Shelf::ForPrimaryDisplay(); | 107 observer_.reset(new TestWmShelfObserver(GetPrimaryShelf())); |
| 110 observer_.reset(new TestShelfIconObserver(shelf)); | |
| 111 | |
| 112 shelf_view_test_.reset( | 108 shelf_view_test_.reset( |
| 113 new ShelfViewTestAPI(ShelfTestAPI(shelf).shelf_view())); | 109 new ShelfViewTestAPI(GetPrimaryShelf()->GetShelfViewForTesting())); |
| 114 shelf_view_test_->SetAnimationDuration(1); | 110 shelf_view_test_->SetAnimationDuration(1); |
| 115 } | 111 } |
| 116 | 112 |
| 117 void TearDown() override { | 113 void TearDown() override { |
| 118 observer_.reset(); | 114 observer_.reset(); |
| 119 AshTestBase::TearDown(); | 115 AshTestBase::TearDown(); |
| 120 } | 116 } |
| 121 | 117 |
| 122 TestShelfIconObserver* observer() { return observer_.get(); } | 118 TestWmShelfObserver* observer() { return observer_.get(); } |
| 123 | 119 |
| 124 ShelfViewTestAPI* shelf_view_test() { return shelf_view_test_.get(); } | 120 ShelfViewTestAPI* shelf_view_test() { return shelf_view_test_.get(); } |
| 125 | 121 |
| 126 Shelf* ShelfForSecondaryDisplay() { | |
| 127 return Shelf::ForWindow(WmShell::Get()->GetAllRootWindows()[1]); | |
| 128 } | |
| 129 | |
| 130 private: | 122 private: |
| 131 std::unique_ptr<TestShelfIconObserver> observer_; | 123 std::unique_ptr<TestWmShelfObserver> observer_; |
| 132 std::unique_ptr<ShelfViewTestAPI> shelf_view_test_; | 124 std::unique_ptr<ShelfViewTestAPI> shelf_view_test_; |
| 133 | 125 |
| 134 DISALLOW_COPY_AND_ASSIGN(ShelfViewIconObserverTest); | 126 DISALLOW_COPY_AND_ASSIGN(WmShelfObserverIconTest); |
| 135 }; | 127 }; |
| 136 | 128 |
| 137 // TestShelfItemDelegate which tracks whether it gets selected. | 129 // TestShelfItemDelegate which tracks whether it gets selected. |
| 138 class ShelfItemSelectionTracker : public TestShelfItemDelegate { | 130 class ShelfItemSelectionTracker : public TestShelfItemDelegate { |
| 139 public: | 131 public: |
| 140 ShelfItemSelectionTracker() | 132 ShelfItemSelectionTracker() |
| 141 : TestShelfItemDelegate(NULL), | 133 : TestShelfItemDelegate(NULL), |
| 142 selected_(false), | 134 selected_(false), |
| 143 item_selected_action_(kNoAction) {} | 135 item_selected_action_(kNoAction) {} |
| 144 | 136 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 164 | 156 |
| 165 private: | 157 private: |
| 166 bool selected_; | 158 bool selected_; |
| 167 | 159 |
| 168 // The action returned from ItemSelected(const ui::Event&). | 160 // The action returned from ItemSelected(const ui::Event&). |
| 169 ShelfItemDelegate::PerformedAction item_selected_action_; | 161 ShelfItemDelegate::PerformedAction item_selected_action_; |
| 170 | 162 |
| 171 DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker); | 163 DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker); |
| 172 }; | 164 }; |
| 173 | 165 |
| 174 TEST_F(ShelfViewIconObserverTest, AddRemove) { | 166 TEST_F(WmShelfObserverIconTest, AddRemove) { |
| 175 TestShelfDelegate* shelf_delegate = TestShelfDelegate::instance(); | 167 TestShelfDelegate* shelf_delegate = TestShelfDelegate::instance(); |
| 176 ASSERT_TRUE(shelf_delegate); | 168 ASSERT_TRUE(shelf_delegate); |
| 177 | 169 |
| 178 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 170 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 179 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 171 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 180 params.bounds = gfx::Rect(0, 0, 200, 200); | 172 params.bounds = gfx::Rect(0, 0, 200, 200); |
| 181 params.context = CurrentContext(); | 173 params.context = CurrentContext(); |
| 182 | 174 |
| 183 std::unique_ptr<views::Widget> widget(new views::Widget()); | 175 std::unique_ptr<views::Widget> widget(new views::Widget()); |
| 184 widget->Init(params); | 176 widget->Init(params); |
| 185 shelf_delegate->AddShelfItem(widget->GetNativeWindow()); | 177 shelf_delegate->AddShelfItem(widget->GetNativeWindow()); |
| 186 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 178 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 187 EXPECT_TRUE(observer()->change_notified()); | 179 EXPECT_TRUE(observer()->icon_positions_changed()); |
| 188 observer()->Reset(); | 180 observer()->Reset(); |
| 189 | 181 |
| 190 widget->Show(); | 182 widget->Show(); |
| 191 widget->GetNativeWindow()->parent()->RemoveChild(widget->GetNativeWindow()); | 183 widget->GetNativeWindow()->parent()->RemoveChild(widget->GetNativeWindow()); |
| 192 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 184 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 193 EXPECT_TRUE(observer()->change_notified()); | 185 EXPECT_TRUE(observer()->icon_positions_changed()); |
| 194 observer()->Reset(); | 186 observer()->Reset(); |
| 195 } | 187 } |
| 196 | 188 |
| 197 // Make sure creating/deleting an window on one displays notifies a | 189 // Make sure creating/deleting an window on one displays notifies a |
| 198 // shelf on external display as well as one on primary. | 190 // shelf on external display as well as one on primary. |
| 199 TEST_F(ShelfViewIconObserverTest, AddRemoveWithMultipleDisplays) { | 191 TEST_F(WmShelfObserverIconTest, AddRemoveWithMultipleDisplays) { |
| 200 if (!SupportsMultipleDisplays()) | 192 if (!SupportsMultipleDisplays()) |
| 201 return; | 193 return; |
| 202 | 194 |
| 203 UpdateDisplay("400x400,400x400"); | 195 UpdateDisplay("400x400,400x400"); |
| 204 TestShelfIconObserver second_observer(ShelfForSecondaryDisplay()); | 196 WmWindow* second_root = WmShell::Get()->GetAllRootWindows()[1]; |
| 197 WmShelf* second_shelf = second_root->GetRootWindowController()->GetShelf(); |
| 198 TestWmShelfObserver second_observer(second_shelf); |
| 205 | 199 |
| 206 TestShelfDelegate* shelf_delegate = TestShelfDelegate::instance(); | 200 TestShelfDelegate* shelf_delegate = TestShelfDelegate::instance(); |
| 207 ASSERT_TRUE(shelf_delegate); | 201 ASSERT_TRUE(shelf_delegate); |
| 208 | 202 |
| 209 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 203 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 210 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 204 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 211 params.bounds = gfx::Rect(0, 0, 200, 200); | 205 params.bounds = gfx::Rect(0, 0, 200, 200); |
| 212 params.context = CurrentContext(); | 206 params.context = CurrentContext(); |
| 213 | 207 |
| 214 std::unique_ptr<views::Widget> widget(new views::Widget()); | 208 std::unique_ptr<views::Widget> widget(new views::Widget()); |
| 215 widget->Init(params); | 209 widget->Init(params); |
| 216 shelf_delegate->AddShelfItem(widget->GetNativeWindow()); | 210 shelf_delegate->AddShelfItem(widget->GetNativeWindow()); |
| 217 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 211 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 218 EXPECT_TRUE(observer()->change_notified()); | 212 EXPECT_TRUE(observer()->icon_positions_changed()); |
| 219 EXPECT_TRUE(second_observer.change_notified()); | 213 EXPECT_TRUE(second_observer.icon_positions_changed()); |
| 220 observer()->Reset(); | 214 observer()->Reset(); |
| 221 second_observer.Reset(); | 215 second_observer.Reset(); |
| 222 | 216 |
| 223 widget->GetNativeWindow()->parent()->RemoveChild(widget->GetNativeWindow()); | 217 widget->GetNativeWindow()->parent()->RemoveChild(widget->GetNativeWindow()); |
| 224 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 218 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 225 EXPECT_TRUE(observer()->change_notified()); | 219 EXPECT_TRUE(observer()->icon_positions_changed()); |
| 226 EXPECT_TRUE(second_observer.change_notified()); | 220 EXPECT_TRUE(second_observer.icon_positions_changed()); |
| 227 | 221 |
| 228 observer()->Reset(); | 222 observer()->Reset(); |
| 229 second_observer.Reset(); | 223 second_observer.Reset(); |
| 230 } | 224 } |
| 231 | 225 |
| 232 TEST_F(ShelfViewIconObserverTest, BoundsChanged) { | 226 TEST_F(WmShelfObserverIconTest, BoundsChanged) { |
| 233 views::Widget* widget = | 227 views::Widget* widget = |
| 234 GetPrimaryShelf()->GetShelfViewForTesting()->GetWidget(); | 228 GetPrimaryShelf()->GetShelfViewForTesting()->GetWidget(); |
| 235 gfx::Rect shelf_bounds = widget->GetWindowBoundsInScreen(); | 229 gfx::Rect shelf_bounds = widget->GetWindowBoundsInScreen(); |
| 236 shelf_bounds.set_width(shelf_bounds.width() / 2); | 230 shelf_bounds.set_width(shelf_bounds.width() / 2); |
| 237 ASSERT_GT(shelf_bounds.width(), 0); | 231 ASSERT_GT(shelf_bounds.width(), 0); |
| 238 widget->SetBounds(shelf_bounds); | 232 widget->SetBounds(shelf_bounds); |
| 239 // No animation happens for ShelfView bounds change. | 233 // No animation happens for ShelfView bounds change. |
| 240 EXPECT_TRUE(observer()->change_notified()); | 234 EXPECT_TRUE(observer()->icon_positions_changed()); |
| 241 observer()->Reset(); | 235 observer()->Reset(); |
| 242 } | 236 } |
| 243 | 237 |
| 244 //////////////////////////////////////////////////////////////////////////////// | 238 //////////////////////////////////////////////////////////////////////////////// |
| 245 // ShelfView tests. | 239 // ShelfView tests. |
| 246 | 240 |
| 247 // A ShelfDelegate test double that will always convert between ShelfIDs and app | 241 // A ShelfDelegate test double that will always convert between ShelfIDs and app |
| 248 // ids. This does not support pinning and unpinning operations and the return | 242 // ids. This does not support pinning and unpinning operations and the return |
| 249 // value of IsAppPinned(...) is configurable. | 243 // value of IsAppPinned(...) is configurable. |
| 250 class TestShelfDelegateForShelfView : public ShelfDelegate { | 244 class TestShelfDelegateForShelfView : public ShelfDelegate { |
| (...skipping 2323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2574 test_api_->CloseMenu(); | 2568 test_api_->CloseMenu(); |
| 2575 EXPECT_EQ(views::InkDropState::HIDDEN, | 2569 EXPECT_EQ(views::InkDropState::HIDDEN, |
| 2576 browser_button_ink_drop_->GetTargetInkDropState()); | 2570 browser_button_ink_drop_->GetTargetInkDropState()); |
| 2577 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(), | 2571 EXPECT_THAT(browser_button_ink_drop_->GetAndResetRequestedStates(), |
| 2578 ElementsAre(views::InkDropState::ACTIVATED, | 2572 ElementsAre(views::InkDropState::ACTIVATED, |
| 2579 views::InkDropState::DEACTIVATED)); | 2573 views::InkDropState::DEACTIVATED)); |
| 2580 } | 2574 } |
| 2581 | 2575 |
| 2582 } // namespace test | 2576 } // namespace test |
| 2583 } // namespace ash | 2577 } // namespace ash |
| OLD | NEW |