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

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

Issue 2357143004: mash: Support ShelfWindowWatcher via ShelfItem properties. (Closed)
Patch Set: Set Settings WmWindow title with a WmWindowObserver. 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
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);
James Cook 2016/09/28 20:41:03 This is fine, but just curious: does it need to ch
msw 2016/09/28 23:27:46 Nope! Just done to keep it a one-liner. Let me kno
James Cook 2016/09/29 02:49:46 This is fine.
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.
James Cook 2016/09/28 20:41:03 Thanks for fixing all the comments.
msw 2016/09/28 23:27:46 Acknowledged.
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);
James Cook 2016/09/28 20:41:03 How about adding a test that sets an icon ID but n
msw 2016/09/28 23:27:46 Done.
107 EXPECT_EQ(1, model_->item_count()); 106 EXPECT_EQ(1, model_->item_count());
108 } 107 }
109 108
110 TEST_F(ShelfWindowWatcherTest, ActivateWindow) { 109 TEST_F(ShelfWindowWatcherTest, ActivateWindow) {
111 // ShelfModel only have APP_LIST item. 110 // ShelfModel only have APP_LIST item.
112 EXPECT_EQ(1, model_->item_count()); 111 EXPECT_EQ(1, model_->item_count());
113 std::unique_ptr<views::Widget> widget1 = 112 std::unique_ptr<views::Widget> widget1 =
114 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 113 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
115 WmWindow* window1 = WmLookup::Get()->GetWindowForWidget(widget1.get()); 114 WmWindow* window1 = WmLookup::Get()->GetWindowForWidget(widget1.get());
116 std::unique_ptr<views::Widget> widget2 = 115 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()); 148 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
150 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get()); 149 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get());
151 150
152 // Create a ShelfItem for |window|. 151 // Create a ShelfItem for |window|.
153 ShelfID id = CreateShelfItem(window); 152 ShelfID id = CreateShelfItem(window);
154 EXPECT_EQ(2, model_->item_count()); 153 EXPECT_EQ(2, model_->item_count());
155 154
156 int index = model_->ItemIndexByID(id); 155 int index = model_->ItemIndexByID(id);
157 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status); 156 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status);
158 157
159 // Update ShelfItem for |window|. 158 // Update the ShelfItemType for |window|.
160 ShelfItemDetails details; 159 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. 160 // No new item is created after updating a launcher item.
165 EXPECT_EQ(2, model_->item_count()); 161 EXPECT_EQ(2, model_->item_count());
166 // index and id are not changed after updating a launcher item. 162 // index and id are not changed after updating a launcher item.
167 EXPECT_EQ(index, model_->ItemIndexByID(id)); 163 EXPECT_EQ(index, model_->ItemIndexByID(id));
168 EXPECT_EQ(id, model_->items()[index].id); 164 EXPECT_EQ(id, model_->items()[index].id);
169 } 165 }
170 166
171 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) { 167 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) {
172 // ShelfModel only has an APP_LIST item. 168 // ShelfModel only has an APP_LIST item.
173 EXPECT_EQ(1, model_->item_count()); 169 EXPECT_EQ(1, model_->item_count());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 ASSERT_TRUE(resizer.get()); 258 ASSERT_TRUE(resizer.get());
263 resizer->Drag(gfx::Point(50, 50), 0); 259 resizer->Drag(gfx::Point(50, 50), 0);
264 resizer->CompleteDrag(); 260 resizer->CompleteDrag();
265 261
266 // Index and id are not changed after dragging a |window|. 262 // Index and id are not changed after dragging a |window|.
267 EXPECT_EQ(index, model_->ItemIndexByID(id)); 263 EXPECT_EQ(index, model_->ItemIndexByID(id));
268 EXPECT_EQ(id, model_->items()[index].id); 264 EXPECT_EQ(id, model_->items()[index].id);
269 } 265 }
270 266
271 } // namespace ash 267 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698