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

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

Issue 2927693002: mash: Limit ShelfWindowWatcher to panels and dialogs. (Closed)
Patch Set: Disable WindowSelectorTest.MultipleDisplays in mash. Created 3 years, 6 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/shelf_model.h" 9 #include "ash/public/cpp/shelf_model.h"
10 #include "ash/public/cpp/shell_window_ids.h" 10 #include "ash/public/cpp/shell_window_ids.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 CreateShelfItem(widget2->GetNativeWindow()); 82 CreateShelfItem(widget2->GetNativeWindow());
83 EXPECT_EQ(3, model_->item_count()); 83 EXPECT_EQ(3, model_->item_count());
84 84
85 // Each ShelfItem is removed when the associated window is destroyed. 85 // Each ShelfItem is removed when the associated window is destroyed.
86 widget1.reset(); 86 widget1.reset();
87 EXPECT_EQ(2, model_->item_count()); 87 EXPECT_EQ(2, model_->item_count());
88 widget2.reset(); 88 widget2.reset();
89 EXPECT_EQ(1, model_->item_count()); 89 EXPECT_EQ(1, model_->item_count());
90 } 90 }
91 91
92 // Ensure shelf items are added and removed for unknown windows in mash. 92 // Ensure shelf items are added and removed for some unknown windows in mash.
93 TEST_F(ShelfWindowWatcherTest, OpenAndCloseMash) { 93 TEST_F(ShelfWindowWatcherTest, OpenAndCloseMash) {
94 if (Shell::GetAshConfig() != Config::MASH) 94 if (Shell::GetAshConfig() != Config::MASH)
95 return; 95 return;
96 96
97 // ShelfModel only has an APP_LIST item. 97 // ShelfModel only has an APP_LIST item.
98 EXPECT_EQ(1, model_->item_count()); 98 EXPECT_EQ(1, model_->item_count());
99 99
100 // Windows with no valid ShelfItemType and ShelfID properties get shelf items. 100 // Windows with no valid ShelfItemType and ShelfID properties get shelf items.
101 std::unique_ptr<views::Widget> widget1 = 101 std::unique_ptr<views::Widget> widget1 =
102 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 102 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
103 EXPECT_EQ(2, model_->item_count()); 103 EXPECT_EQ(2, model_->item_count());
104 std::unique_ptr<views::Widget> widget2 = 104 std::unique_ptr<views::Widget> widget2 =
105 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 105 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
106 EXPECT_EQ(3, model_->item_count()); 106 EXPECT_EQ(3, model_->item_count());
107 107
108 // Each ShelfItem is removed when the associated window is destroyed. 108 // Each ShelfItem is removed when the associated window is destroyed.
109 widget1.reset(); 109 widget1.reset();
110 EXPECT_EQ(2, model_->item_count()); 110 EXPECT_EQ(2, model_->item_count());
111 widget2.reset(); 111 widget2.reset();
112 EXPECT_EQ(1, model_->item_count()); 112 EXPECT_EQ(1, model_->item_count());
113 113
114 // Windows with type WINDOW_TYPE_NORMAL get shelf items, others do not.
115 aura::client::WindowType no_item_types[] = {
116 aura::client::WINDOW_TYPE_UNKNOWN, aura::client::WINDOW_TYPE_NORMAL,
117 aura::client::WINDOW_TYPE_POPUP, aura::client::WINDOW_TYPE_CONTROL,
118 aura::client::WINDOW_TYPE_PANEL, aura::client::WINDOW_TYPE_MENU,
119 aura::client::WINDOW_TYPE_TOOLTIP};
120 for (aura::client::WindowType type : no_item_types) {
121 std::unique_ptr<aura::Window> window =
122 base::MakeUnique<aura::Window>(nullptr, type);
123 window->Init(ui::LAYER_NOT_DRAWN);
124 Shell::GetPrimaryRootWindow()
125 ->GetChildById(kShellWindowId_DefaultContainer)
126 ->AddChild(window.get());
127 window->Show();
128 EXPECT_EQ(type == aura::client::WINDOW_TYPE_NORMAL ? 2 : 1,
James Cook 2017/06/08 17:14:00 nit: Take WINDOW_TYPE_NORMAL out of the array abov
129 model_->item_count());
130 }
131
114 // Windows with WindowState::ignored_by_shelf set do not get shelf items. 132 // Windows with WindowState::ignored_by_shelf set do not get shelf items.
115 widget1 = 133 widget1 =
116 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 134 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
117 wm::GetWindowState(widget1->GetNativeWindow())->set_ignored_by_shelf(true); 135 wm::GetWindowState(widget1->GetNativeWindow())->set_ignored_by_shelf(true);
118 // TODO(msw): Make the flag a window property and remove this workaround. 136 // TODO(msw): Make the flag a window property and remove this workaround.
119 widget1->GetNativeWindow()->SetProperty(aura::client::kDrawAttentionKey, 137 widget1->GetNativeWindow()->SetProperty(aura::client::kDrawAttentionKey,
120 true); 138 true);
121 EXPECT_EQ(1, model_->item_count()); 139 EXPECT_EQ(1, model_->item_count());
122 } 140 }
123 141
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w1].status); 211 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w1].status);
194 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status); 212 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status);
195 213
196 // The ShelfItem for the second window is active when the window is activated. 214 // The ShelfItem for the second window is active when the window is activated.
197 widget2->Activate(); 215 widget2->Activate();
198 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); 216 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
199 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status); 217 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status);
200 } 218 }
201 219
202 TEST_F(ShelfWindowWatcherTest, UpdateWindowProperty) { 220 TEST_F(ShelfWindowWatcherTest, UpdateWindowProperty) {
203 // TODO: investigate failure in mash. http://crbug.com/695562.
James Cook 2017/06/08 17:14:00 Woo hoo, things work in mash!
204 if (Shell::GetAshConfig() == Config::MASH)
205 return;
206
207 // ShelfModel only has an APP_LIST item. 221 // ShelfModel only has an APP_LIST item.
208 EXPECT_EQ(1, model_->item_count()); 222 EXPECT_EQ(1, model_->item_count());
209 223
210 std::unique_ptr<views::Widget> widget = 224 std::unique_ptr<views::Widget> widget =
211 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 225 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
212 226
213 // Create a ShelfItem for |window|. 227 // Create a ShelfItem for |window|.
214 ShelfID id = CreateShelfItem(widget->GetNativeWindow()); 228 ShelfID id = CreateShelfItem(widget->GetNativeWindow());
215 EXPECT_EQ(2, model_->item_count()); 229 EXPECT_EQ(2, model_->item_count());
216 230
217 int index = model_->ItemIndexByID(id); 231 int index = model_->ItemIndexByID(id);
218 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status); 232 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status);
219 233
220 // Update the window's ShelfItemType. 234 // Update the window's ShelfItemType.
221 widget->GetNativeWindow()->SetProperty(kShelfItemTypeKey, 235 widget->GetNativeWindow()->SetProperty(kShelfItemTypeKey,
222 static_cast<int32_t>(TYPE_APP)); 236 static_cast<int32_t>(TYPE_APP_PANEL));
223 // No new item is created after updating a launcher item. 237 // No new item is created after updating a launcher item.
224 EXPECT_EQ(2, model_->item_count()); 238 EXPECT_EQ(2, model_->item_count());
225 // index and id are not changed after updating a launcher item. 239 // index and id are not changed after updating a launcher item.
226 EXPECT_EQ(index, model_->ItemIndexByID(id)); 240 EXPECT_EQ(index, model_->ItemIndexByID(id));
227 EXPECT_EQ(id, model_->items()[index].id); 241 EXPECT_EQ(id, model_->items()[index].id);
228 } 242 }
229 243
230 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) { 244 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) {
231 // TODO: investigate failure in mash. http://crbug.com/695562.
232 if (Shell::GetAshConfig() == Config::MASH)
233 return;
234
235 // ShelfModel only has an APP_LIST item. 245 // ShelfModel only has an APP_LIST item.
236 EXPECT_EQ(1, model_->item_count()); 246 EXPECT_EQ(1, model_->item_count());
237 247
238 std::unique_ptr<views::Widget> widget = 248 std::unique_ptr<views::Widget> widget =
239 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 249 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
240 wm::WindowState* window_state = wm::GetWindowState(widget->GetNativeWindow()); 250 wm::WindowState* window_state = wm::GetWindowState(widget->GetNativeWindow());
241 251
242 // Create a ShelfItem for the window. 252 // Create a ShelfItem for the window.
243 ShelfID id = CreateShelfItem(widget->GetNativeWindow()); 253 ShelfID id = CreateShelfItem(widget->GetNativeWindow());
244 EXPECT_EQ(2, model_->item_count()); 254 EXPECT_EQ(2, model_->item_count());
(...skipping 17 matching lines...) Expand all
262 // No new item is created after restoring the window. 272 // No new item is created after restoring the window.
263 EXPECT_EQ(2, model_->item_count()); 273 EXPECT_EQ(2, model_->item_count());
264 // Index and id are not changed after maximizing the window. 274 // Index and id are not changed after maximizing the window.
265 EXPECT_EQ(index, model_->ItemIndexByID(id)); 275 EXPECT_EQ(index, model_->ItemIndexByID(id));
266 EXPECT_EQ(id, model_->items()[index].id); 276 EXPECT_EQ(id, model_->items()[index].id);
267 } 277 }
268 278
269 // Check |window|'s item is not changed during the dragging. 279 // Check |window|'s item is not changed during the dragging.
270 // TODO(simonhong): Add a test for removing a Window during the dragging. 280 // TODO(simonhong): Add a test for removing a Window during the dragging.
271 TEST_F(ShelfWindowWatcherTest, DragWindow) { 281 TEST_F(ShelfWindowWatcherTest, DragWindow) {
272 // TODO: investigate failure in mash. http://crbug.com/695562.
273 if (Shell::GetAshConfig() == Config::MASH)
274 return;
275
276 // ShelfModel only has an APP_LIST item. 282 // ShelfModel only has an APP_LIST item.
277 EXPECT_EQ(1, model_->item_count()); 283 EXPECT_EQ(1, model_->item_count());
278 284
279 std::unique_ptr<views::Widget> widget = 285 std::unique_ptr<views::Widget> widget =
280 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 286 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
281 287
282 // Create a ShelfItem for the window. 288 // Create a ShelfItem for the window.
283 ShelfID id = CreateShelfItem(widget->GetNativeWindow()); 289 ShelfID id = CreateShelfItem(widget->GetNativeWindow());
284 EXPECT_EQ(2, model_->item_count()); 290 EXPECT_EQ(2, model_->item_count());
285 291
286 int index = model_->ItemIndexByID(id); 292 int index = model_->ItemIndexByID(id);
287 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status); 293 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status);
288 294
289 // Simulate dragging of the window and check its item is not changed. 295 // Simulate dragging of the window and check its item is not changed.
290 std::unique_ptr<WindowResizer> resizer( 296 std::unique_ptr<WindowResizer> resizer(
291 CreateWindowResizer(widget->GetNativeWindow(), gfx::Point(), HTCAPTION, 297 CreateWindowResizer(widget->GetNativeWindow(), gfx::Point(), HTCAPTION,
292 ::wm::WINDOW_MOVE_SOURCE_MOUSE)); 298 ::wm::WINDOW_MOVE_SOURCE_MOUSE));
293 ASSERT_TRUE(resizer.get()); 299 ASSERT_TRUE(resizer.get());
294 resizer->Drag(gfx::Point(50, 50), 0); 300 resizer->Drag(gfx::Point(50, 50), 0);
295 resizer->CompleteDrag(); 301 resizer->CompleteDrag();
296 302
297 // Index and id are not changed after dragging the window. 303 // Index and id are not changed after dragging the window.
298 EXPECT_EQ(index, model_->ItemIndexByID(id)); 304 EXPECT_EQ(index, model_->ItemIndexByID(id));
299 EXPECT_EQ(id, model_->items()[index].id); 305 EXPECT_EQ(id, model_->items()[index].id);
300 } 306 }
301 307
302 // Ensure shelf items are added and removed as panels are opened and closed. 308 // Ensure panels and dialogs get shelf items.
303 TEST_F(ShelfWindowWatcherTest, PanelWindow) { 309 TEST_F(ShelfWindowWatcherTest, PanelAndDialogWindows) {
304 // TODO: investigate failure in mash. http://crbug.com/695562.
305 if (Shell::GetAshConfig() == Config::MASH)
306 return;
307
308 // ShelfModel only has an APP_LIST item. 310 // ShelfModel only has an APP_LIST item.
309 EXPECT_EQ(1, model_->item_count()); 311 EXPECT_EQ(1, model_->item_count());
310 312
311 // Adding windows with valid ShelfItemType properties adds shelf items. 313 // An item is created for a dialog window.
312 std::unique_ptr<views::Widget> widget1 = 314 std::unique_ptr<views::Widget> dialog_widget =
313 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 315 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
314 aura::Window* window1 = widget1->GetNativeWindow(); 316 aura::Window* dialog = dialog_widget->GetNativeWindow();
315 window1->SetProperty(kShelfIDKey, new std::string(ShelfID("a").Serialize())); 317 dialog->SetProperty(kShelfIDKey, new std::string(ShelfID("a").Serialize()));
316 window1->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP)); 318 dialog->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_DIALOG));
317 EXPECT_EQ(2, model_->item_count()); 319 EXPECT_EQ(2, model_->item_count());
318 std::unique_ptr<views::Widget> widget2 =
319 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
320 aura::Window* window2 = widget2->GetNativeWindow();
321 window2->SetProperty(kShelfIDKey, new std::string(ShelfID("b").Serialize()));
322 window2->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_DIALOG));
323 EXPECT_EQ(3, model_->item_count());
324 320
325 // Create a panel-type widget to mimic Chrome's app panel windows. 321 // An item is created for a panel window.
James Cook 2017/06/08 17:14:00 I think this test would be clearer if split into m
326 views::Widget panel_widget; 322 views::Widget panel_widget;
327 views::Widget::InitParams panel_params(views::Widget::InitParams::TYPE_PANEL); 323 views::Widget::InitParams panel_params(views::Widget::InitParams::TYPE_PANEL);
328 panel_params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 324 panel_params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
329 Shell::GetPrimaryRootWindowController() 325 Shell::GetPrimaryRootWindowController()
330 ->ConfigureWidgetInitParamsForContainer( 326 ->ConfigureWidgetInitParamsForContainer(
331 &panel_widget, kShellWindowId_PanelContainer, &panel_params); 327 &panel_widget, kShellWindowId_PanelContainer, &panel_params);
332 panel_widget.Init(panel_params); 328 panel_widget.Init(panel_params);
333 panel_widget.Show(); 329 panel_widget.Show();
334 aura::Window* panel_window = panel_widget.GetNativeWindow(); 330 aura::Window* panel = panel_widget.GetNativeWindow();
335 panel_window->SetProperty(kShelfIDKey, 331 panel->SetProperty(kShelfIDKey, new std::string(ShelfID("b").Serialize()));
336 new std::string(ShelfID("c").Serialize())); 332 panel->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP_PANEL));
337 panel_window->SetProperty(kShelfItemTypeKey, 333 EXPECT_EQ(3, model_->item_count());
338 static_cast<int32_t>(TYPE_APP_PANEL)); 334
339 EXPECT_EQ(4, model_->item_count()); 335 // An item is not created for an app window.
336 std::unique_ptr<views::Widget> app_widget =
337 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
338 aura::Window* app = app_widget->GetNativeWindow();
339 app->SetProperty(kShelfIDKey, new std::string(ShelfID("c").Serialize()));
340 app->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP));
341 EXPECT_EQ(3, model_->item_count());
342 app_widget.reset();
340 343
341 // Each ShelfItem is removed when the associated window is destroyed. 344 // Each ShelfItem is removed when the associated window is destroyed.
342 panel_widget.CloseNow(); 345 panel_widget.CloseNow();
343 EXPECT_EQ(3, model_->item_count());
344 widget2.reset();
345 EXPECT_EQ(2, model_->item_count()); 346 EXPECT_EQ(2, model_->item_count());
346 widget1.reset(); 347 dialog_widget.reset();
347 EXPECT_EQ(1, model_->item_count()); 348 EXPECT_EQ(1, model_->item_count());
348 } 349 }
349 350
350 // Ensure items use the app icon and window icon aura::Window properties. 351 // Ensure items use the app icon and window icon aura::Window properties.
351 TEST_F(ShelfWindowWatcherTest, ItemIcon) { 352 TEST_F(ShelfWindowWatcherTest, ItemIcon) {
352 // ShelfModel only has an APP_LIST item. 353 // ShelfModel only has an APP_LIST item.
353 EXPECT_EQ(1, model_->item_count()); 354 EXPECT_EQ(1, model_->item_count());
354 355
355 // Create a ShelfItem for a window; it should have a default icon. 356 // Create a ShelfItem for a window; it should have a default icon.
356 std::unique_ptr<views::Widget> widget = 357 std::unique_ptr<views::Widget> widget =
(...skipping 15 matching lines...) Expand all
372 const gfx::ImageSkia blue = CreateImageSkiaIcon(SK_ColorBLUE); 373 const gfx::ImageSkia blue = CreateImageSkiaIcon(SK_ColorBLUE);
373 window->SetProperty(aura::client::kAppIconKey, new gfx::ImageSkia(blue)); 374 window->SetProperty(aura::client::kAppIconKey, new gfx::ImageSkia(blue));
374 EXPECT_EQ(SK_ColorBLUE, model_->items()[1].image.bitmap()->getColor(0, 0)); 375 EXPECT_EQ(SK_ColorBLUE, model_->items()[1].image.bitmap()->getColor(0, 0));
375 376
376 // Clearing the app icon should restore the window icon to the shelf item. 377 // Clearing the app icon should restore the window icon to the shelf item.
377 window->ClearProperty(aura::client::kAppIconKey); 378 window->ClearProperty(aura::client::kAppIconKey);
378 EXPECT_EQ(SK_ColorRED, model_->items()[1].image.bitmap()->getColor(0, 0)); 379 EXPECT_EQ(SK_ColorRED, model_->items()[1].image.bitmap()->getColor(0, 0));
379 } 380 }
380 381
381 TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) { 382 TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) {
382 const int initial_item_count = model_->item_count(); 383 EXPECT_EQ(1, model_->item_count());
383 384 std::unique_ptr<aura::Window> window =
384 std::unique_ptr<aura::Window> window(base::MakeUnique<aura::Window>( 385 base::MakeUnique<aura::Window>(nullptr, aura::client::WINDOW_TYPE_NORMAL);
385 nullptr, aura::client::WINDOW_TYPE_NORMAL));
386 window->Init(ui::LAYER_NOT_DRAWN); 386 window->Init(ui::LAYER_NOT_DRAWN);
387 window->SetProperty(kShelfIDKey, new std::string(ShelfID("foo").Serialize())); 387 window->SetProperty(kShelfIDKey, new std::string(ShelfID("a").Serialize()));
388 window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP)); 388 window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_DIALOG));
389 Shell::GetPrimaryRootWindow() 389 Shell::GetPrimaryRootWindow()
390 ->GetChildById(kShellWindowId_DefaultContainer) 390 ->GetChildById(kShellWindowId_DefaultContainer)
391 ->AddChild(window.get()); 391 ->AddChild(window.get());
392 window->Show(); 392 window->Show();
393 EXPECT_EQ(initial_item_count + 1, model_->item_count()); 393 EXPECT_EQ(2, model_->item_count());
James Cook 2017/06/08 17:14:00 Hooray for explicit expectations instead of math i
394 394
395 std::unique_ptr<aura::Window> child_window(base::MakeUnique<aura::Window>( 395 std::unique_ptr<aura::Window> child =
396 nullptr, aura::client::WINDOW_TYPE_NORMAL)); 396 base::MakeUnique<aura::Window>(nullptr, aura::client::WINDOW_TYPE_NORMAL);
397 child_window->Init(ui::LAYER_NOT_DRAWN); 397 child->Init(ui::LAYER_NOT_DRAWN);
398 child_window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP)); 398 child->SetProperty(kShelfIDKey, new std::string(ShelfID("b").Serialize()));
399 window->AddChild(child_window.get()); 399 child->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_DIALOG));
400 child_window->Show(); 400 window->AddChild(child.get());
401 // |child_window| should not result in adding a new entry. 401 child->Show();
402 EXPECT_EQ(initial_item_count + 1, model_->item_count()); 402 // There should not be a new shelf item for |child|.
403 EXPECT_EQ(2, model_->item_count());
403 404
404 child_window.reset(); 405 child.reset();
406 EXPECT_EQ(2, model_->item_count());
405 window.reset(); 407 window.reset();
406 EXPECT_EQ(initial_item_count, model_->item_count()); 408 EXPECT_EQ(1, model_->item_count());
407 } 409 }
408 410
409 TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForTransientWindows) { 411 TEST_F(ShelfWindowWatcherTest, CreateShelfEntriesForTransientWindows) {
410 const int initial_item_count = model_->item_count(); 412 EXPECT_EQ(1, model_->item_count());
411 413 std::unique_ptr<aura::Window> window =
412 std::unique_ptr<aura::Window> window(base::MakeUnique<aura::Window>( 414 base::MakeUnique<aura::Window>(nullptr, aura::client::WINDOW_TYPE_NORMAL);
413 nullptr, aura::client::WINDOW_TYPE_NORMAL));
414 window->Init(ui::LAYER_NOT_DRAWN); 415 window->Init(ui::LAYER_NOT_DRAWN);
415 window->SetProperty(kShelfIDKey, new std::string(ShelfID("foo").Serialize())); 416 window->SetProperty(kShelfIDKey, new std::string(ShelfID("a").Serialize()));
416 window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP)); 417 window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_DIALOG));
417 Shell::GetPrimaryRootWindow() 418 Shell::GetPrimaryRootWindow()
418 ->GetChildById(kShellWindowId_DefaultContainer) 419 ->GetChildById(kShellWindowId_DefaultContainer)
419 ->AddChild(window.get()); 420 ->AddChild(window.get());
420 window->Show(); 421 window->Show();
421 EXPECT_EQ(initial_item_count + 1, model_->item_count()); 422 EXPECT_EQ(2, model_->item_count());
422 423
423 std::unique_ptr<aura::Window> transient_window(base::MakeUnique<aura::Window>( 424 std::unique_ptr<aura::Window> transient =
424 nullptr, aura::client::WINDOW_TYPE_NORMAL)); 425 base::MakeUnique<aura::Window>(nullptr, aura::client::WINDOW_TYPE_NORMAL);
425 transient_window->Init(ui::LAYER_NOT_DRAWN); 426 transient->Init(ui::LAYER_NOT_DRAWN);
426 transient_window->SetProperty(kShelfItemTypeKey, 427 transient->SetProperty(kShelfIDKey,
427 static_cast<int32_t>(TYPE_APP)); 428 new std::string(ShelfID("b").Serialize()));
428 ::wm::TransientWindowController::Get()->AddTransientChild( 429 transient->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_DIALOG));
429 window.get(), transient_window.get()); 430 Shell::GetPrimaryRootWindow()
430 transient_window->Show(); 431 ->GetChildById(kShellWindowId_DefaultContainer)
431 // |transient_window| should not result in adding a new entry. 432 ->AddChild(transient.get());
432 EXPECT_EQ(initial_item_count + 1, model_->item_count()); 433 ::wm::TransientWindowController::Get()->AddTransientChild(window.get(),
434 transient.get());
435 transient->Show();
436 // There should be a new shelf item for |transient|.
437 EXPECT_EQ(3, model_->item_count());
433 438
434 transient_window.reset(); 439 transient.reset();
440 EXPECT_EQ(2, model_->item_count());
435 window.reset(); 441 window.reset();
436 EXPECT_EQ(initial_item_count, model_->item_count()); 442 EXPECT_EQ(1, model_->item_count());
437 } 443 }
438 444
439 // Ensures ShelfWindowWatcher supports windows opened prior to session start. 445 // Ensures ShelfWindowWatcher supports windows opened prior to session start.
440 using ShelfWindowWatcherSessionStartTest = test::NoSessionAshTestBase; 446 using ShelfWindowWatcherSessionStartTest = test::NoSessionAshTestBase;
441 TEST_F(ShelfWindowWatcherSessionStartTest, PreExistingWindow) { 447 TEST_F(ShelfWindowWatcherSessionStartTest, PreExistingWindow) {
442 ShelfModel* model = Shell::Get()->shelf_model(); 448 ShelfModel* model = Shell::Get()->shelf_model();
443 ASSERT_FALSE( 449 ASSERT_FALSE(
444 Shell::Get()->session_controller()->IsActiveUserSessionStarted()); 450 Shell::Get()->session_controller()->IsActiveUserSessionStarted());
445 451
446 // ShelfModel only has an APP_LIST item. 452 // ShelfModel only has an APP_LIST item.
447 EXPECT_EQ(1, model->item_count()); 453 EXPECT_EQ(1, model->item_count());
448 454
449 // Construct a window that should get a shelf item once the session starts. 455 // Construct a window that should get a shelf item once the session starts.
450 std::unique_ptr<views::Widget> widget = 456 std::unique_ptr<views::Widget> widget =
451 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 457 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
452 ShelfWindowWatcherTest::CreateShelfItem(widget->GetNativeWindow()); 458 ShelfWindowWatcherTest::CreateShelfItem(widget->GetNativeWindow());
453 EXPECT_EQ(1, model->item_count()); 459 EXPECT_EQ(1, model->item_count());
454 460
455 // Start the test user session; ShelfWindowWatcher will find the open window. 461 // Start the test user session; ShelfWindowWatcher will find the open window.
456 SetSessionStarted(true); 462 SetSessionStarted(true);
457 EXPECT_EQ(2, model->item_count()); 463 EXPECT_EQ(2, model->item_count());
458 } 464 }
459 465
460 } // namespace 466 } // namespace
461 } // namespace ash 467 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698