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