diff options
| author | jamescook <jamescook@chromium.org> | 2016-03-25 11:11:53 -0700 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2016-03-25 18:13:27 +0000 |
| commit | cac8709a0d06fee9d9f048b9e779ce59902673a5 (patch) | |
| tree | f43374d99bd8f0310b9f26d39487b20354849678 /ui/views/mus/native_widget_mus_unittest.cc | |
| parent | 260528431247b958483c9f7f2e1c6525aba077d7 (diff) | |
| download | chromium_src-cac8709a0d06fee9d9f048b9e779ce59902673a5.zip chromium_src-cac8709a0d06fee9d9f048b9e779ce59902673a5.tar.gz chromium_src-cac8709a0d06fee9d9f048b9e779ce59902673a5.tar.bz2 | |
Mash: Show app icons in shelf based on the Widget's app icon
* Use the large icon from WidgetDelegate::GetWindowAppIcon().
* In the mojo app's NativeWidgetMus, serialize the icon's SkBitmap as a vector of bytes and set it as a shared window property.
* In the window manager, pass the serialized icon to any UserWindowObservers.
* In the system UI, deserialize the icon and use it on the shelf.
* Set an icon in task_viewer as a demonstration.
The window property serialization is handled by a custom TypeConverter for vector<uint8>, SkBitmap. In the future it would be nice to use the serialized form of the Skia Mojom struct skia.Bitmap, but that will require Mojo to generate a public API to read the serialized bytes.
Also fixed an issue where the app's primary widget and the window manager's non-client-frame widget would fight over window titles.
A screenshot of the shelf is attached to the bug.
BUG=595850
TEST=launch mash, run mojo:task_viewer, note QuickLaunch shelf icon is default but TaskViewer icon is a gear
Review URL: https://codereview.chromium.org/1824183002
Cr-Commit-Position: refs/heads/master@{#383312}
Diffstat (limited to 'ui/views/mus/native_widget_mus_unittest.cc')
| -rw-r--r-- | ui/views/mus/native_widget_mus_unittest.cc | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/ui/views/mus/native_widget_mus_unittest.cc b/ui/views/mus/native_widget_mus_unittest.cc new file mode 100644 index 0000000..a2ff4b0 --- /dev/null +++ b/ui/views/mus/native_widget_mus_unittest.cc @@ -0,0 +1,128 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/views/mus/native_widget_mus.h" + +#include "base/macros.h" +#include "components/mus/public/cpp/property_type_converters.h" +#include "components/mus/public/cpp/window.h" +#include "components/mus/public/cpp/window_property.h" +#include "components/mus/public/interfaces/window_manager.mojom.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "third_party/skia/include/core/SkColor.h" +#include "ui/gfx/geometry/rect.h" +#include "ui/gfx/image/image_skia.h" +#include "ui/gfx/skia_util.h" +#include "ui/views/test/views_test_base.h" +#include "ui/views/widget/widget.h" +#include "ui/views/widget/widget_delegate.h" + +namespace views { +namespace { + +// Returns a small colored bitmap. +SkBitmap MakeBitmap(SkColor color) { + SkBitmap bitmap; + bitmap.allocN32Pixels(8, 8); + bitmap.eraseColor(color); + return bitmap; +} + +// A WidgetDelegate that supplies an app icon. +class TestWidgetDelegate : public WidgetDelegateView { + public: + explicit TestWidgetDelegate(const SkBitmap& icon) + : app_icon_(gfx::ImageSkia::CreateFrom1xBitmap(icon)) {} + + ~TestWidgetDelegate() override {} + + void SetIcon(const SkBitmap& icon) { + app_icon_ = gfx::ImageSkia::CreateFrom1xBitmap(icon); + } + + // views::WidgetDelegate: + gfx::ImageSkia GetWindowAppIcon() override { return app_icon_; } + + private: + gfx::ImageSkia app_icon_; + + DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate); +}; + +class NativeWidgetMusTest : public ViewsTestBase { + public: + NativeWidgetMusTest() {} + ~NativeWidgetMusTest() override {} + + // Creates a test widget. Takes ownership of |delegate|. + Widget* CreateWidget(TestWidgetDelegate* delegate) { + Widget* widget = new Widget(); + Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); + params.delegate = delegate; + params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; + params.bounds = gfx::Rect(10, 20, 100, 200); + widget->Init(params); + return widget; + } + + private: + DISALLOW_COPY_AND_ASSIGN(NativeWidgetMusTest); +}; + +// Tests that a window with an icon sets the mus::Window icon property. +TEST_F(NativeWidgetMusTest, AppIcon) { + // Create a Widget with a bitmap as the icon. + SkBitmap source_bitmap = MakeBitmap(SK_ColorRED); + scoped_ptr<Widget> widget( + CreateWidget(new TestWidgetDelegate(source_bitmap))); + + // The mus::Window has the icon property. + mus::Window* window = + static_cast<NativeWidgetMus*>(widget->native_widget_private())->window(); + EXPECT_TRUE(window->HasSharedProperty( + mus::mojom::WindowManager::kWindowAppIcon_Property)); + + // The icon is the expected icon. + SkBitmap icon = window->GetSharedProperty<SkBitmap>( + mus::mojom::WindowManager::kWindowAppIcon_Property); + EXPECT_TRUE(gfx::BitmapsAreEqual(source_bitmap, icon)); +} + +// Tests that a window without an icon does not set the mus::Window icon +// property. +TEST_F(NativeWidgetMusTest, NoAppIcon) { + // Create a Widget without a special icon. + scoped_ptr<Widget> widget(CreateWidget(nullptr)); + + // The mus::Window does not have an icon property. + mus::Window* window = + static_cast<NativeWidgetMus*>(widget->native_widget_private())->window(); + EXPECT_FALSE(window->HasSharedProperty( + mus::mojom::WindowManager::kWindowAppIcon_Property)); +} + +// Tests that changing the icon on a Widget updates the mus::Window icon +// property. +TEST_F(NativeWidgetMusTest, ChangeAppIcon) { + // Create a Widget with an icon. + SkBitmap bitmap1 = MakeBitmap(SK_ColorRED); + TestWidgetDelegate* delegate = new TestWidgetDelegate(bitmap1); + scoped_ptr<Widget> widget(CreateWidget(delegate)); + + // Update the icon to a new image. + SkBitmap bitmap2 = MakeBitmap(SK_ColorGREEN); + delegate->SetIcon(bitmap2); + widget->UpdateWindowIcon(); + + // The window has the updated icon. + mus::Window* window = + static_cast<NativeWidgetMus*>(widget->native_widget_private())->window(); + SkBitmap icon = window->GetSharedProperty<SkBitmap>( + mus::mojom::WindowManager::kWindowAppIcon_Property); + EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap2, icon)); +} + +} // namespace +} // namespace views |
