| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 | 5 |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "services/ui/public/cpp/property_type_converters.h" | 8 #include "services/ui/public/cpp/property_type_converters.h" |
| 9 #include "services/ui/public/cpp/tests/window_tree_client_private.h" | 9 #include "services/ui/public/cpp/tests/window_tree_client_private.h" |
| 10 #include "services/ui/public/cpp/window.h" | 10 #include "services/ui/public/cpp/window.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 changes_.push_back(active); | 96 changes_.push_back(active); |
| 97 } | 97 } |
| 98 | 98 |
| 99 private: | 99 private: |
| 100 Widget* widget_; | 100 Widget* widget_; |
| 101 std::vector<bool> changes_; | 101 std::vector<bool> changes_; |
| 102 | 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(WidgetActivationObserver); | 103 DISALLOW_COPY_AND_ASSIGN(WidgetActivationObserver); |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 // A WidgetDelegate that supplies an app icon. | 106 // A WidgetDelegate that supplies app and window icons. |
| 107 class TestWidgetDelegate : public WidgetDelegateView { | 107 class TestWidgetDelegate : public WidgetDelegateView { |
| 108 public: | 108 public: |
| 109 explicit TestWidgetDelegate(const SkBitmap& icon) | 109 explicit TestWidgetDelegate(const SkBitmap& app_icon, |
| 110 : app_icon_(gfx::ImageSkia::CreateFrom1xBitmap(icon)) {} | 110 const SkBitmap& window_icon) |
| 111 : app_icon_(gfx::ImageSkia::CreateFrom1xBitmap(app_icon)), |
| 112 window_icon_(gfx::ImageSkia::CreateFrom1xBitmap(window_icon)) {} |
| 111 | 113 |
| 112 ~TestWidgetDelegate() override {} | 114 ~TestWidgetDelegate() override {} |
| 113 | 115 |
| 114 void SetIcon(const SkBitmap& icon) { | 116 void SetAppIcon(const SkBitmap& icon) { |
| 115 app_icon_ = gfx::ImageSkia::CreateFrom1xBitmap(icon); | 117 app_icon_ = gfx::ImageSkia::CreateFrom1xBitmap(icon); |
| 116 } | 118 } |
| 117 | 119 |
| 120 void SetWindowIcon(const SkBitmap& icon) { |
| 121 window_icon_ = gfx::ImageSkia::CreateFrom1xBitmap(icon); |
| 122 } |
| 123 |
| 118 // views::WidgetDelegate: | 124 // views::WidgetDelegate: |
| 119 gfx::ImageSkia GetWindowAppIcon() override { return app_icon_; } | 125 gfx::ImageSkia GetWindowAppIcon() override { return app_icon_; } |
| 126 gfx::ImageSkia GetWindowIcon() override { return window_icon_; } |
| 120 | 127 |
| 121 private: | 128 private: |
| 122 gfx::ImageSkia app_icon_; | 129 gfx::ImageSkia app_icon_; |
| 130 gfx::ImageSkia window_icon_; |
| 123 | 131 |
| 124 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate); | 132 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate); |
| 125 }; | 133 }; |
| 126 | 134 |
| 127 class WidgetDelegateWithHitTestMask : public WidgetDelegateView { | 135 class WidgetDelegateWithHitTestMask : public WidgetDelegateView { |
| 128 public: | 136 public: |
| 129 explicit WidgetDelegateWithHitTestMask(const gfx::Rect& mask_rect) | 137 explicit WidgetDelegateWithHitTestMask(const gfx::Rect& mask_rect) |
| 130 : mask_rect_(mask_rect) {} | 138 : mask_rect_(mask_rect) {} |
| 131 | 139 |
| 132 ~WidgetDelegateWithHitTestMask() override {} | 140 ~WidgetDelegateWithHitTestMask() override {} |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 widget.Init(params); | 249 widget.Init(params); |
| 242 widget.Show(); | 250 widget.Show(); |
| 243 | 251 |
| 244 // The widget is not currently active. | 252 // The widget is not currently active. |
| 245 EXPECT_FALSE(widget.IsActive()); | 253 EXPECT_FALSE(widget.IsActive()); |
| 246 | 254 |
| 247 // The widget was never active. | 255 // The widget was never active. |
| 248 EXPECT_EQ(0u, activation_observer.changes().size()); | 256 EXPECT_EQ(0u, activation_observer.changes().size()); |
| 249 } | 257 } |
| 250 | 258 |
| 251 // Tests that a window with an icon sets the ui::Window icon property. | 259 // Tests that a window with app/window icons sets ui::Window icon properties. |
| 252 TEST_F(NativeWidgetMusTest, AppIcon) { | 260 TEST_F(NativeWidgetMusTest, AppAndWindowIcons) { |
| 253 // Create a Widget with a bitmap as the icon. | 261 // Create a Widget with app and window icons. |
| 254 SkBitmap source_bitmap = MakeBitmap(SK_ColorRED); | 262 SkBitmap app_icon_input = MakeBitmap(SK_ColorRED); |
| 263 SkBitmap window_icon_input = MakeBitmap(SK_ColorGREEN); |
| 255 std::unique_ptr<Widget> widget( | 264 std::unique_ptr<Widget> widget( |
| 256 CreateWidget(new TestWidgetDelegate(source_bitmap))); | 265 CreateWidget(new TestWidgetDelegate(app_icon_input, window_icon_input))); |
| 257 | 266 |
| 258 // The ui::Window has the icon property. | 267 // The ui::Window has the expected icon properties. |
| 259 ui::Window* window = | 268 ui::Window* window = |
| 260 static_cast<NativeWidgetMus*>(widget->native_widget_private())->window(); | 269 static_cast<NativeWidgetMus*>(widget->native_widget_private())->window(); |
| 270 EXPECT_TRUE( |
| 271 window->HasSharedProperty(ui::mojom::WindowManager::kAppIcon_Property)); |
| 261 EXPECT_TRUE(window->HasSharedProperty( | 272 EXPECT_TRUE(window->HasSharedProperty( |
| 262 ui::mojom::WindowManager::kWindowAppIcon_Property)); | 273 ui::mojom::WindowManager::kWindowIcon_Property)); |
| 263 | 274 SkBitmap app_icon = window->GetSharedProperty<SkBitmap>( |
| 264 // The icon is the expected icon. | 275 ui::mojom::WindowManager::kAppIcon_Property); |
| 265 SkBitmap icon = window->GetSharedProperty<SkBitmap>( | 276 EXPECT_TRUE(gfx::BitmapsAreEqual(app_icon_input, app_icon)); |
| 266 ui::mojom::WindowManager::kWindowAppIcon_Property); | 277 SkBitmap window_icon = window->GetSharedProperty<SkBitmap>( |
| 267 EXPECT_TRUE(gfx::BitmapsAreEqual(source_bitmap, icon)); | 278 ui::mojom::WindowManager::kWindowIcon_Property); |
| 279 EXPECT_TRUE(gfx::BitmapsAreEqual(window_icon_input, window_icon)); |
| 268 } | 280 } |
| 269 | 281 |
| 270 // Tests that a window without an icon does not set the ui::Window icon | 282 // Tests that a window without icons does not set ui::Window icon properties. |
| 271 // property. | 283 TEST_F(NativeWidgetMusTest, NoAppNorWindowIcon) { |
| 272 TEST_F(NativeWidgetMusTest, NoAppIcon) { | 284 // Create a Widget without app or window icons, by supplying a null delegate. |
| 273 // Create a Widget without a special icon. | |
| 274 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); | 285 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); |
| 275 | 286 |
| 276 // The ui::Window does not have an icon property. | 287 // The ui::Window does not have either icon property. |
| 277 ui::Window* window = | 288 ui::Window* window = |
| 278 static_cast<NativeWidgetMus*>(widget->native_widget_private())->window(); | 289 static_cast<NativeWidgetMus*>(widget->native_widget_private())->window(); |
| 290 EXPECT_FALSE( |
| 291 window->HasSharedProperty(ui::mojom::WindowManager::kAppIcon_Property)); |
| 279 EXPECT_FALSE(window->HasSharedProperty( | 292 EXPECT_FALSE(window->HasSharedProperty( |
| 280 ui::mojom::WindowManager::kWindowAppIcon_Property)); | 293 ui::mojom::WindowManager::kWindowIcon_Property)); |
| 281 } | 294 } |
| 282 | 295 |
| 283 // Tests that changing the icon on a Widget updates the ui::Window icon | 296 // Tests that changing icons on a Widget updates ui::Window icon properties. |
| 284 // property. | 297 TEST_F(NativeWidgetMusTest, ChangeAppAndWindowIcons) { |
| 285 TEST_F(NativeWidgetMusTest, ChangeAppIcon) { | 298 // Create a Widget with app and window icons. |
| 286 // Create a Widget with an icon. | |
| 287 SkBitmap bitmap1 = MakeBitmap(SK_ColorRED); | 299 SkBitmap bitmap1 = MakeBitmap(SK_ColorRED); |
| 288 TestWidgetDelegate* delegate = new TestWidgetDelegate(bitmap1); | 300 TestWidgetDelegate* delegate = new TestWidgetDelegate(bitmap1, bitmap1); |
| 289 std::unique_ptr<Widget> widget(CreateWidget(delegate)); | 301 std::unique_ptr<Widget> widget(CreateWidget(delegate)); |
| 290 | |
| 291 // Update the icon to a new image. | |
| 292 SkBitmap bitmap2 = MakeBitmap(SK_ColorGREEN); | |
| 293 delegate->SetIcon(bitmap2); | |
| 294 widget->UpdateWindowIcon(); | |
| 295 | |
| 296 // The window has the updated icon. | |
| 297 ui::Window* window = | 302 ui::Window* window = |
| 298 static_cast<NativeWidgetMus*>(widget->native_widget_private())->window(); | 303 static_cast<NativeWidgetMus*>(widget->native_widget_private())->window(); |
| 299 SkBitmap icon = window->GetSharedProperty<SkBitmap>( | 304 |
| 300 ui::mojom::WindowManager::kWindowAppIcon_Property); | 305 // Update the app icon image; verify the window has the updated icon. |
| 301 EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap2, icon)); | 306 SkBitmap bitmap2 = MakeBitmap(SK_ColorGREEN); |
| 307 delegate->SetAppIcon(bitmap2); |
| 308 widget->UpdateWindowIcon(); |
| 309 SkBitmap app_icon = window->GetSharedProperty<SkBitmap>( |
| 310 ui::mojom::WindowManager::kAppIcon_Property); |
| 311 EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap2, app_icon)); |
| 312 |
| 313 // Update the window icon image; verify the window has the updated icon. |
| 314 SkBitmap bitmap3 = MakeBitmap(SK_ColorBLUE); |
| 315 delegate->SetWindowIcon(bitmap3); |
| 316 widget->UpdateWindowIcon(); |
| 317 SkBitmap window_icon = window->GetSharedProperty<SkBitmap>( |
| 318 ui::mojom::WindowManager::kWindowIcon_Property); |
| 319 EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap3, window_icon)); |
| 302 } | 320 } |
| 303 | 321 |
| 304 TEST_F(NativeWidgetMusTest, ValidLayerTree) { | 322 TEST_F(NativeWidgetMusTest, ValidLayerTree) { |
| 305 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); | 323 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); |
| 306 View* content = new View; | 324 View* content = new View; |
| 307 content->SetPaintToLayer(true); | 325 content->SetPaintToLayer(true); |
| 308 widget->GetContentsView()->AddChildView(content); | 326 widget->GetContentsView()->AddChildView(content); |
| 309 EXPECT_TRUE(widget->GetNativeWindow()->layer()->Contains(content->layer())); | 327 EXPECT_TRUE(widget->GetNativeWindow()->layer()->Contains(content->layer())); |
| 310 } | 328 } |
| 311 | 329 |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 not_child_params.name = "Not Child Widget"; | 671 not_child_params.name = "Not Child Widget"; |
| 654 not_child_params.native_widget = | 672 not_child_params.native_widget = |
| 655 new NativeWidgetMus(not_child_widget.get(), not_child_window, | 673 new NativeWidgetMus(not_child_widget.get(), not_child_window, |
| 656 ui::mojom::CompositorFrameSinkType::DEFAULT); | 674 ui::mojom::CompositorFrameSinkType::DEFAULT); |
| 657 not_child_widget->Init(not_child_params); | 675 not_child_widget->Init(not_child_params); |
| 658 | 676 |
| 659 EXPECT_NE(not_child_window->parent(), parent_window); | 677 EXPECT_NE(not_child_window->parent(), parent_window); |
| 660 } | 678 } |
| 661 | 679 |
| 662 } // namespace views | 680 } // namespace views |
| OLD | NEW |