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

Side by Side Diff: ash/common/shelf/shelf_window_watcher_unittest.cc

Issue 2357143004: mash: Support ShelfWindowWatcher via ShelfItem properties. (Closed)
Patch Set: Address comments. Created 4 years, 2 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/common/shelf/shelf_window_watcher_item_delegate.cc ('k') | ash/common/wm_window.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/common/shelf/shelf_window_watcher.h" 5 #include "ash/common/shelf/shelf_window_watcher.h"
6 6
7 #include "ash/common/shelf/shelf_item_types.h" 7 #include "ash/common/shelf/shelf_item_types.h"
8 #include "ash/common/shelf/shelf_model.h" 8 #include "ash/common/shelf/shelf_model.h"
9 #include "ash/common/shell_window_ids.h" 9 #include "ash/common/shell_window_ids.h"
10 #include "ash/common/wm/window_resizer.h" 10 #include "ash/common/wm/window_resizer.h"
11 #include "ash/common/wm/window_state.h" 11 #include "ash/common/wm/window_state.h"
12 #include "ash/common/wm_lookup.h" 12 #include "ash/common/wm_lookup.h"
13 #include "ash/common/wm_shell.h" 13 #include "ash/common/wm_shell.h"
14 #include "ash/common/wm_window.h" 14 #include "ash/common/wm_window.h"
15 #include "ash/common/wm_window_property.h"
15 #include "ash/test/ash_test_base.h" 16 #include "ash/test/ash_test_base.h"
16 #include "ui/base/hit_test.h" 17 #include "ui/base/hit_test.h"
17 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
18 19
19 namespace ash { 20 namespace ash {
20 21
21 class ShelfWindowWatcherTest : public test::AshTestBase { 22 class ShelfWindowWatcherTest : public test::AshTestBase {
22 public: 23 public:
23 ShelfWindowWatcherTest() : model_(nullptr) {} 24 ShelfWindowWatcherTest() : model_(nullptr) {}
24 ~ShelfWindowWatcherTest() override {} 25 ~ShelfWindowWatcherTest() override {}
25 26
26 void SetUp() override { 27 void SetUp() override {
27 test::AshTestBase::SetUp(); 28 test::AshTestBase::SetUp();
28 model_ = WmShell::Get()->shelf_model(); 29 model_ = WmShell::Get()->shelf_model();
29 } 30 }
30 31
31 void TearDown() override { 32 void TearDown() override {
32 model_ = nullptr; 33 model_ = nullptr;
33 test::AshTestBase::TearDown(); 34 test::AshTestBase::TearDown();
34 } 35 }
35 36
36 ShelfID CreateShelfItem(WmWindow* window) { 37 ShelfID CreateShelfItem(WmWindow* window) {
37 ShelfID id = model_->next_id(); 38 ShelfID id = model_->next_id();
38 ShelfItemDetails item_details; 39 window->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_DIALOG);
39 item_details.type = TYPE_PLATFORM_APP;
40 window->SetShelfItemDetails(item_details);
41 return id; 40 return id;
42 } 41 }
43 42
44 protected: 43 protected:
45 ShelfModel* model_; 44 ShelfModel* model_;
46 45
47 private: 46 private:
48 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest); 47 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest);
49 }; 48 };
50 49
51 // Ensure shelf items are added and removed as windows are opened and closed. 50 // Ensure shelf items are added and removed as windows are opened and closed.
52 TEST_F(ShelfWindowWatcherTest, OpenAndClose) { 51 TEST_F(ShelfWindowWatcherTest, OpenAndClose) {
53 // ShelfModel only has an APP_LIST item. 52 // ShelfModel only has an APP_LIST item.
54 EXPECT_EQ(1, model_->item_count()); 53 EXPECT_EQ(1, model_->item_count());
55 54
56 // Adding windows with ShelfItemDetails properties adds shelf items. 55 // Adding windows with valid ShelfItemType properties adds shelf items.
57 std::unique_ptr<views::Widget> widget1 = 56 std::unique_ptr<views::Widget> widget1 =
58 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 57 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
59 CreateShelfItem(WmLookup::Get()->GetWindowForWidget(widget1.get())); 58 CreateShelfItem(WmLookup::Get()->GetWindowForWidget(widget1.get()));
60 EXPECT_EQ(2, model_->item_count()); 59 EXPECT_EQ(2, model_->item_count());
61 std::unique_ptr<views::Widget> widget2 = 60 std::unique_ptr<views::Widget> widget2 =
62 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 61 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
63 CreateShelfItem(WmLookup::Get()->GetWindowForWidget(widget2.get())); 62 CreateShelfItem(WmLookup::Get()->GetWindowForWidget(widget2.get()));
64 EXPECT_EQ(3, model_->item_count()); 63 EXPECT_EQ(3, model_->item_count());
65 64
66 // Each ShelfItem is removed when the associated window is destroyed. 65 // Each ShelfItem is removed when the associated window is destroyed.
67 widget1.reset(); 66 widget1.reset();
68 EXPECT_EQ(2, model_->item_count()); 67 EXPECT_EQ(2, model_->item_count());
69 widget2.reset(); 68 widget2.reset();
70 EXPECT_EQ(1, model_->item_count()); 69 EXPECT_EQ(1, model_->item_count());
71 } 70 }
72 71
73 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveShelfItemDetails) { 72 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveShelfItemProperties) {
74 // ShelfModel only has an APP_LIST item. 73 // ShelfModel only has an APP_LIST item.
75 EXPECT_EQ(1, model_->item_count()); 74 EXPECT_EQ(1, model_->item_count());
76 75
77 // Creating windows without ShelfItemDetails does not add items. 76 // Creating windows without a valid ShelfItemType does not add items.
78 std::unique_ptr<views::Widget> widget1 = 77 std::unique_ptr<views::Widget> widget1 =
79 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 78 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
80 WmWindow* window1 = WmLookup::Get()->GetWindowForWidget(widget1.get()); 79 WmWindow* window1 = WmLookup::Get()->GetWindowForWidget(widget1.get());
81 std::unique_ptr<views::Widget> widget2 = 80 std::unique_ptr<views::Widget> widget2 =
82 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 81 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
83 WmWindow* window2 = WmLookup::Get()->GetWindowForWidget(widget2.get()); 82 WmWindow* window2 = WmLookup::Get()->GetWindowForWidget(widget2.get());
84 EXPECT_EQ(1, model_->item_count()); 83 EXPECT_EQ(1, model_->item_count());
85 84
86 // Create a ShelfItem for the first window. 85 // Create a ShelfItem for the first window.
87 ShelfID id_w1 = CreateShelfItem(window1); 86 ShelfID id_w1 = CreateShelfItem(window1);
88 EXPECT_EQ(2, model_->item_count()); 87 EXPECT_EQ(2, model_->item_count());
89 88
90 int index_w1 = model_->ItemIndexByID(id_w1); 89 int index_w1 = model_->ItemIndexByID(id_w1);
91 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); 90 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
92 91
93 // Create a ShelfItem for the second window. 92 // Create a ShelfItem for the second window.
94 ShelfID id_w2 = CreateShelfItem(window2); 93 ShelfID id_w2 = CreateShelfItem(window2);
95 EXPECT_EQ(3, model_->item_count()); 94 EXPECT_EQ(3, model_->item_count());
96 95
97 int index_w2 = model_->ItemIndexByID(id_w2); 96 int index_w2 = model_->ItemIndexByID(id_w2);
98 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status); 97 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status);
99 98
100 // ShelfItem is removed when its window property is cleared. 99 // ShelfItem is removed when the item type window property is cleared.
101 window1->ClearShelfItemDetails(); 100 window1->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_UNDEFINED);
102 EXPECT_EQ(2, model_->item_count()); 101 EXPECT_EQ(2, model_->item_count());
103 window2->ClearShelfItemDetails(); 102 window2->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_UNDEFINED);
104 EXPECT_EQ(1, model_->item_count()); 103 EXPECT_EQ(1, model_->item_count());
105 // Clearing twice doesn't do anything. 104 // Clearing twice doesn't do anything.
106 window2->ClearShelfItemDetails(); 105 window2->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_UNDEFINED);
106 EXPECT_EQ(1, model_->item_count());
107
108 // Setting an icon id (without a valid item type) does not add a shelf item.
109 window2->SetIntProperty(WmWindowProperty::SHELF_ICON_RESOURCE_ID, 1234);
107 EXPECT_EQ(1, model_->item_count()); 110 EXPECT_EQ(1, model_->item_count());
108 } 111 }
109 112
110 TEST_F(ShelfWindowWatcherTest, ActivateWindow) { 113 TEST_F(ShelfWindowWatcherTest, ActivateWindow) {
111 // ShelfModel only have APP_LIST item. 114 // ShelfModel only have APP_LIST item.
112 EXPECT_EQ(1, model_->item_count()); 115 EXPECT_EQ(1, model_->item_count());
113 std::unique_ptr<views::Widget> widget1 = 116 std::unique_ptr<views::Widget> widget1 =
114 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 117 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
115 WmWindow* window1 = WmLookup::Get()->GetWindowForWidget(widget1.get()); 118 WmWindow* window1 = WmLookup::Get()->GetWindowForWidget(widget1.get());
116 std::unique_ptr<views::Widget> widget2 = 119 std::unique_ptr<views::Widget> widget2 =
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 152 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
150 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get()); 153 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get());
151 154
152 // Create a ShelfItem for |window|. 155 // Create a ShelfItem for |window|.
153 ShelfID id = CreateShelfItem(window); 156 ShelfID id = CreateShelfItem(window);
154 EXPECT_EQ(2, model_->item_count()); 157 EXPECT_EQ(2, model_->item_count());
155 158
156 int index = model_->ItemIndexByID(id); 159 int index = model_->ItemIndexByID(id);
157 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status); 160 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status);
158 161
159 // Update ShelfItem for |window|. 162 // Update the ShelfItemType for |window|.
160 ShelfItemDetails details; 163 window->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_PLATFORM_APP);
161 details.type = TYPE_PLATFORM_APP;
162
163 window->SetShelfItemDetails(details);
164 // No new item is created after updating a launcher item. 164 // No new item is created after updating a launcher item.
165 EXPECT_EQ(2, model_->item_count()); 165 EXPECT_EQ(2, model_->item_count());
166 // index and id are not changed after updating a launcher item. 166 // index and id are not changed after updating a launcher item.
167 EXPECT_EQ(index, model_->ItemIndexByID(id)); 167 EXPECT_EQ(index, model_->ItemIndexByID(id));
168 EXPECT_EQ(id, model_->items()[index].id); 168 EXPECT_EQ(id, model_->items()[index].id);
169 } 169 }
170 170
171 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) { 171 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) {
172 // ShelfModel only has an APP_LIST item. 172 // ShelfModel only has an APP_LIST item.
173 EXPECT_EQ(1, model_->item_count()); 173 EXPECT_EQ(1, model_->item_count());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 ASSERT_TRUE(resizer.get()); 262 ASSERT_TRUE(resizer.get());
263 resizer->Drag(gfx::Point(50, 50), 0); 263 resizer->Drag(gfx::Point(50, 50), 0);
264 resizer->CompleteDrag(); 264 resizer->CompleteDrag();
265 265
266 // Index and id are not changed after dragging a |window|. 266 // Index and id are not changed after dragging a |window|.
267 EXPECT_EQ(index, model_->ItemIndexByID(id)); 267 EXPECT_EQ(index, model_->ItemIndexByID(id));
268 EXPECT_EQ(id, model_->items()[index].id); 268 EXPECT_EQ(id, model_->items()[index].id);
269 } 269 }
270 270
271 } // namespace ash 271 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/shelf_window_watcher_item_delegate.cc ('k') | ash/common/wm_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698