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

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: more review comments 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
« no previous file with comments | « ui/views/mus/native_widget_mus.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/macros.h"
8 #include "components/mus/public/cpp/property_type_converters.h"
9 #include "components/mus/public/cpp/window.h"
10 #include "components/mus/public/cpp/window_property.h"
11 #include "components/mus/public/interfaces/window_manager.mojom.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "third_party/skia/include/core/SkColor.h"
15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/image/image_skia.h"
17 #include "ui/gfx/skia_util.h"
18 #include "ui/views/test/views_test_base.h"
19 #include "ui/views/widget/widget.h"
20 #include "ui/views/widget/widget_delegate.h"
21
22 namespace views {
23 namespace {
24
25 // Returns a small colored bitmap.
26 SkBitmap MakeBitmap(SkColor color) {
27 SkBitmap bitmap;
28 bitmap.allocN32Pixels(8, 8);
29 bitmap.eraseColor(color);
30 return bitmap;
31 }
32
33 // A WidgetDelegate that supplies an app icon.
34 class TestWidgetDelegate : public WidgetDelegateView {
35 public:
36 explicit TestWidgetDelegate(const SkBitmap& icon)
37 : app_icon_(gfx::ImageSkia::CreateFrom1xBitmap(icon)) {}
38
39 ~TestWidgetDelegate() override {}
40
41 void SetIcon(const SkBitmap& icon) {
42 app_icon_ = gfx::ImageSkia::CreateFrom1xBitmap(icon);
43 }
44
45 // views::WidgetDelegate:
46 gfx::ImageSkia GetWindowAppIcon() override { return app_icon_; }
47
48 private:
49 gfx::ImageSkia app_icon_;
50
51 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate);
52 };
53
54 class NativeWidgetMusTest : public ViewsTestBase {
55 public:
56 NativeWidgetMusTest() {}
57 ~NativeWidgetMusTest() override {}
58
59 // Creates a test widget. Takes ownership of |delegate|.
60 Widget* CreateWidget(TestWidgetDelegate* delegate) {
61 Widget* widget = new Widget();
62 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
63 params.delegate = delegate;
64 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
65 params.bounds = gfx::Rect(10, 20, 100, 200);
66 widget->Init(params);
67 return widget;
68 }
69
70 private:
71 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMusTest);
72 };
73
74 // Tests that a window with an icon sets the mus::Window icon property.
75 TEST_F(NativeWidgetMusTest, AppIcon) {
76 // Create a Widget with a bitmap as the icon.
77 SkBitmap source_bitmap = MakeBitmap(SK_ColorRED);
78 scoped_ptr<Widget> widget(
79 CreateWidget(new TestWidgetDelegate(source_bitmap)));
80
81 // The mus::Window has the icon property.
82 mus::Window* window =
83 static_cast<NativeWidgetMus*>(widget->native_widget_private())->window();
84 EXPECT_TRUE(window->HasSharedProperty(
85 mus::mojom::WindowManager::kWindowAppIcon_Property));
86
87 // The icon is the expected icon.
88 SkBitmap icon = window->GetSharedProperty<SkBitmap>(
89 mus::mojom::WindowManager::kWindowAppIcon_Property);
90 EXPECT_TRUE(gfx::BitmapsAreEqual(source_bitmap, icon));
91 }
92
93 // Tests that a window without an icon does not set the mus::Window icon
94 // property.
95 TEST_F(NativeWidgetMusTest, NoAppIcon) {
96 // Create a Widget without a special icon.
97 scoped_ptr<Widget> widget(CreateWidget(nullptr));
98
99 // The mus::Window does not have an icon property.
100 mus::Window* window =
101 static_cast<NativeWidgetMus*>(widget->native_widget_private())->window();
102 EXPECT_FALSE(window->HasSharedProperty(
103 mus::mojom::WindowManager::kWindowAppIcon_Property));
104 }
105
106 // Tests that changing the icon on a Widget updates the mus::Window icon
107 // property.
108 TEST_F(NativeWidgetMusTest, ChangeAppIcon) {
109 // Create a Widget with an icon.
110 SkBitmap bitmap1 = MakeBitmap(SK_ColorRED);
111 TestWidgetDelegate* delegate = new TestWidgetDelegate(bitmap1);
112 scoped_ptr<Widget> widget(CreateWidget(delegate));
113
114 // Update the icon to a new image.
115 SkBitmap bitmap2 = MakeBitmap(SK_ColorGREEN);
116 delegate->SetIcon(bitmap2);
117 widget->UpdateWindowIcon();
118
119 // The window has the updated icon.
120 mus::Window* window =
121 static_cast<NativeWidgetMus*>(widget->native_widget_private())->window();
122 SkBitmap icon = window->GetSharedProperty<SkBitmap>(
123 mus::mojom::WindowManager::kWindowAppIcon_Property);
124 EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap2, icon));
125 }
126
127 } // namespace
128 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/native_widget_mus.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698