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