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

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

Issue 2878133002: mash: Serialize ShelfIDs for property conversion and transport. (Closed)
Patch Set: Remove |user_windows_with_items_| entries in workaround; disable a test in mash. Created 3 years, 7 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/shelf/shelf_window_watcher.h" 5 #include "ash/shelf/shelf_window_watcher.h"
6 6
7 #include "ash/public/cpp/config.h" 7 #include "ash/public/cpp/config.h"
8 #include "ash/public/cpp/shelf_item.h" 8 #include "ash/public/cpp/shelf_item.h"
9 #include "ash/public/cpp/shell_window_ids.h" 9 #include "ash/public/cpp/shell_window_ids.h"
10 #include "ash/public/cpp/window_properties.h" 10 #include "ash/public/cpp/window_properties.h"
11 #include "ash/root_window_controller.h" 11 #include "ash/root_window_controller.h"
12 #include "ash/session/session_controller.h" 12 #include "ash/session/session_controller.h"
13 #include "ash/shelf/shelf_model.h" 13 #include "ash/shelf/shelf_model.h"
14 #include "ash/shell.h" 14 #include "ash/shell.h"
15 #include "ash/shell_port.h" 15 #include "ash/shell_port.h"
16 #include "ash/test/ash_test_base.h" 16 #include "ash/test/ash_test_base.h"
17 #include "ash/wm/window_resizer.h" 17 #include "ash/wm/window_resizer.h"
18 #include "ash/wm/window_state.h" 18 #include "ash/wm/window_state.h"
19 #include "ash/wm/window_state_aura.h"
19 #include "ash/wm_window.h" 20 #include "ash/wm_window.h"
20 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
21 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
22 #include "ui/base/hit_test.h" 23 #include "ui/base/hit_test.h"
23 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
24 25
25 namespace ash { 26 namespace ash {
26 27
27 class ShelfWindowWatcherTest : public test::AshTestBase { 28 class ShelfWindowWatcherTest : public test::AshTestBase {
28 public: 29 public:
29 ShelfWindowWatcherTest() : model_(nullptr) {} 30 ShelfWindowWatcherTest() : model_(nullptr) {}
30 ~ShelfWindowWatcherTest() override {} 31 ~ShelfWindowWatcherTest() override {}
31 32
32 void SetUp() override { 33 void SetUp() override {
33 test::AshTestBase::SetUp(); 34 test::AshTestBase::SetUp();
34 model_ = Shell::Get()->shelf_model(); 35 model_ = Shell::Get()->shelf_model();
35 } 36 }
36 37
37 void TearDown() override { 38 void TearDown() override {
38 model_ = nullptr; 39 model_ = nullptr;
39 test::AshTestBase::TearDown(); 40 test::AshTestBase::TearDown();
40 } 41 }
41 42
42 static ShelfID CreateShelfItem(WmWindow* window) { 43 static ShelfID CreateShelfItem(aura::Window* window) {
James Cook 2017/05/15 16:37:23 Hooray for less WmWindow!
msw 2017/05/15 19:21:32 Acknowledged.
43 static int id = 0; 44 static int id = 0;
44 ShelfID shelf_id(base::IntToString(id++)); 45 ash::ShelfID shelf_id(base::IntToString(id++));
James Cook 2017/05/15 16:37:23 Is ash:: needed?
msw 2017/05/15 19:21:32 Done.
45 window->aura_window()->SetProperty(kShelfIDKey, new ShelfID(shelf_id)); 46 window->SetProperty(kShelfIDKey, new std::string(shelf_id.Serialize()));
46 window->aura_window()->SetProperty(kShelfItemTypeKey, 47 window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_DIALOG));
47 static_cast<int32_t>(TYPE_DIALOG));
48 return shelf_id; 48 return shelf_id;
49 } 49 }
50 50
51 protected: 51 protected:
52 ShelfModel* model_; 52 ShelfModel* model_;
53 53
54 private: 54 private:
55 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest); 55 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest);
56 }; 56 };
57 57
58 // Ensure shelf items are added and removed as windows are opened and closed. 58 // Ensure shelf items are added and removed as windows are opened and closed.
59 TEST_F(ShelfWindowWatcherTest, OpenAndClose) { 59 TEST_F(ShelfWindowWatcherTest, OpenAndClose) {
60 // ShelfModel only has an APP_LIST item. 60 // ShelfModel only has an APP_LIST item.
61 EXPECT_EQ(1, model_->item_count()); 61 EXPECT_EQ(1, model_->item_count());
62 62
63 // Adding windows with valid ShelfItemType properties adds shelf items. 63 // Adding windows with valid ShelfItemType properties adds shelf items.
64 std::unique_ptr<views::Widget> widget1 = 64 std::unique_ptr<views::Widget> widget1 =
65 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 65 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
66 CreateShelfItem(WmWindow::Get(widget1->GetNativeWindow())); 66 CreateShelfItem(widget1->GetNativeWindow());
67 EXPECT_EQ(2, model_->item_count()); 67 EXPECT_EQ(2, model_->item_count());
68 std::unique_ptr<views::Widget> widget2 = 68 std::unique_ptr<views::Widget> widget2 =
69 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 69 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
70 CreateShelfItem(WmWindow::Get(widget2->GetNativeWindow())); 70 CreateShelfItem(widget2->GetNativeWindow());
71 EXPECT_EQ(3, model_->item_count()); 71 EXPECT_EQ(3, model_->item_count());
72 72
73 // Each ShelfItem is removed when the associated window is destroyed. 73 // Each ShelfItem is removed when the associated window is destroyed.
74 widget1.reset(); 74 widget1.reset();
75 EXPECT_EQ(2, model_->item_count()); 75 EXPECT_EQ(2, model_->item_count());
76 widget2.reset(); 76 widget2.reset();
77 EXPECT_EQ(1, model_->item_count()); 77 EXPECT_EQ(1, model_->item_count());
78 } 78 }
79 79
80 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveShelfItemProperties) { 80 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveShelfItemProperties) {
81 // TODO: investigate failure in mash. http://crbug.com/695562. 81 // TODO: investigate failure in mash. http://crbug.com/695562.
82 if (Shell::GetAshConfig() == Config::MASH) 82 if (Shell::GetAshConfig() == Config::MASH)
83 return; 83 return;
84 84
85 // ShelfModel only has an APP_LIST item. 85 // ShelfModel only has an APP_LIST item.
86 EXPECT_EQ(1, model_->item_count()); 86 EXPECT_EQ(1, model_->item_count());
87 87
88 // Creating windows without a valid ShelfItemType does not add items. 88 // Creating windows without a valid ShelfItemType does not add items.
89 std::unique_ptr<views::Widget> widget1 = 89 std::unique_ptr<views::Widget> widget1 =
90 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 90 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
91 WmWindow* window1 = WmWindow::Get(widget1->GetNativeWindow());
92 std::unique_ptr<views::Widget> widget2 = 91 std::unique_ptr<views::Widget> widget2 =
93 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 92 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
94 WmWindow* window2 = WmWindow::Get(widget2->GetNativeWindow());
95 EXPECT_EQ(1, model_->item_count()); 93 EXPECT_EQ(1, model_->item_count());
96 94
97 // Create a ShelfItem for the first window. 95 // Create a ShelfItem for the first window.
98 ShelfID id_w1 = CreateShelfItem(window1); 96 ShelfID id_w1 = CreateShelfItem(widget1->GetNativeWindow());
99 EXPECT_EQ(2, model_->item_count()); 97 EXPECT_EQ(2, model_->item_count());
100 98
101 int index_w1 = model_->ItemIndexByID(id_w1); 99 int index_w1 = model_->ItemIndexByID(id_w1);
102 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); 100 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
103 101
104 // Create a ShelfItem for the second window. 102 // Create a ShelfItem for the second window.
105 ShelfID id_w2 = CreateShelfItem(window2); 103 ShelfID id_w2 = CreateShelfItem(widget2->GetNativeWindow());
106 EXPECT_EQ(3, model_->item_count()); 104 EXPECT_EQ(3, model_->item_count());
107 105
108 int index_w2 = model_->ItemIndexByID(id_w2); 106 int index_w2 = model_->ItemIndexByID(id_w2);
109 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status); 107 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status);
110 108
111 // ShelfItem is removed when the item type window property is cleared. 109 // ShelfItem is removed when the item type window property is cleared.
112 window1->aura_window()->SetProperty(kShelfItemTypeKey, 110 widget1->GetNativeWindow()->SetProperty(kShelfItemTypeKey,
113 static_cast<int32_t>(TYPE_UNDEFINED)); 111 static_cast<int32_t>(TYPE_UNDEFINED));
114 EXPECT_EQ(2, model_->item_count()); 112 EXPECT_EQ(2, model_->item_count());
115 window2->aura_window()->SetProperty(kShelfItemTypeKey, 113 widget2->GetNativeWindow()->SetProperty(kShelfItemTypeKey,
116 static_cast<int32_t>(TYPE_UNDEFINED)); 114 static_cast<int32_t>(TYPE_UNDEFINED));
117 EXPECT_EQ(1, model_->item_count()); 115 EXPECT_EQ(1, model_->item_count());
118 // Clearing twice doesn't do anything. 116 // Clearing twice doesn't do anything.
119 window2->aura_window()->SetProperty(kShelfItemTypeKey, 117 widget2->GetNativeWindow()->SetProperty(kShelfItemTypeKey,
120 static_cast<int32_t>(TYPE_UNDEFINED)); 118 static_cast<int32_t>(TYPE_UNDEFINED));
121 EXPECT_EQ(1, model_->item_count()); 119 EXPECT_EQ(1, model_->item_count());
122 } 120 }
123 121
124 TEST_F(ShelfWindowWatcherTest, ActivateWindow) { 122 TEST_F(ShelfWindowWatcherTest, ActivateWindow) {
125 // TODO: investigate failure in mash. http://crbug.com/695562. 123 // TODO: investigate failure in mash. http://crbug.com/695562.
126 if (Shell::GetAshConfig() == Config::MASH) 124 if (Shell::GetAshConfig() == Config::MASH)
127 return; 125 return;
128 126
129 // ShelfModel only have APP_LIST item. 127 // ShelfModel only has an APP_LIST item.
130 EXPECT_EQ(1, model_->item_count()); 128 EXPECT_EQ(1, model_->item_count());
131 std::unique_ptr<views::Widget> widget1 = 129 std::unique_ptr<views::Widget> widget1 =
132 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 130 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
133 WmWindow* window1 = WmWindow::Get(widget1->GetNativeWindow());
134 std::unique_ptr<views::Widget> widget2 = 131 std::unique_ptr<views::Widget> widget2 =
135 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 132 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
136 WmWindow* window2 = WmWindow::Get(widget2->GetNativeWindow());
137 133
138 // Create a ShelfItem for the first window. 134 // Create a ShelfItem for the first window.
139 ShelfID id_w1 = CreateShelfItem(window1); 135 ShelfID id_w1 = CreateShelfItem(widget1->GetNativeWindow());
140 EXPECT_EQ(2, model_->item_count()); 136 EXPECT_EQ(2, model_->item_count());
141 int index_w1 = model_->ItemIndexByID(id_w1); 137 int index_w1 = model_->ItemIndexByID(id_w1);
142 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); 138 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
143 139
144 // Create a ShelfItem for the second window. 140 // Create a ShelfItem for the second window.
145 ShelfID id_w2 = CreateShelfItem(window2); 141 ShelfID id_w2 = CreateShelfItem(widget2->GetNativeWindow());
146 EXPECT_EQ(3, model_->item_count()); 142 EXPECT_EQ(3, model_->item_count());
147 int index_w2 = model_->ItemIndexByID(id_w2); 143 int index_w2 = model_->ItemIndexByID(id_w2);
148 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); 144 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
149 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status); 145 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status);
150 146
151 // The ShelfItem for the first window is active when the window is activated. 147 // The ShelfItem for the first window is active when the window is activated.
152 widget1->Activate(); 148 widget1->Activate();
153 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w1].status); 149 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w1].status);
154 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status); 150 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status);
155 151
156 // The ShelfItem for the second window is active when the window is activated. 152 // The ShelfItem for the second window is active when the window is activated.
157 widget2->Activate(); 153 widget2->Activate();
158 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); 154 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
159 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status); 155 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status);
160 } 156 }
161 157
162 TEST_F(ShelfWindowWatcherTest, UpdateWindowProperty) { 158 TEST_F(ShelfWindowWatcherTest, UpdateWindowProperty) {
163 // TODO: investigate failure in mash. http://crbug.com/695562. 159 // TODO: investigate failure in mash. http://crbug.com/695562.
164 if (Shell::GetAshConfig() == Config::MASH) 160 if (Shell::GetAshConfig() == Config::MASH)
165 return; 161 return;
166 162
167 // ShelfModel only has an APP_LIST item. 163 // ShelfModel only has an APP_LIST item.
168 EXPECT_EQ(1, model_->item_count()); 164 EXPECT_EQ(1, model_->item_count());
169 165
170 std::unique_ptr<views::Widget> widget = 166 std::unique_ptr<views::Widget> widget =
171 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 167 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
172 WmWindow* window = WmWindow::Get(widget->GetNativeWindow());
173 168
174 // Create a ShelfItem for |window|. 169 // Create a ShelfItem for |window|.
175 ShelfID id = CreateShelfItem(window); 170 ShelfID id = CreateShelfItem(widget->GetNativeWindow());
176 EXPECT_EQ(2, model_->item_count()); 171 EXPECT_EQ(2, model_->item_count());
177 172
178 int index = model_->ItemIndexByID(id); 173 int index = model_->ItemIndexByID(id);
179 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status); 174 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status);
180 175
181 // Update the ShelfItemType for |window|. 176 // Update the window's ShelfItemType.
182 window->aura_window()->SetProperty(kShelfItemTypeKey, 177 widget->GetNativeWindow()->SetProperty(kShelfItemTypeKey,
183 static_cast<int32_t>(TYPE_APP)); 178 static_cast<int32_t>(TYPE_APP));
184 // No new item is created after updating a launcher item. 179 // No new item is created after updating a launcher item.
185 EXPECT_EQ(2, model_->item_count()); 180 EXPECT_EQ(2, model_->item_count());
186 // index and id are not changed after updating a launcher item. 181 // index and id are not changed after updating a launcher item.
187 EXPECT_EQ(index, model_->ItemIndexByID(id)); 182 EXPECT_EQ(index, model_->ItemIndexByID(id));
188 EXPECT_EQ(id, model_->items()[index].id); 183 EXPECT_EQ(id, model_->items()[index].id);
189 } 184 }
190 185
191 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) { 186 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) {
192 // TODO: investigate failure in mash. http://crbug.com/695562. 187 // TODO: investigate failure in mash. http://crbug.com/695562.
193 if (Shell::GetAshConfig() == Config::MASH) 188 if (Shell::GetAshConfig() == Config::MASH)
194 return; 189 return;
195 190
196 // ShelfModel only has an APP_LIST item. 191 // ShelfModel only has an APP_LIST item.
197 EXPECT_EQ(1, model_->item_count()); 192 EXPECT_EQ(1, model_->item_count());
198 193
199 std::unique_ptr<views::Widget> widget = 194 std::unique_ptr<views::Widget> widget =
200 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 195 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
201 WmWindow* window = WmWindow::Get(widget->GetNativeWindow()); 196 wm::WindowState* window_state = wm::GetWindowState(widget->GetNativeWindow());
202 wm::WindowState* window_state = window->GetWindowState();
203 197
204 // Create a ShelfItem for |window|. 198 // Create a ShelfItem for the window.
205 ShelfID id = CreateShelfItem(window); 199 ShelfID id = CreateShelfItem(widget->GetNativeWindow());
206 EXPECT_EQ(2, model_->item_count()); 200 EXPECT_EQ(2, model_->item_count());
207 201
208 int index = model_->ItemIndexByID(id); 202 int index = model_->ItemIndexByID(id);
209 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status); 203 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status);
210 204
211 // Maximize window |window|. 205 // Maximize the window.
212 EXPECT_FALSE(window_state->IsMaximized()); 206 EXPECT_FALSE(window_state->IsMaximized());
213 window_state->Maximize(); 207 window_state->Maximize();
214 EXPECT_TRUE(window_state->IsMaximized()); 208 EXPECT_TRUE(window_state->IsMaximized());
215 // No new item is created after maximizing a window |window|. 209 // No new item is created after maximizing the window.
216 EXPECT_EQ(2, model_->item_count()); 210 EXPECT_EQ(2, model_->item_count());
217 // index and id are not changed after maximizing a window |window|. 211 // index and id are not changed after maximizing the window.
218 EXPECT_EQ(index, model_->ItemIndexByID(id)); 212 EXPECT_EQ(index, model_->ItemIndexByID(id));
219 EXPECT_EQ(id, model_->items()[index].id); 213 EXPECT_EQ(id, model_->items()[index].id);
220 214
221 // Restore window |window|. 215 // Restore the window.
222 window_state->Restore(); 216 window_state->Restore();
223 EXPECT_FALSE(window_state->IsMaximized()); 217 EXPECT_FALSE(window_state->IsMaximized());
224 // No new item is created after restoring a window |window|. 218 // No new item is created after restoring the window.
225 EXPECT_EQ(2, model_->item_count()); 219 EXPECT_EQ(2, model_->item_count());
226 // Index and id are not changed after maximizing a window |window|. 220 // Index and id are not changed after maximizing the window.
227 EXPECT_EQ(index, model_->ItemIndexByID(id)); 221 EXPECT_EQ(index, model_->ItemIndexByID(id));
228 EXPECT_EQ(id, model_->items()[index].id); 222 EXPECT_EQ(id, model_->items()[index].id);
229 } 223 }
230 224
231 // Check |window|'s item is not changed during the dragging. 225 // Check |window|'s item is not changed during the dragging.
232 // TODO(simonhong): Add a test for removing a Window during the dragging. 226 // TODO(simonhong): Add a test for removing a Window during the dragging.
233 TEST_F(ShelfWindowWatcherTest, DragWindow) { 227 TEST_F(ShelfWindowWatcherTest, DragWindow) {
234 // TODO: investigate failure in mash. http://crbug.com/695562. 228 // TODO: investigate failure in mash. http://crbug.com/695562.
235 if (Shell::GetAshConfig() == Config::MASH) 229 if (Shell::GetAshConfig() == Config::MASH)
236 return; 230 return;
237 231
238 // ShelfModel only has an APP_LIST item. 232 // ShelfModel only has an APP_LIST item.
239 EXPECT_EQ(1, model_->item_count()); 233 EXPECT_EQ(1, model_->item_count());
240 234
241 std::unique_ptr<views::Widget> widget = 235 std::unique_ptr<views::Widget> widget =
242 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 236 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
243 WmWindow* window = WmWindow::Get(widget->GetNativeWindow());
244 237
245 // Create a ShelfItem for |window|. 238 // Create a ShelfItem for the window.
246 ShelfID id = CreateShelfItem(window); 239 ShelfID id = CreateShelfItem(widget->GetNativeWindow());
247 EXPECT_EQ(2, model_->item_count()); 240 EXPECT_EQ(2, model_->item_count());
248 241
249 int index = model_->ItemIndexByID(id); 242 int index = model_->ItemIndexByID(id);
250 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status); 243 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status);
251 244
252 // Simulate dragging of |window| and check its item is not changed. 245 // Simulate dragging of the window and check its item is not changed.
253 std::unique_ptr<WindowResizer> resizer(CreateWindowResizer( 246 std::unique_ptr<WindowResizer> resizer(CreateWindowResizer(
254 window, gfx::Point(), HTCAPTION, aura::client::WINDOW_MOVE_SOURCE_MOUSE)); 247 WmWindow::Get(widget->GetNativeWindow()), gfx::Point(), HTCAPTION,
248 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
255 ASSERT_TRUE(resizer.get()); 249 ASSERT_TRUE(resizer.get());
256 resizer->Drag(gfx::Point(50, 50), 0); 250 resizer->Drag(gfx::Point(50, 50), 0);
257 resizer->CompleteDrag(); 251 resizer->CompleteDrag();
258 252
259 // Index and id are not changed after dragging a |window|. 253 // Index and id are not changed after dragging the window.
260 EXPECT_EQ(index, model_->ItemIndexByID(id)); 254 EXPECT_EQ(index, model_->ItemIndexByID(id));
261 EXPECT_EQ(id, model_->items()[index].id); 255 EXPECT_EQ(id, model_->items()[index].id);
262 } 256 }
263 257
264 // Ensure shelf items are added and removed as panels are opened and closed. 258 // Ensure shelf items are added and removed as panels are opened and closed.
265 TEST_F(ShelfWindowWatcherTest, PanelWindow) { 259 TEST_F(ShelfWindowWatcherTest, PanelWindow) {
266 // TODO: investigate failure in mash. http://crbug.com/695562. 260 // TODO: investigate failure in mash. http://crbug.com/695562.
267 if (Shell::GetAshConfig() == Config::MASH) 261 if (Shell::GetAshConfig() == Config::MASH)
268 return; 262 return;
269 263
270 // ShelfModel only has an APP_LIST item. 264 // ShelfModel only has an APP_LIST item.
271 EXPECT_EQ(1, model_->item_count()); 265 EXPECT_EQ(1, model_->item_count());
272 266
273 // Adding windows with valid ShelfItemType properties adds shelf items. 267 // Adding windows with valid ShelfItemType properties adds shelf items.
274 std::unique_ptr<views::Widget> widget1 = 268 std::unique_ptr<views::Widget> widget1 =
275 CreateTestWidget(nullptr, kShellWindowId_PanelContainer, gfx::Rect()); 269 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
276 WmWindow* window1 = WmWindow::Get(widget1->GetNativeWindow()); 270 aura::Window* window1 = widget1->GetNativeWindow();
277 window1->aura_window()->SetProperty(kShelfIDKey, new ShelfID("foo")); 271 window1->SetProperty(kShelfIDKey, new std::string(ShelfID("a").Serialize()));
James Cook 2017/05/15 16:37:23 Oh, you and your love of fitting it all on one lin
msw 2017/05/15 19:21:32 Hahaha, I can't help it!
278 window1->aura_window()->SetProperty(kShelfItemTypeKey, 272 window1->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP));
279 static_cast<int32_t>(TYPE_APP_PANEL));
280 EXPECT_EQ(2, model_->item_count()); 273 EXPECT_EQ(2, model_->item_count());
281 std::unique_ptr<views::Widget> widget2 = 274 std::unique_ptr<views::Widget> widget2 =
282 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 275 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
283 WmWindow* window2 = WmWindow::Get(widget2->GetNativeWindow()); 276 aura::Window* window2 = widget2->GetNativeWindow();
284 window2->aura_window()->SetProperty(kShelfIDKey, new ShelfID("bar")); 277 window2->SetProperty(kShelfIDKey, new std::string(ShelfID("b").Serialize()));
285 window2->aura_window()->SetProperty(kShelfItemTypeKey, 278 window2->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_DIALOG));
286 static_cast<int32_t>(TYPE_APP_PANEL));
287 EXPECT_EQ(3, model_->item_count()); 279 EXPECT_EQ(3, model_->item_count());
288 280
289 // Create a panel-type widget to mimic Chrome's app panel windows. 281 // Create a panel-type widget to mimic Chrome's app panel windows.
290 views::Widget panel_widget; 282 views::Widget panel_widget;
291 views::Widget::InitParams panel_params(views::Widget::InitParams::TYPE_PANEL); 283 views::Widget::InitParams panel_params(views::Widget::InitParams::TYPE_PANEL);
292 panel_params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 284 panel_params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
293 ShellPort::Get() 285 ShellPort::Get()
294 ->GetPrimaryRootWindow() 286 ->GetPrimaryRootWindow()
295 ->GetRootWindowController() 287 ->GetRootWindowController()
296 ->ConfigureWidgetInitParamsForContainer( 288 ->ConfigureWidgetInitParamsForContainer(
297 &panel_widget, kShellWindowId_PanelContainer, &panel_params); 289 &panel_widget, kShellWindowId_PanelContainer, &panel_params);
298 panel_widget.Init(panel_params); 290 panel_widget.Init(panel_params);
299 panel_widget.Show(); 291 panel_widget.Show();
300 WmWindow* panel_window = WmWindow::Get(panel_widget.GetNativeWindow()); 292 aura::Window* panel_window = panel_widget.GetNativeWindow();
301 panel_window->aura_window()->SetProperty(kShelfIDKey, new ShelfID("baz")); 293 panel_window->SetProperty(kShelfIDKey,
302 panel_window->aura_window()->SetProperty( 294 new std::string(ShelfID("c").Serialize()));
303 kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP_PANEL)); 295 panel_window->SetProperty(kShelfItemTypeKey,
296 static_cast<int32_t>(TYPE_APP_PANEL));
304 EXPECT_EQ(4, model_->item_count()); 297 EXPECT_EQ(4, model_->item_count());
305 298
306 // Each ShelfItem is removed when the associated window is destroyed. 299 // Each ShelfItem is removed when the associated window is destroyed.
307 panel_widget.CloseNow(); 300 panel_widget.CloseNow();
308 EXPECT_EQ(3, model_->item_count()); 301 EXPECT_EQ(3, model_->item_count());
309 widget2.reset(); 302 widget2.reset();
310 EXPECT_EQ(2, model_->item_count()); 303 EXPECT_EQ(2, model_->item_count());
311 widget1.reset(); 304 widget1.reset();
312 EXPECT_EQ(1, model_->item_count()); 305 EXPECT_EQ(1, model_->item_count());
313 } 306 }
314 307
315 TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) { 308 TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) {
316 const int initial_item_count = model_->item_count(); 309 const int initial_item_count = model_->item_count();
317 310
318 std::unique_ptr<aura::Window> window( 311 std::unique_ptr<aura::Window> window(
319 base::MakeUnique<aura::Window>(nullptr, ui::wm::WINDOW_TYPE_NORMAL)); 312 base::MakeUnique<aura::Window>(nullptr, ui::wm::WINDOW_TYPE_NORMAL));
320 window->Init(ui::LAYER_NOT_DRAWN); 313 window->Init(ui::LAYER_NOT_DRAWN);
321 window->SetProperty(kShelfIDKey, new ShelfID("foo")); 314 window->SetProperty(kShelfIDKey, new std::string(ShelfID("foo").Serialize()));
322 window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP)); 315 window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP));
323 Shell::GetPrimaryRootWindow() 316 Shell::GetPrimaryRootWindow()
324 ->GetChildById(kShellWindowId_DefaultContainer) 317 ->GetChildById(kShellWindowId_DefaultContainer)
325 ->AddChild(window.get()); 318 ->AddChild(window.get());
326 window->Show(); 319 window->Show();
327 EXPECT_EQ(initial_item_count + 1, model_->item_count()); 320 EXPECT_EQ(initial_item_count + 1, model_->item_count());
328 321
329 std::unique_ptr<aura::Window> child_window( 322 std::unique_ptr<aura::Window> child_window(
330 base::MakeUnique<aura::Window>(nullptr, ui::wm::WINDOW_TYPE_NORMAL)); 323 base::MakeUnique<aura::Window>(nullptr, ui::wm::WINDOW_TYPE_NORMAL));
331 child_window->Init(ui::LAYER_NOT_DRAWN); 324 child_window->Init(ui::LAYER_NOT_DRAWN);
(...skipping 14 matching lines...) Expand all
346 ShelfModel* model = Shell::Get()->shelf_model(); 339 ShelfModel* model = Shell::Get()->shelf_model();
347 ASSERT_FALSE( 340 ASSERT_FALSE(
348 Shell::Get()->session_controller()->IsActiveUserSessionStarted()); 341 Shell::Get()->session_controller()->IsActiveUserSessionStarted());
349 342
350 // ShelfModel only has an APP_LIST item. 343 // ShelfModel only has an APP_LIST item.
351 EXPECT_EQ(1, model->item_count()); 344 EXPECT_EQ(1, model->item_count());
352 345
353 // Construct a window that should get a shelf item once the session starts. 346 // Construct a window that should get a shelf item once the session starts.
354 std::unique_ptr<views::Widget> widget = 347 std::unique_ptr<views::Widget> widget =
355 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 348 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
356 WmWindow* window = WmWindow::Get(widget->GetNativeWindow()); 349 ShelfWindowWatcherTest::CreateShelfItem(widget->GetNativeWindow());
357 ShelfWindowWatcherTest::CreateShelfItem(window);
358 EXPECT_EQ(1, model->item_count()); 350 EXPECT_EQ(1, model->item_count());
359 351
360 // Start the test user session; ShelfWindowWatcher will find the open window. 352 // Start the test user session; ShelfWindowWatcher will find the open window.
361 SetSessionStarted(true); 353 SetSessionStarted(true);
362 EXPECT_EQ(2, model->item_count()); 354 EXPECT_EQ(2, model->item_count());
363 } 355 }
364 356
365 } // namespace ash 357 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698