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

Side by Side Diff: ash/shelf/shelf_unittest.cc

Issue 2171813004: mash: Fold ShelfItemDelegateManager into ShelfModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: explicitly destroy ShelfItemDelegates Created 4 years, 5 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
« no previous file with comments | « ash/shelf/shelf_tooltip_manager_unittest.cc ('k') | ash/shelf/shelf_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/shelf/shelf.h" 5 #include "ash/shelf/shelf.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/common/shelf/shelf_item_delegate_manager.h"
10 #include "ash/common/shelf/shelf_model.h" 9 #include "ash/common/shelf/shelf_model.h"
11 #include "ash/shelf/shelf_button.h" 10 #include "ash/shelf/shelf_button.h"
12 #include "ash/shelf/shelf_view.h" 11 #include "ash/shelf/shelf_view.h"
13 #include "ash/shelf/shelf_widget.h" 12 #include "ash/shelf/shelf_widget.h"
14 #include "ash/shell.h"
15 #include "ash/test/ash_test_base.h" 13 #include "ash/test/ash_test_base.h"
16 #include "ash/test/shelf_test_api.h" 14 #include "ash/test/shelf_test_api.h"
17 #include "ash/test/shelf_view_test_api.h" 15 #include "ash/test/shelf_view_test_api.h"
18 #include "ash/test/test_shelf_item_delegate.h" 16 #include "ash/test/test_shelf_item_delegate.h"
19 #include "ash/wm/window_util.h" 17 #include "ash/wm/window_util.h"
20 #include "ui/aura/window_event_dispatcher.h" 18 #include "ui/aura/window_event_dispatcher.h"
21 #include "ui/views/view.h" 19 #include "ui/views/view.h"
22 #include "ui/views/widget/widget.h" 20 #include "ui/views/widget/widget.h"
23 21
24 #if defined(OS_WIN) 22 #if defined(OS_WIN)
25 #include "base/win/windows_version.h" 23 #include "base/win/windows_version.h"
26 #endif 24 #endif
27 25
28 using ash::ShelfView;
29 using ash::ShelfButton;
30
31 namespace ash { 26 namespace ash {
32 27
33 class ShelfTest : public ash::test::AshTestBase { 28 class ShelfTest : public test::AshTestBase {
34 public: 29 public:
35 ShelfTest() 30 ShelfTest() : shelf_(nullptr), shelf_view_(nullptr), shelf_model_(nullptr) {}
36 : shelf_(NULL),
37 shelf_view_(NULL),
38 shelf_model_(NULL),
39 item_delegate_manager_(NULL) {}
40 31
41 ~ShelfTest() override {} 32 ~ShelfTest() override {}
42 33
43 void SetUp() override { 34 void SetUp() override {
44 test::AshTestBase::SetUp(); 35 test::AshTestBase::SetUp();
45 36
46 shelf_ = Shelf::ForPrimaryDisplay(); 37 shelf_ = Shelf::ForPrimaryDisplay();
47 ASSERT_TRUE(shelf_); 38 ASSERT_TRUE(shelf_);
48 39
49 test::ShelfTestAPI test(shelf_); 40 test::ShelfTestAPI test(shelf_);
50 shelf_view_ = test.shelf_view(); 41 shelf_view_ = test.shelf_view();
51 shelf_model_ = shelf_view_->model(); 42 shelf_model_ = shelf_view_->model();
52 item_delegate_manager_ =
53 Shell::GetInstance()->shelf_item_delegate_manager();
54 43
55 test_.reset(new ash::test::ShelfViewTestAPI(shelf_view_)); 44 test_.reset(new test::ShelfViewTestAPI(shelf_view_));
56 } 45 }
57 46
58 void TearDown() override { test::AshTestBase::TearDown(); }
59
60 Shelf* shelf() { return shelf_; } 47 Shelf* shelf() { return shelf_; }
61 48
62 ShelfView* shelf_view() { return shelf_view_; } 49 ShelfView* shelf_view() { return shelf_view_; }
63 50
64 ShelfModel* shelf_model() { return shelf_model_; } 51 ShelfModel* shelf_model() { return shelf_model_; }
65 52
66 ShelfItemDelegateManager* item_manager() { return item_delegate_manager_; } 53 test::ShelfViewTestAPI* test_api() { return test_.get(); }
67
68 ash::test::ShelfViewTestAPI* test_api() { return test_.get(); }
69 54
70 private: 55 private:
71 Shelf* shelf_; 56 Shelf* shelf_;
72 ShelfView* shelf_view_; 57 ShelfView* shelf_view_;
73 ShelfModel* shelf_model_; 58 ShelfModel* shelf_model_;
74 ShelfItemDelegateManager* item_delegate_manager_;
75 std::unique_ptr<test::ShelfViewTestAPI> test_; 59 std::unique_ptr<test::ShelfViewTestAPI> test_;
76 60
77 DISALLOW_COPY_AND_ASSIGN(ShelfTest); 61 DISALLOW_COPY_AND_ASSIGN(ShelfTest);
78 }; 62 };
79 63
80 // Confirms that ShelfItem reflects the appropriated state. 64 // Confirms that ShelfItem reflects the appropriated state.
81 TEST_F(ShelfTest, StatusReflection) { 65 TEST_F(ShelfTest, StatusReflection) {
82 // Initially we have the app list. 66 // Initially we have the app list.
83 int button_count = test_api()->GetButtonCount(); 67 int button_count = test_api()->GetButtonCount();
84 68
85 // Add running platform app. 69 // Add running platform app.
86 ShelfItem item; 70 ShelfItem item;
87 item.type = TYPE_PLATFORM_APP; 71 item.type = TYPE_PLATFORM_APP;
88 item.status = STATUS_RUNNING; 72 item.status = STATUS_RUNNING;
89 int index = shelf_model()->Add(item); 73 int index = shelf_model()->Add(item);
90 ASSERT_EQ(++button_count, test_api()->GetButtonCount()); 74 ASSERT_EQ(++button_count, test_api()->GetButtonCount());
91 ShelfButton* button = test_api()->GetButton(index); 75 ShelfButton* button = test_api()->GetButton(index);
92 EXPECT_EQ(ShelfButton::STATE_RUNNING, button->state()); 76 EXPECT_EQ(ShelfButton::STATE_RUNNING, button->state());
93 77
94 // Remove it. 78 // Remove it.
95 shelf_model()->RemoveItemAt(index); 79 shelf_model()->RemoveItemAt(index);
96 ASSERT_EQ(--button_count, test_api()->GetButtonCount()); 80 ASSERT_EQ(--button_count, test_api()->GetButtonCount());
97 } 81 }
98 82
99 // Confirm that using the menu will clear the hover attribute. To avoid another 83 // Confirm that using the menu will clear the hover attribute. To avoid another
100 // browser test we check this here. 84 // browser test we check this here.
101 TEST_F(ShelfTest, checkHoverAfterMenu) { 85 TEST_F(ShelfTest, CheckHoverAfterMenu) {
102 // Initially we have the app list. 86 // Initially we have the app list.
103 int button_count = test_api()->GetButtonCount(); 87 int button_count = test_api()->GetButtonCount();
104 88
105 // Add running platform app. 89 // Add running platform app.
106 ShelfItem item; 90 ShelfItem item;
107 item.type = TYPE_PLATFORM_APP; 91 item.type = TYPE_PLATFORM_APP;
108 item.status = STATUS_RUNNING; 92 item.status = STATUS_RUNNING;
109 int index = shelf_model()->Add(item); 93 int index = shelf_model()->Add(item);
110 94
111 std::unique_ptr<ShelfItemDelegate> delegate( 95 std::unique_ptr<ShelfItemDelegate> delegate(
112 new test::TestShelfItemDelegate(NULL)); 96 new test::TestShelfItemDelegate(NULL));
113 item_manager()->SetShelfItemDelegate(shelf_model()->items()[index].id, 97 shelf_model()->SetShelfItemDelegate(shelf_model()->items()[index].id,
114 std::move(delegate)); 98 std::move(delegate));
115 99
116 ASSERT_EQ(++button_count, test_api()->GetButtonCount()); 100 ASSERT_EQ(++button_count, test_api()->GetButtonCount());
117 ShelfButton* button = test_api()->GetButton(index); 101 ShelfButton* button = test_api()->GetButton(index);
118 button->AddState(ShelfButton::STATE_HOVERED); 102 button->AddState(ShelfButton::STATE_HOVERED);
119 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); 103 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE);
120 EXPECT_FALSE(button->state() & ShelfButton::STATE_HOVERED); 104 EXPECT_FALSE(button->state() & ShelfButton::STATE_HOVERED);
121 105
122 // Remove it. 106 // Remove it.
123 shelf_model()->RemoveItemAt(index); 107 shelf_model()->RemoveItemAt(index);
124 } 108 }
(...skipping 19 matching lines...) Expand all
144 128
145 // Removes the first item in main shelf view. 129 // Removes the first item in main shelf view.
146 shelf_model()->RemoveItemAt(shelf_model()->ItemIndexByID(first_item_id)); 130 shelf_model()->RemoveItemAt(shelf_model()->ItemIndexByID(first_item_id));
147 131
148 // Waits for all transitions to finish and there should be no crash. 132 // Waits for all transitions to finish and there should be no crash.
149 test_api()->RunMessageLoopUntilAnimationsDone(); 133 test_api()->RunMessageLoopUntilAnimationsDone();
150 EXPECT_FALSE(shelf()->IsShowingOverflowBubble()); 134 EXPECT_FALSE(shelf()->IsShowingOverflowBubble());
151 } 135 }
152 136
153 } // namespace ash 137 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_tooltip_manager_unittest.cc ('k') | ash/shelf/shelf_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698