| 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/config.h" |
| 8 #include "ash/public/cpp/shelf_item.h" | 8 #include "ash/public/cpp/shelf_item.h" |
| 9 #include "ash/public/cpp/shell_window_ids.h" | 9 #include "ash/public/cpp/shell_window_ids.h" |
| 10 #include "ash/public/cpp/window_properties.h" | 10 #include "ash/public/cpp/window_properties.h" |
| 11 #include "ash/root_window_controller.h" | 11 #include "ash/root_window_controller.h" |
| 12 #include "ash/session/session_controller.h" | 12 #include "ash/session/session_controller.h" |
| 13 #include "ash/shelf/shelf_model.h" | 13 #include "ash/shelf/shelf_model.h" |
| 14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 15 #include "ash/shell_port.h" | 15 #include "ash/shell_port.h" |
| 16 #include "ash/test/ash_test_base.h" | 16 #include "ash/test/ash_test_base.h" |
| 17 #include "ash/wm/window_resizer.h" | 17 #include "ash/wm/window_resizer.h" |
| 18 #include "ash/wm/window_state.h" | 18 #include "ash/wm/window_state.h" |
| 19 #include "ash/wm_window.h" | 19 #include "ash/wm_window.h" |
| 20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 21 #include "third_party/skia/include/core/SkBitmap.h" |
| 22 #include "ui/aura/client/aura_constants.h" |
| 21 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
| 22 #include "ui/base/hit_test.h" | 24 #include "ui/base/hit_test.h" |
| 25 #include "ui/gfx/image/image_skia.h" |
| 23 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 24 | 27 |
| 25 namespace ash { | 28 namespace ash { |
| 29 namespace { |
| 30 |
| 31 // Create a test 1x1 icon image with a given |color|. |
| 32 gfx::ImageSkia CreateImageSkiaIcon(SkColor color) { |
| 33 SkBitmap bitmap; |
| 34 bitmap.allocN32Pixels(1, 1); |
| 35 bitmap.eraseColor(color); |
| 36 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 37 } |
| 26 | 38 |
| 27 class ShelfWindowWatcherTest : public test::AshTestBase { | 39 class ShelfWindowWatcherTest : public test::AshTestBase { |
| 28 public: | 40 public: |
| 29 ShelfWindowWatcherTest() : model_(nullptr) {} | 41 ShelfWindowWatcherTest() : model_(nullptr) {} |
| 30 ~ShelfWindowWatcherTest() override {} | 42 ~ShelfWindowWatcherTest() override {} |
| 31 | 43 |
| 32 void SetUp() override { | 44 void SetUp() override { |
| 33 test::AshTestBase::SetUp(); | 45 test::AshTestBase::SetUp(); |
| 34 model_ = Shell::Get()->shelf_model(); | 46 model_ = Shell::Get()->shelf_model(); |
| 35 } | 47 } |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 | 307 |
| 296 // Each ShelfItem is removed when the associated window is destroyed. | 308 // Each ShelfItem is removed when the associated window is destroyed. |
| 297 panel_widget.CloseNow(); | 309 panel_widget.CloseNow(); |
| 298 EXPECT_EQ(3, model_->item_count()); | 310 EXPECT_EQ(3, model_->item_count()); |
| 299 widget2.reset(); | 311 widget2.reset(); |
| 300 EXPECT_EQ(2, model_->item_count()); | 312 EXPECT_EQ(2, model_->item_count()); |
| 301 widget1.reset(); | 313 widget1.reset(); |
| 302 EXPECT_EQ(1, model_->item_count()); | 314 EXPECT_EQ(1, model_->item_count()); |
| 303 } | 315 } |
| 304 | 316 |
| 317 // Ensure items icons use the app icon and window icon aura::Window properties. |
| 318 TEST_F(ShelfWindowWatcherTest, ItemIcon) { |
| 319 // ShelfModel only has an APP_LIST item. |
| 320 EXPECT_EQ(1, model_->item_count()); |
| 321 |
| 322 // Create a ShelfItem for a window; it should have an empty icon. |
| 323 std::unique_ptr<views::Widget> widget = |
| 324 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); |
| 325 aura::Window* window = widget->GetNativeWindow(); |
| 326 ShelfID id = CreateShelfItem(window); |
| 327 EXPECT_EQ(2, model_->item_count()); |
| 328 |
| 329 // Setting a window icon should update the item icon. |
| 330 const gfx::ImageSkia red = CreateImageSkiaIcon(SK_ColorRED); |
| 331 window->SetProperty(aura::client::kWindowIconKey, new gfx::ImageSkia(red)); |
| 332 EXPECT_EQ(SK_ColorRED, model_->items()[1].image.bitmap()->getColor(0, 0)); |
| 333 |
| 334 // Setting an app icon should override the window icon. |
| 335 const gfx::ImageSkia blue = CreateImageSkiaIcon(SK_ColorBLUE); |
| 336 window->SetProperty(aura::client::kAppIconKey, new gfx::ImageSkia(blue)); |
| 337 EXPECT_EQ(SK_ColorBLUE, model_->items()[1].image.bitmap()->getColor(0, 0)); |
| 338 |
| 339 // Clearing the app icon should restore the window icon to the shelf item. |
| 340 window->ClearProperty(aura::client::kAppIconKey); |
| 341 EXPECT_EQ(SK_ColorRED, model_->items()[1].image.bitmap()->getColor(0, 0)); |
| 342 } |
| 343 |
| 305 TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) { | 344 TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) { |
| 306 const int initial_item_count = model_->item_count(); | 345 const int initial_item_count = model_->item_count(); |
| 307 | 346 |
| 308 std::unique_ptr<aura::Window> window(base::MakeUnique<aura::Window>( | 347 std::unique_ptr<aura::Window> window(base::MakeUnique<aura::Window>( |
| 309 nullptr, aura::client::WINDOW_TYPE_NORMAL)); | 348 nullptr, aura::client::WINDOW_TYPE_NORMAL)); |
| 310 window->Init(ui::LAYER_NOT_DRAWN); | 349 window->Init(ui::LAYER_NOT_DRAWN); |
| 311 window->SetProperty(kShelfIDKey, new std::string(ShelfID("foo").Serialize())); | 350 window->SetProperty(kShelfIDKey, new std::string(ShelfID("foo").Serialize())); |
| 312 window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP)); | 351 window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP)); |
| 313 Shell::GetPrimaryRootWindow() | 352 Shell::GetPrimaryRootWindow() |
| 314 ->GetChildById(kShellWindowId_DefaultContainer) | 353 ->GetChildById(kShellWindowId_DefaultContainer) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 344 std::unique_ptr<views::Widget> widget = | 383 std::unique_ptr<views::Widget> widget = |
| 345 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | 384 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); |
| 346 ShelfWindowWatcherTest::CreateShelfItem(widget->GetNativeWindow()); | 385 ShelfWindowWatcherTest::CreateShelfItem(widget->GetNativeWindow()); |
| 347 EXPECT_EQ(1, model->item_count()); | 386 EXPECT_EQ(1, model->item_count()); |
| 348 | 387 |
| 349 // Start the test user session; ShelfWindowWatcher will find the open window. | 388 // Start the test user session; ShelfWindowWatcher will find the open window. |
| 350 SetSessionStarted(true); | 389 SetSessionStarted(true); |
| 351 EXPECT_EQ(2, model->item_count()); | 390 EXPECT_EQ(2, model->item_count()); |
| 352 } | 391 } |
| 353 | 392 |
| 393 } // namespace |
| 354 } // namespace ash | 394 } // namespace ash |
| OLD | NEW |