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