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

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

Issue 2731663002: Remove WmWindowProperty (Closed)
Patch Set: Created 3 years, 9 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/session/session_state_delegate.h" 7 #include "ash/common/session/session_state_delegate.h"
8 #include "ash/common/shelf/shelf_item_types.h" 8 #include "ash/common/shelf/shelf_item_types.h"
9 #include "ash/common/shelf/shelf_model.h" 9 #include "ash/common/shelf/shelf_model.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"
16 #include "ash/public/cpp/shell_window_ids.h" 15 #include "ash/public/cpp/shell_window_ids.h"
16 #include "ash/public/cpp/window_properties.h"
17 #include "ash/root_window_controller.h" 17 #include "ash/root_window_controller.h"
18 #include "ash/test/ash_test_base.h" 18 #include "ash/test/ash_test_base.h"
19 #include "ui/base/hit_test.h" 19 #include "ui/base/hit_test.h"
20 #include "ui/views/widget/widget.h" 20 #include "ui/views/widget/widget.h"
21 21
22 namespace ash { 22 namespace ash {
23 23
24 class ShelfWindowWatcherTest : public test::AshTestBase { 24 class ShelfWindowWatcherTest : public test::AshTestBase {
25 public: 25 public:
26 ShelfWindowWatcherTest() : model_(nullptr) {} 26 ShelfWindowWatcherTest() : model_(nullptr) {}
27 ~ShelfWindowWatcherTest() override {} 27 ~ShelfWindowWatcherTest() override {}
28 28
29 void SetUp() override { 29 void SetUp() override {
30 test::AshTestBase::SetUp(); 30 test::AshTestBase::SetUp();
31 model_ = WmShell::Get()->shelf_model(); 31 model_ = WmShell::Get()->shelf_model();
32 } 32 }
33 33
34 void TearDown() override { 34 void TearDown() override {
35 model_ = nullptr; 35 model_ = nullptr;
36 test::AshTestBase::TearDown(); 36 test::AshTestBase::TearDown();
37 } 37 }
38 38
39 static ShelfID CreateShelfItem(WmWindow* window) { 39 static ShelfID CreateShelfItem(WmWindow* window) {
40 ShelfID id = WmShell::Get()->shelf_model()->next_id(); 40 ShelfID id = WmShell::Get()->shelf_model()->next_id();
41 window->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_DIALOG); 41 window->aura_window()->SetProperty(kShelfItemTypeKey, TYPE_DIALOG);
42 return id; 42 return id;
43 } 43 }
44 44
45 protected: 45 protected:
46 ShelfModel* model_; 46 ShelfModel* model_;
47 47
48 private: 48 private:
49 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest); 49 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest);
50 }; 50 };
51 51
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); 96 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
97 97
98 // Create a ShelfItem for the second window. 98 // Create a ShelfItem for the second window.
99 ShelfID id_w2 = CreateShelfItem(window2); 99 ShelfID id_w2 = CreateShelfItem(window2);
100 EXPECT_EQ(3, model_->item_count()); 100 EXPECT_EQ(3, model_->item_count());
101 101
102 int index_w2 = model_->ItemIndexByID(id_w2); 102 int index_w2 = model_->ItemIndexByID(id_w2);
103 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status); 103 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status);
104 104
105 // ShelfItem is removed when the item type window property is cleared. 105 // ShelfItem is removed when the item type window property is cleared.
106 window1->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_UNDEFINED); 106 window1->aura_window()->SetProperty(kShelfItemTypeKey, TYPE_UNDEFINED);
107 EXPECT_EQ(2, model_->item_count()); 107 EXPECT_EQ(2, model_->item_count());
108 window2->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_UNDEFINED); 108 window2->aura_window()->SetProperty(kShelfItemTypeKey, TYPE_UNDEFINED);
109 EXPECT_EQ(1, model_->item_count()); 109 EXPECT_EQ(1, model_->item_count());
110 // Clearing twice doesn't do anything. 110 // Clearing twice doesn't do anything.
111 window2->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_UNDEFINED); 111 window2->aura_window()->SetProperty(kShelfItemTypeKey, TYPE_UNDEFINED);
112 EXPECT_EQ(1, model_->item_count()); 112 EXPECT_EQ(1, model_->item_count());
113 } 113 }
114 114
115 TEST_F(ShelfWindowWatcherTest, ActivateWindow) { 115 TEST_F(ShelfWindowWatcherTest, ActivateWindow) {
116 // TODO: investigate failure in mash. http://crbug.com/695562. 116 // TODO: investigate failure in mash. http://crbug.com/695562.
117 if (WmShell::Get()->IsRunningInMash()) 117 if (WmShell::Get()->IsRunningInMash())
118 return; 118 return;
119 119
120 // ShelfModel only have APP_LIST item. 120 // ShelfModel only have APP_LIST item.
121 EXPECT_EQ(1, model_->item_count()); 121 EXPECT_EQ(1, model_->item_count());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get()); 163 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get());
164 164
165 // Create a ShelfItem for |window|. 165 // Create a ShelfItem for |window|.
166 ShelfID id = CreateShelfItem(window); 166 ShelfID id = CreateShelfItem(window);
167 EXPECT_EQ(2, model_->item_count()); 167 EXPECT_EQ(2, model_->item_count());
168 168
169 int index = model_->ItemIndexByID(id); 169 int index = model_->ItemIndexByID(id);
170 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status); 170 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status);
171 171
172 // Update the ShelfItemType for |window|. 172 // Update the ShelfItemType for |window|.
173 window->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_APP); 173 window->aura_window()->SetProperty(kShelfItemTypeKey, TYPE_APP);
174 // No new item is created after updating a launcher item. 174 // No new item is created after updating a launcher item.
175 EXPECT_EQ(2, model_->item_count()); 175 EXPECT_EQ(2, model_->item_count());
176 // index and id are not changed after updating a launcher item. 176 // index and id are not changed after updating a launcher item.
177 EXPECT_EQ(index, model_->ItemIndexByID(id)); 177 EXPECT_EQ(index, model_->ItemIndexByID(id));
178 EXPECT_EQ(id, model_->items()[index].id); 178 EXPECT_EQ(id, model_->items()[index].id);
179 } 179 }
180 180
181 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) { 181 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) {
182 // TODO: investigate failure in mash. http://crbug.com/695562. 182 // TODO: investigate failure in mash. http://crbug.com/695562.
183 if (WmShell::Get()->IsRunningInMash()) 183 if (WmShell::Get()->IsRunningInMash())
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 if (WmShell::Get()->IsRunningInMash()) 296 if (WmShell::Get()->IsRunningInMash())
297 return; 297 return;
298 298
299 // ShelfModel only has an APP_LIST item. 299 // ShelfModel only has an APP_LIST item.
300 EXPECT_EQ(1, model_->item_count()); 300 EXPECT_EQ(1, model_->item_count());
301 301
302 // Adding windows with valid ShelfItemType properties adds shelf items. 302 // Adding windows with valid ShelfItemType properties adds shelf items.
303 std::unique_ptr<views::Widget> widget1 = 303 std::unique_ptr<views::Widget> widget1 =
304 CreateTestWidget(nullptr, kShellWindowId_PanelContainer, gfx::Rect()); 304 CreateTestWidget(nullptr, kShellWindowId_PanelContainer, gfx::Rect());
305 WmWindow* window1 = WmLookup::Get()->GetWindowForWidget(widget1.get()); 305 WmWindow* window1 = WmLookup::Get()->GetWindowForWidget(widget1.get());
306 window1->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_APP_PANEL); 306 window1->aura_window()->SetProperty(kShelfItemTypeKey, TYPE_APP_PANEL);
307 EXPECT_EQ(2, model_->item_count()); 307 EXPECT_EQ(2, model_->item_count());
308 std::unique_ptr<views::Widget> widget2 = 308 std::unique_ptr<views::Widget> widget2 =
309 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 309 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
310 WmWindow* window2 = WmLookup::Get()->GetWindowForWidget(widget2.get()); 310 WmWindow* window2 = WmLookup::Get()->GetWindowForWidget(widget2.get());
311 window2->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_APP_PANEL); 311 window2->aura_window()->SetProperty(kShelfItemTypeKey, TYPE_APP_PANEL);
312 EXPECT_EQ(3, model_->item_count()); 312 EXPECT_EQ(3, model_->item_count());
313 313
314 // Create a panel-type widget to mimic Chrome's app panel windows. 314 // Create a panel-type widget to mimic Chrome's app panel windows.
315 views::Widget panel_widget; 315 views::Widget panel_widget;
316 views::Widget::InitParams panel_params(views::Widget::InitParams::TYPE_PANEL); 316 views::Widget::InitParams panel_params(views::Widget::InitParams::TYPE_PANEL);
317 panel_params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 317 panel_params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
318 WmShell::Get() 318 WmShell::Get()
319 ->GetPrimaryRootWindow() 319 ->GetPrimaryRootWindow()
320 ->GetRootWindowController() 320 ->GetRootWindowController()
321 ->ConfigureWidgetInitParamsForContainer( 321 ->ConfigureWidgetInitParamsForContainer(
322 &panel_widget, kShellWindowId_PanelContainer, &panel_params); 322 &panel_widget, kShellWindowId_PanelContainer, &panel_params);
323 panel_widget.Init(panel_params); 323 panel_widget.Init(panel_params);
324 panel_widget.Show(); 324 panel_widget.Show();
325 WmWindow* panel_window = WmLookup::Get()->GetWindowForWidget(&panel_widget); 325 WmWindow* panel_window = WmLookup::Get()->GetWindowForWidget(&panel_widget);
326 panel_window->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, 326 panel_window->aura_window()->SetProperty(kShelfItemTypeKey, TYPE_APP_PANEL);
327 TYPE_APP_PANEL);
328 EXPECT_EQ(4, model_->item_count()); 327 EXPECT_EQ(4, model_->item_count());
329 328
330 // Each ShelfItem is removed when the associated window is destroyed. 329 // Each ShelfItem is removed when the associated window is destroyed.
331 panel_widget.CloseNow(); 330 panel_widget.CloseNow();
332 EXPECT_EQ(3, model_->item_count()); 331 EXPECT_EQ(3, model_->item_count());
333 widget2.reset(); 332 widget2.reset();
334 EXPECT_EQ(2, model_->item_count()); 333 EXPECT_EQ(2, model_->item_count());
335 widget1.reset(); 334 widget1.reset();
336 EXPECT_EQ(1, model_->item_count()); 335 EXPECT_EQ(1, model_->item_count());
337 } 336 }
338 337
339 TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) { 338 TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) {
340 const int initial_item_count = model_->item_count(); 339 const int initial_item_count = model_->item_count();
341 340
342 WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_NORMAL, 341 WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_NORMAL,
343 ui::LAYER_NOT_DRAWN); 342 ui::LAYER_NOT_DRAWN);
344 window->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_APP); 343 window->aura_window()->SetProperty(kShelfItemTypeKey, TYPE_APP);
345 WmShell::Get() 344 WmShell::Get()
346 ->GetPrimaryRootWindow() 345 ->GetPrimaryRootWindow()
347 ->GetChildByShellWindowId(kShellWindowId_DefaultContainer) 346 ->GetChildByShellWindowId(kShellWindowId_DefaultContainer)
348 ->AddChild(window); 347 ->AddChild(window);
349 window->Show(); 348 window->Show();
350 EXPECT_EQ(initial_item_count + 1, model_->item_count()); 349 EXPECT_EQ(initial_item_count + 1, model_->item_count());
351 350
352 WmWindow* child_window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_NORMAL, 351 WmWindow* child_window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_NORMAL,
353 ui::LAYER_NOT_DRAWN); 352 ui::LAYER_NOT_DRAWN);
354 child_window->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_APP); 353 child_window->aura_window()->SetProperty(kShelfItemTypeKey, TYPE_APP);
355 window->AddChild(child_window); 354 window->AddChild(child_window);
356 child_window->Show(); 355 child_window->Show();
357 // |child_window| should not result in adding a new entry. 356 // |child_window| should not result in adding a new entry.
358 EXPECT_EQ(initial_item_count + 1, model_->item_count()); 357 EXPECT_EQ(initial_item_count + 1, model_->item_count());
359 358
360 child_window->Destroy(); 359 child_window->Destroy();
361 window->Destroy(); 360 window->Destroy();
362 EXPECT_EQ(initial_item_count, model_->item_count()); 361 EXPECT_EQ(initial_item_count, model_->item_count());
363 } 362 }
364 363
(...skipping 13 matching lines...) Expand all
378 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get()); 377 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get());
379 ShelfWindowWatcherTest::CreateShelfItem(window); 378 ShelfWindowWatcherTest::CreateShelfItem(window);
380 EXPECT_EQ(1, model->item_count()); 379 EXPECT_EQ(1, model->item_count());
381 380
382 // Start the test user session; ShelfWindowWatcher will find the open window. 381 // Start the test user session; ShelfWindowWatcher will find the open window.
383 SetSessionStarted(true); 382 SetSessionStarted(true);
384 EXPECT_EQ(2, model->item_count()); 383 EXPECT_EQ(2, model->item_count());
385 } 384 }
386 385
387 } // namespace ash 386 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698