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/base/resource/resource_bundle.h" |
| 25 #include "ui/gfx/image/image_skia.h" |
| 26 #include "ui/resources/grit/ui_resources.h" |
22 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
23 | 28 |
24 namespace ash { | 29 namespace ash { |
| 30 namespace { |
| 31 |
| 32 // Create a test 1x1 icon image with a given |color|. |
| 33 gfx::ImageSkia CreateImageSkiaIcon(SkColor color) { |
| 34 SkBitmap bitmap; |
| 35 bitmap.allocN32Pixels(1, 1); |
| 36 bitmap.eraseColor(color); |
| 37 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 38 } |
25 | 39 |
26 class ShelfWindowWatcherTest : public test::AshTestBase { | 40 class ShelfWindowWatcherTest : public test::AshTestBase { |
27 public: | 41 public: |
28 ShelfWindowWatcherTest() : model_(nullptr) {} | 42 ShelfWindowWatcherTest() : model_(nullptr) {} |
29 ~ShelfWindowWatcherTest() override {} | 43 ~ShelfWindowWatcherTest() override {} |
30 | 44 |
31 void SetUp() override { | 45 void SetUp() override { |
32 test::AshTestBase::SetUp(); | 46 test::AshTestBase::SetUp(); |
33 model_ = Shell::Get()->shelf_model(); | 47 model_ = Shell::Get()->shelf_model(); |
34 } | 48 } |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 308 |
295 // Each ShelfItem is removed when the associated window is destroyed. | 309 // Each ShelfItem is removed when the associated window is destroyed. |
296 panel_widget.CloseNow(); | 310 panel_widget.CloseNow(); |
297 EXPECT_EQ(3, model_->item_count()); | 311 EXPECT_EQ(3, model_->item_count()); |
298 widget2.reset(); | 312 widget2.reset(); |
299 EXPECT_EQ(2, model_->item_count()); | 313 EXPECT_EQ(2, model_->item_count()); |
300 widget1.reset(); | 314 widget1.reset(); |
301 EXPECT_EQ(1, model_->item_count()); | 315 EXPECT_EQ(1, model_->item_count()); |
302 } | 316 } |
303 | 317 |
| 318 // Ensure items use the app icon and window icon aura::Window properties. |
| 319 TEST_F(ShelfWindowWatcherTest, ItemIcon) { |
| 320 // ShelfModel only has an APP_LIST item. |
| 321 EXPECT_EQ(1, model_->item_count()); |
| 322 |
| 323 // Create a ShelfItem for a window; it should have a default icon. |
| 324 std::unique_ptr<views::Widget> widget = |
| 325 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); |
| 326 aura::Window* window = widget->GetNativeWindow(); |
| 327 ShelfID id = CreateShelfItem(window); |
| 328 EXPECT_EQ(2, model_->item_count()); |
| 329 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 330 gfx::Image default_image = rb.GetImageNamed(IDR_DEFAULT_FAVICON_32); |
| 331 EXPECT_TRUE(model_->items()[1].image.BackedBySameObjectAs( |
| 332 default_image.AsImageSkia())); |
| 333 |
| 334 // Setting a window icon should update the item icon. |
| 335 const gfx::ImageSkia red = CreateImageSkiaIcon(SK_ColorRED); |
| 336 window->SetProperty(aura::client::kWindowIconKey, new gfx::ImageSkia(red)); |
| 337 EXPECT_EQ(SK_ColorRED, model_->items()[1].image.bitmap()->getColor(0, 0)); |
| 338 |
| 339 // Setting an app icon should override the window icon. |
| 340 const gfx::ImageSkia blue = CreateImageSkiaIcon(SK_ColorBLUE); |
| 341 window->SetProperty(aura::client::kAppIconKey, new gfx::ImageSkia(blue)); |
| 342 EXPECT_EQ(SK_ColorBLUE, model_->items()[1].image.bitmap()->getColor(0, 0)); |
| 343 |
| 344 // Clearing the app icon should restore the window icon to the shelf item. |
| 345 window->ClearProperty(aura::client::kAppIconKey); |
| 346 EXPECT_EQ(SK_ColorRED, model_->items()[1].image.bitmap()->getColor(0, 0)); |
| 347 } |
| 348 |
304 TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) { | 349 TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) { |
305 const int initial_item_count = model_->item_count(); | 350 const int initial_item_count = model_->item_count(); |
306 | 351 |
307 std::unique_ptr<aura::Window> window(base::MakeUnique<aura::Window>( | 352 std::unique_ptr<aura::Window> window(base::MakeUnique<aura::Window>( |
308 nullptr, aura::client::WINDOW_TYPE_NORMAL)); | 353 nullptr, aura::client::WINDOW_TYPE_NORMAL)); |
309 window->Init(ui::LAYER_NOT_DRAWN); | 354 window->Init(ui::LAYER_NOT_DRAWN); |
310 window->SetProperty(kShelfIDKey, new std::string(ShelfID("foo").Serialize())); | 355 window->SetProperty(kShelfIDKey, new std::string(ShelfID("foo").Serialize())); |
311 window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP)); | 356 window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP)); |
312 Shell::GetPrimaryRootWindow() | 357 Shell::GetPrimaryRootWindow() |
313 ->GetChildById(kShellWindowId_DefaultContainer) | 358 ->GetChildById(kShellWindowId_DefaultContainer) |
(...skipping 29 matching lines...) Expand all Loading... |
343 std::unique_ptr<views::Widget> widget = | 388 std::unique_ptr<views::Widget> widget = |
344 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | 389 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); |
345 ShelfWindowWatcherTest::CreateShelfItem(widget->GetNativeWindow()); | 390 ShelfWindowWatcherTest::CreateShelfItem(widget->GetNativeWindow()); |
346 EXPECT_EQ(1, model->item_count()); | 391 EXPECT_EQ(1, model->item_count()); |
347 | 392 |
348 // Start the test user session; ShelfWindowWatcher will find the open window. | 393 // Start the test user session; ShelfWindowWatcher will find the open window. |
349 SetSessionStarted(true); | 394 SetSessionStarted(true); |
350 EXPECT_EQ(2, model->item_count()); | 395 EXPECT_EQ(2, model->item_count()); |
351 } | 396 } |
352 | 397 |
| 398 } // namespace |
353 } // namespace ash | 399 } // namespace ash |
OLD | NEW |