Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: ui/views/mus/native_widget_mus_unittest.cc

Issue 1824183002: Mash: Show app icons in shelf based on the Widget's app icon (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added unit tests Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/views/mus/native_widget_mus.h"
6
7 #include "components/mus/public/cpp/property_type_converters.h"
8 #include "components/mus/public/cpp/window.h"
9 #include "components/mus/public/cpp/window_property.h"
10 #include "components/mus/public/interfaces/window_manager.mojom.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "third_party/skia/include/core/SkColor.h"
14 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/image/image_skia.h"
16 #include "ui/gfx/skia_util.h"
17 #include "ui/views/test/views_test_base.h"
18 #include "ui/views/widget/widget.h"
19 #include "ui/views/widget/widget_delegate.h"
20
21 namespace views {
22 namespace {
23
24 // Returns a small colored bitmap.
25 SkBitmap MakeBitmap(SkColor color) {
26 SkBitmap bitmap;
27 bitmap.allocN32Pixels(8, 8);
28 bitmap.eraseColor(color);
29 return bitmap;
30 }
31
32 // A WidgetDelegate that supplies an app icon.
33 class TestWidgetDelegate : public WidgetDelegateView {
34 public:
35 explicit TestWidgetDelegate(const SkBitmap& icon)
36 : app_icon_(gfx::ImageSkia::CreateFrom1xBitmap(icon)) {}
37
38 ~TestWidgetDelegate() override {}
39
40 void SetIcon(const SkBitmap& icon) {
41 app_icon_ = gfx::ImageSkia::CreateFrom1xBitmap(icon);
42 }
43
44 // views::WidgetDelegate:
45 gfx::ImageSkia GetWindowAppIcon() override { return app_icon_; }
46
47 private:
48 gfx::ImageSkia app_icon_;
49 };
50
51 class NativeWidgetMusTest : public ViewsTestBase {
52 public:
53 NativeWidgetMusTest() {}
54 ~NativeWidgetMusTest() override {}
55
56 // Creates a test widget. Takes ownership of |delegate|.
57 Widget* CreateWidget(TestWidgetDelegate* delegate) {
58 Widget* widget = new Widget();
59 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
60 params.delegate = delegate;
61 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
62 params.bounds = gfx::Rect(10, 20, 100, 200);
63 widget->Init(params);
64 return widget;
65 }
66 };
sky 2016/03/25 15:56:34 nit: private: DISALLOW...
James Cook 2016/03/25 16:52:39 Done.
67
68 // Tests that a window with an icon sets the mus::Window icon property.
69 TEST_F(NativeWidgetMusTest, AppIcon) {
70 // Create a Widget with a bitmap as the icon.
71 SkBitmap source_bitmap = MakeBitmap(SK_ColorRED);
72 scoped_ptr<Widget> widget(
73 CreateWidget(new TestWidgetDelegate(source_bitmap)));
74
75 // The mus::Window has the icon property.
76 mus::Window* window =
77 static_cast<NativeWidgetMus*>(widget->native_widget_private())->window();
78 EXPECT_TRUE(window->HasSharedProperty(
79 mus::mojom::WindowManager::kWindowAppIcon_Property));
80
81 // The icon is the expected icon.
82 SkBitmap icon = window->GetSharedProperty<SkBitmap>(
83 mus::mojom::WindowManager::kWindowAppIcon_Property);
84 EXPECT_TRUE(gfx::BitmapsAreEqual(source_bitmap, icon));
85 }
86
87 // Tests that a window without an icon does not set the mus::Window icon
88 // property.
89 TEST_F(NativeWidgetMusTest, NoAppIcon) {
90 // Create a Widget without a special icon.
91 scoped_ptr<Widget> widget(CreateWidget(nullptr));
92
93 // The mus::Window does not have an icon property.
94 mus::Window* window =
95 static_cast<NativeWidgetMus*>(widget->native_widget_private())->window();
96 EXPECT_FALSE(window->HasSharedProperty(
97 mus::mojom::WindowManager::kWindowAppIcon_Property));
98 }
99
100 // Tests that changing the icon on a Widget updates the mus::Window icon
101 // property.
102 TEST_F(NativeWidgetMusTest, ChangeAppIcon) {
103 // Create a Widget with an icon.
104 SkBitmap bitmap1 = MakeBitmap(SK_ColorRED);
105 TestWidgetDelegate* delegate = new TestWidgetDelegate(bitmap1);
106 scoped_ptr<Widget> widget(CreateWidget(delegate));
107
108 // Update the icon to a new image.
109 SkBitmap bitmap2 = MakeBitmap(SK_ColorGREEN);
110 delegate->SetIcon(bitmap2);
111 widget->UpdateWindowIcon();
112
113 // The window has the updated icon.
114 mus::Window* window =
115 static_cast<NativeWidgetMus*>(widget->native_widget_private())->window();
116 SkBitmap icon = window->GetSharedProperty<SkBitmap>(
117 mus::mojom::WindowManager::kWindowAppIcon_Property);
118 EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap2, icon));
119 }
120
121 } // namespace
122 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698