| 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/shelf/shelf_window_watcher.h" | 5 #include "ash/shelf/shelf_window_watcher.h" |
| 6 | 6 |
| 7 #include "ash/public/cpp/shelf_item.h" | 7 #include "ash/public/cpp/shelf_item.h" |
| 8 #include "ash/public/cpp/shell_window_ids.h" | 8 #include "ash/public/cpp/shell_window_ids.h" |
| 9 #include "ash/public/cpp/window_properties.h" | 9 #include "ash/public/cpp/window_properties.h" |
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| 11 #include "ash/session/session_controller.h" | 11 #include "ash/session/session_controller.h" |
| 12 #include "ash/shelf/shelf_model.h" | 12 #include "ash/shelf/shelf_model.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/shell_port.h" |
| 14 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
| 15 #include "ash/wm/window_resizer.h" | 16 #include "ash/wm/window_resizer.h" |
| 16 #include "ash/wm/window_state.h" | 17 #include "ash/wm/window_state.h" |
| 17 #include "ash/wm_shell.h" | |
| 18 #include "ash/wm_window.h" | 18 #include "ash/wm_window.h" |
| 19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 20 #include "ui/base/hit_test.h" | 20 #include "ui/base/hit_test.h" |
| 21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 22 | 22 |
| 23 namespace ash { | 23 namespace ash { |
| 24 | 24 |
| 25 class ShelfWindowWatcherTest : public test::AshTestBase { | 25 class ShelfWindowWatcherTest : public test::AshTestBase { |
| 26 public: | 26 public: |
| 27 ShelfWindowWatcherTest() : model_(nullptr) {} | 27 ShelfWindowWatcherTest() : model_(nullptr) {} |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 // Each ShelfItem is removed when the associated window is destroyed. | 69 // Each ShelfItem is removed when the associated window is destroyed. |
| 70 widget1.reset(); | 70 widget1.reset(); |
| 71 EXPECT_EQ(2, model_->item_count()); | 71 EXPECT_EQ(2, model_->item_count()); |
| 72 widget2.reset(); | 72 widget2.reset(); |
| 73 EXPECT_EQ(1, model_->item_count()); | 73 EXPECT_EQ(1, model_->item_count()); |
| 74 } | 74 } |
| 75 | 75 |
| 76 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveShelfItemProperties) { | 76 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveShelfItemProperties) { |
| 77 // TODO: investigate failure in mash. http://crbug.com/695562. | 77 // TODO: investigate failure in mash. http://crbug.com/695562. |
| 78 if (WmShell::Get()->IsRunningInMash()) | 78 if (ShellPort::Get()->IsRunningInMash()) |
| 79 return; | 79 return; |
| 80 | 80 |
| 81 // ShelfModel only has an APP_LIST item. | 81 // ShelfModel only has an APP_LIST item. |
| 82 EXPECT_EQ(1, model_->item_count()); | 82 EXPECT_EQ(1, model_->item_count()); |
| 83 | 83 |
| 84 // Creating windows without a valid ShelfItemType does not add items. | 84 // Creating windows without a valid ShelfItemType does not add items. |
| 85 std::unique_ptr<views::Widget> widget1 = | 85 std::unique_ptr<views::Widget> widget1 = |
| 86 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | 86 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); |
| 87 WmWindow* window1 = WmWindow::Get(widget1->GetNativeWindow()); | 87 WmWindow* window1 = WmWindow::Get(widget1->GetNativeWindow()); |
| 88 std::unique_ptr<views::Widget> widget2 = | 88 std::unique_ptr<views::Widget> widget2 = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 112 static_cast<int32_t>(TYPE_UNDEFINED)); | 112 static_cast<int32_t>(TYPE_UNDEFINED)); |
| 113 EXPECT_EQ(1, model_->item_count()); | 113 EXPECT_EQ(1, model_->item_count()); |
| 114 // Clearing twice doesn't do anything. | 114 // Clearing twice doesn't do anything. |
| 115 window2->aura_window()->SetProperty(kShelfItemTypeKey, | 115 window2->aura_window()->SetProperty(kShelfItemTypeKey, |
| 116 static_cast<int32_t>(TYPE_UNDEFINED)); | 116 static_cast<int32_t>(TYPE_UNDEFINED)); |
| 117 EXPECT_EQ(1, model_->item_count()); | 117 EXPECT_EQ(1, model_->item_count()); |
| 118 } | 118 } |
| 119 | 119 |
| 120 TEST_F(ShelfWindowWatcherTest, ActivateWindow) { | 120 TEST_F(ShelfWindowWatcherTest, ActivateWindow) { |
| 121 // TODO: investigate failure in mash. http://crbug.com/695562. | 121 // TODO: investigate failure in mash. http://crbug.com/695562. |
| 122 if (WmShell::Get()->IsRunningInMash()) | 122 if (ShellPort::Get()->IsRunningInMash()) |
| 123 return; | 123 return; |
| 124 | 124 |
| 125 // ShelfModel only have APP_LIST item. | 125 // ShelfModel only have APP_LIST item. |
| 126 EXPECT_EQ(1, model_->item_count()); | 126 EXPECT_EQ(1, model_->item_count()); |
| 127 std::unique_ptr<views::Widget> widget1 = | 127 std::unique_ptr<views::Widget> widget1 = |
| 128 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | 128 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); |
| 129 WmWindow* window1 = WmWindow::Get(widget1->GetNativeWindow()); | 129 WmWindow* window1 = WmWindow::Get(widget1->GetNativeWindow()); |
| 130 std::unique_ptr<views::Widget> widget2 = | 130 std::unique_ptr<views::Widget> widget2 = |
| 131 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | 131 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); |
| 132 WmWindow* window2 = WmWindow::Get(widget2->GetNativeWindow()); | 132 WmWindow* window2 = WmWindow::Get(widget2->GetNativeWindow()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 150 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status); | 150 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status); |
| 151 | 151 |
| 152 // 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. |
| 153 widget2->Activate(); | 153 widget2->Activate(); |
| 154 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); | 154 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); |
| 155 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status); | 155 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status); |
| 156 } | 156 } |
| 157 | 157 |
| 158 TEST_F(ShelfWindowWatcherTest, UpdateWindowProperty) { | 158 TEST_F(ShelfWindowWatcherTest, UpdateWindowProperty) { |
| 159 // TODO: investigate failure in mash. http://crbug.com/695562. | 159 // TODO: investigate failure in mash. http://crbug.com/695562. |
| 160 if (WmShell::Get()->IsRunningInMash()) | 160 if (ShellPort::Get()->IsRunningInMash()) |
| 161 return; | 161 return; |
| 162 | 162 |
| 163 // ShelfModel only has an APP_LIST item. | 163 // ShelfModel only has an APP_LIST item. |
| 164 EXPECT_EQ(1, model_->item_count()); | 164 EXPECT_EQ(1, model_->item_count()); |
| 165 | 165 |
| 166 std::unique_ptr<views::Widget> widget = | 166 std::unique_ptr<views::Widget> widget = |
| 167 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | 167 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); |
| 168 WmWindow* window = WmWindow::Get(widget->GetNativeWindow()); | 168 WmWindow* window = WmWindow::Get(widget->GetNativeWindow()); |
| 169 | 169 |
| 170 // Create a ShelfItem for |window|. | 170 // Create a ShelfItem for |window|. |
| 171 ShelfID id = CreateShelfItem(window); | 171 ShelfID id = CreateShelfItem(window); |
| 172 EXPECT_EQ(2, model_->item_count()); | 172 EXPECT_EQ(2, model_->item_count()); |
| 173 | 173 |
| 174 int index = model_->ItemIndexByID(id); | 174 int index = model_->ItemIndexByID(id); |
| 175 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status); | 175 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status); |
| 176 | 176 |
| 177 // Update the ShelfItemType for |window|. | 177 // Update the ShelfItemType for |window|. |
| 178 window->aura_window()->SetProperty(kShelfItemTypeKey, | 178 window->aura_window()->SetProperty(kShelfItemTypeKey, |
| 179 static_cast<int32_t>(TYPE_APP)); | 179 static_cast<int32_t>(TYPE_APP)); |
| 180 // No new item is created after updating a launcher item. | 180 // No new item is created after updating a launcher item. |
| 181 EXPECT_EQ(2, model_->item_count()); | 181 EXPECT_EQ(2, model_->item_count()); |
| 182 // index and id are not changed after updating a launcher item. | 182 // index and id are not changed after updating a launcher item. |
| 183 EXPECT_EQ(index, model_->ItemIndexByID(id)); | 183 EXPECT_EQ(index, model_->ItemIndexByID(id)); |
| 184 EXPECT_EQ(id, model_->items()[index].id); | 184 EXPECT_EQ(id, model_->items()[index].id); |
| 185 } | 185 } |
| 186 | 186 |
| 187 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) { | 187 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) { |
| 188 // TODO: investigate failure in mash. http://crbug.com/695562. | 188 // TODO: investigate failure in mash. http://crbug.com/695562. |
| 189 if (WmShell::Get()->IsRunningInMash()) | 189 if (ShellPort::Get()->IsRunningInMash()) |
| 190 return; | 190 return; |
| 191 | 191 |
| 192 // ShelfModel only has an APP_LIST item. | 192 // ShelfModel only has an APP_LIST item. |
| 193 EXPECT_EQ(1, model_->item_count()); | 193 EXPECT_EQ(1, model_->item_count()); |
| 194 | 194 |
| 195 std::unique_ptr<views::Widget> widget = | 195 std::unique_ptr<views::Widget> widget = |
| 196 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | 196 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); |
| 197 WmWindow* window = WmWindow::Get(widget->GetNativeWindow()); | 197 WmWindow* window = WmWindow::Get(widget->GetNativeWindow()); |
| 198 wm::WindowState* window_state = window->GetWindowState(); | 198 wm::WindowState* window_state = window->GetWindowState(); |
| 199 | 199 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 221 EXPECT_EQ(2, model_->item_count()); | 221 EXPECT_EQ(2, model_->item_count()); |
| 222 // Index and id are not changed after maximizing a window |window|. | 222 // Index and id are not changed after maximizing a window |window|. |
| 223 EXPECT_EQ(index, model_->ItemIndexByID(id)); | 223 EXPECT_EQ(index, model_->ItemIndexByID(id)); |
| 224 EXPECT_EQ(id, model_->items()[index].id); | 224 EXPECT_EQ(id, model_->items()[index].id); |
| 225 } | 225 } |
| 226 | 226 |
| 227 // Check |window|'s item is not changed during the dragging. | 227 // Check |window|'s item is not changed during the dragging. |
| 228 // TODO(simonhong): Add a test for removing a Window during the dragging. | 228 // TODO(simonhong): Add a test for removing a Window during the dragging. |
| 229 TEST_F(ShelfWindowWatcherTest, DragWindow) { | 229 TEST_F(ShelfWindowWatcherTest, DragWindow) { |
| 230 // TODO: investigate failure in mash. http://crbug.com/695562. | 230 // TODO: investigate failure in mash. http://crbug.com/695562. |
| 231 if (WmShell::Get()->IsRunningInMash()) | 231 if (ShellPort::Get()->IsRunningInMash()) |
| 232 return; | 232 return; |
| 233 | 233 |
| 234 // ShelfModel only has an APP_LIST item. | 234 // ShelfModel only has an APP_LIST item. |
| 235 EXPECT_EQ(1, model_->item_count()); | 235 EXPECT_EQ(1, model_->item_count()); |
| 236 | 236 |
| 237 std::unique_ptr<views::Widget> widget = | 237 std::unique_ptr<views::Widget> widget = |
| 238 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | 238 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); |
| 239 WmWindow* window = WmWindow::Get(widget->GetNativeWindow()); | 239 WmWindow* window = WmWindow::Get(widget->GetNativeWindow()); |
| 240 | 240 |
| 241 // Create a ShelfItem for |window|. | 241 // Create a ShelfItem for |window|. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 253 resizer->CompleteDrag(); | 253 resizer->CompleteDrag(); |
| 254 | 254 |
| 255 // Index and id are not changed after dragging a |window|. | 255 // Index and id are not changed after dragging a |window|. |
| 256 EXPECT_EQ(index, model_->ItemIndexByID(id)); | 256 EXPECT_EQ(index, model_->ItemIndexByID(id)); |
| 257 EXPECT_EQ(id, model_->items()[index].id); | 257 EXPECT_EQ(id, model_->items()[index].id); |
| 258 } | 258 } |
| 259 | 259 |
| 260 // Ensure shelf items are added and removed as panels are opened and closed. | 260 // Ensure shelf items are added and removed as panels are opened and closed. |
| 261 TEST_F(ShelfWindowWatcherTest, PanelWindow) { | 261 TEST_F(ShelfWindowWatcherTest, PanelWindow) { |
| 262 // TODO: investigate failure in mash. http://crbug.com/695562. | 262 // TODO: investigate failure in mash. http://crbug.com/695562. |
| 263 if (WmShell::Get()->IsRunningInMash()) | 263 if (ShellPort::Get()->IsRunningInMash()) |
| 264 return; | 264 return; |
| 265 | 265 |
| 266 // ShelfModel only has an APP_LIST item. | 266 // ShelfModel only has an APP_LIST item. |
| 267 EXPECT_EQ(1, model_->item_count()); | 267 EXPECT_EQ(1, model_->item_count()); |
| 268 | 268 |
| 269 // Adding windows with valid ShelfItemType properties adds shelf items. | 269 // Adding windows with valid ShelfItemType properties adds shelf items. |
| 270 std::unique_ptr<views::Widget> widget1 = | 270 std::unique_ptr<views::Widget> widget1 = |
| 271 CreateTestWidget(nullptr, kShellWindowId_PanelContainer, gfx::Rect()); | 271 CreateTestWidget(nullptr, kShellWindowId_PanelContainer, gfx::Rect()); |
| 272 WmWindow* window1 = WmWindow::Get(widget1->GetNativeWindow()); | 272 WmWindow* window1 = WmWindow::Get(widget1->GetNativeWindow()); |
| 273 window1->aura_window()->SetProperty(kShelfItemTypeKey, | 273 window1->aura_window()->SetProperty(kShelfItemTypeKey, |
| 274 static_cast<int32_t>(TYPE_APP_PANEL)); | 274 static_cast<int32_t>(TYPE_APP_PANEL)); |
| 275 EXPECT_EQ(2, model_->item_count()); | 275 EXPECT_EQ(2, model_->item_count()); |
| 276 std::unique_ptr<views::Widget> widget2 = | 276 std::unique_ptr<views::Widget> widget2 = |
| 277 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | 277 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); |
| 278 WmWindow* window2 = WmWindow::Get(widget2->GetNativeWindow()); | 278 WmWindow* window2 = WmWindow::Get(widget2->GetNativeWindow()); |
| 279 window2->aura_window()->SetProperty(kShelfItemTypeKey, | 279 window2->aura_window()->SetProperty(kShelfItemTypeKey, |
| 280 static_cast<int32_t>(TYPE_APP_PANEL)); | 280 static_cast<int32_t>(TYPE_APP_PANEL)); |
| 281 EXPECT_EQ(3, model_->item_count()); | 281 EXPECT_EQ(3, model_->item_count()); |
| 282 | 282 |
| 283 // Create a panel-type widget to mimic Chrome's app panel windows. | 283 // Create a panel-type widget to mimic Chrome's app panel windows. |
| 284 views::Widget panel_widget; | 284 views::Widget panel_widget; |
| 285 views::Widget::InitParams panel_params(views::Widget::InitParams::TYPE_PANEL); | 285 views::Widget::InitParams panel_params(views::Widget::InitParams::TYPE_PANEL); |
| 286 panel_params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 286 panel_params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 287 WmShell::Get() | 287 ShellPort::Get() |
| 288 ->GetPrimaryRootWindow() | 288 ->GetPrimaryRootWindow() |
| 289 ->GetRootWindowController() | 289 ->GetRootWindowController() |
| 290 ->ConfigureWidgetInitParamsForContainer( | 290 ->ConfigureWidgetInitParamsForContainer( |
| 291 &panel_widget, kShellWindowId_PanelContainer, &panel_params); | 291 &panel_widget, kShellWindowId_PanelContainer, &panel_params); |
| 292 panel_widget.Init(panel_params); | 292 panel_widget.Init(panel_params); |
| 293 panel_widget.Show(); | 293 panel_widget.Show(); |
| 294 WmWindow* panel_window = WmWindow::Get(panel_widget.GetNativeWindow()); | 294 WmWindow* panel_window = WmWindow::Get(panel_widget.GetNativeWindow()); |
| 295 panel_window->aura_window()->SetProperty( | 295 panel_window->aura_window()->SetProperty( |
| 296 kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP_PANEL)); | 296 kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP_PANEL)); |
| 297 EXPECT_EQ(4, model_->item_count()); | 297 EXPECT_EQ(4, model_->item_count()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 WmWindow* window = WmWindow::Get(widget->GetNativeWindow()); | 348 WmWindow* window = WmWindow::Get(widget->GetNativeWindow()); |
| 349 ShelfWindowWatcherTest::CreateShelfItem(window); | 349 ShelfWindowWatcherTest::CreateShelfItem(window); |
| 350 EXPECT_EQ(1, model->item_count()); | 350 EXPECT_EQ(1, model->item_count()); |
| 351 | 351 |
| 352 // Start the test user session; ShelfWindowWatcher will find the open window. | 352 // Start the test user session; ShelfWindowWatcher will find the open window. |
| 353 SetSessionStarted(true); | 353 SetSessionStarted(true); |
| 354 EXPECT_EQ(2, model->item_count()); | 354 EXPECT_EQ(2, model->item_count()); |
| 355 } | 355 } |
| 356 | 356 |
| 357 } // namespace ash | 357 } // namespace ash |
| OLD | NEW |