| 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 #include "ui/views/mus/native_widget_mus.h" | 5 #include "ui/views/mus/native_widget_mus.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "services/ui/public/cpp/property_type_converters.h" | 9 #include "services/ui/public/cpp/property_type_converters.h" |
| 10 #include "services/ui/public/cpp/tests/window_tree_client_private.h" | 10 #include "services/ui/public/cpp/tests/window_tree_client_private.h" |
| 11 #include "services/ui/public/cpp/window.h" | 11 #include "services/ui/public/cpp/window.h" |
| 12 #include "services/ui/public/cpp/window_observer.h" |
| 12 #include "services/ui/public/cpp/window_property.h" | 13 #include "services/ui/public/cpp/window_property.h" |
| 13 #include "services/ui/public/cpp/window_tree_client.h" | 14 #include "services/ui/public/cpp/window_tree_client.h" |
| 14 #include "services/ui/public/interfaces/window_manager.mojom.h" | 15 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 15 #include "services/ui/public/interfaces/window_tree.mojom.h" | 16 #include "services/ui/public/interfaces/window_tree.mojom.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
| 18 #include "third_party/skia/include/core/SkColor.h" | 19 #include "third_party/skia/include/core/SkColor.h" |
| 19 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| 20 #include "ui/events/event.h" | 21 #include "ui/events/event.h" |
| 21 #include "ui/events/test/test_event_handler.h" | 22 #include "ui/events/test/test_event_handler.h" |
| 22 #include "ui/gfx/geometry/rect.h" | 23 #include "ui/gfx/geometry/rect.h" |
| 23 #include "ui/gfx/image/image_skia.h" | 24 #include "ui/gfx/image/image_skia.h" |
| 24 #include "ui/gfx/path.h" | 25 #include "ui/gfx/path.h" |
| 25 #include "ui/gfx/skia_util.h" | 26 #include "ui/gfx/skia_util.h" |
| 26 #include "ui/views/controls/native/native_view_host.h" | 27 #include "ui/views/controls/native/native_view_host.h" |
| 28 #include "ui/views/mus/window_manager_connection.h" |
| 27 #include "ui/views/test/focus_manager_test.h" | 29 #include "ui/views/test/focus_manager_test.h" |
| 28 #include "ui/views/test/views_test_base.h" | 30 #include "ui/views/test/views_test_base.h" |
| 29 #include "ui/views/widget/widget.h" | 31 #include "ui/views/widget/widget.h" |
| 30 #include "ui/views/widget/widget_delegate.h" | 32 #include "ui/views/widget/widget_delegate.h" |
| 31 #include "ui/views/widget/widget_observer.h" | 33 #include "ui/views/widget/widget_observer.h" |
| 32 #include "ui/wm/public/activation_client.h" | 34 #include "ui/wm/public/activation_client.h" |
| 33 | 35 |
| 34 using ui::mojom::EventResult; | 36 using ui::mojom::EventResult; |
| 35 | 37 |
| 36 namespace views { | 38 namespace views { |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 // aura::Window. | 542 // aura::Window. |
| 541 TEST_F(NativeWidgetMusTest, DontShowTwice) { | 543 TEST_F(NativeWidgetMusTest, DontShowTwice) { |
| 542 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); | 544 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); |
| 543 widget->GetNativeView()->layer()->SetOpacity(0.0f); | 545 widget->GetNativeView()->layer()->SetOpacity(0.0f); |
| 544 // aura::Window::Show() allows the opacity to be 0 as long as the window is | 546 // aura::Window::Show() allows the opacity to be 0 as long as the window is |
| 545 // hidden. So, as long as this only invokes aura::Window::Show() once the | 547 // hidden. So, as long as this only invokes aura::Window::Show() once the |
| 546 // DCHECK in aura::Window::Show() won't fire. | 548 // DCHECK in aura::Window::Show() won't fire. |
| 547 widget->Show(); | 549 widget->Show(); |
| 548 } | 550 } |
| 549 | 551 |
| 552 namespace { |
| 553 |
| 554 // See description of test for details. |
| 555 class IsMaximizedObserver : public ui::WindowObserver { |
| 556 public: |
| 557 IsMaximizedObserver() {} |
| 558 ~IsMaximizedObserver() override {} |
| 559 |
| 560 void set_widget(Widget* widget) { widget_ = widget; } |
| 561 |
| 562 bool got_change() const { return got_change_; } |
| 563 |
| 564 // ui::WindowObserver: |
| 565 void OnWindowSharedPropertyChanged( |
| 566 ui::Window* window, |
| 567 const std::string& name, |
| 568 const std::vector<uint8_t>* old_data, |
| 569 const std::vector<uint8_t>* new_data) override { |
| 570 // Expect only one change for the show state. |
| 571 ASSERT_FALSE(got_change_); |
| 572 got_change_ = true; |
| 573 EXPECT_EQ(ui::mojom::WindowManager::kShowState_Property, name); |
| 574 EXPECT_TRUE(widget_->IsMaximized()); |
| 575 } |
| 576 |
| 577 private: |
| 578 bool got_change_ = false; |
| 579 Widget* widget_ = nullptr; |
| 580 |
| 581 DISALLOW_COPY_AND_ASSIGN(IsMaximizedObserver); |
| 582 }; |
| 583 |
| 584 } // namespace |
| 585 |
| 586 // Verifies that asking for Widget::IsMaximized() from within |
| 587 // OnWindowSharedPropertyChanged() returns the right thing. |
| 588 TEST_F(NativeWidgetMusTest, IsMaximized) { |
| 589 ASSERT_TRUE(WindowManagerConnection::Exists()); |
| 590 ui::Window* window = WindowManagerConnection::Get()->NewWindow( |
| 591 std::map<std::string, std::vector<uint8_t>>()); |
| 592 IsMaximizedObserver observer; |
| 593 // NOTE: the order here is important, we purposefully add the |
| 594 // ui::WindowObserver before creating NativeWidgetMus, which also adds its |
| 595 // own observer. |
| 596 window->AddObserver(&observer); |
| 597 |
| 598 std::unique_ptr<Widget> widget(new Widget()); |
| 599 observer.set_widget(widget.get()); |
| 600 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 601 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 602 params.bounds = initial_bounds(); |
| 603 params.native_widget = new NativeWidgetMus(widget.get(), window, |
| 604 ui::mojom::SurfaceType::DEFAULT); |
| 605 widget->Init(params); |
| 606 window->SetSharedProperty<int32_t>( |
| 607 ui::mojom::WindowManager::kShowState_Property, |
| 608 static_cast<uint32_t>(ui::mojom::ShowState::MAXIMIZED)); |
| 609 EXPECT_TRUE(widget->IsMaximized()); |
| 610 } |
| 611 |
| 550 } // namespace views | 612 } // namespace views |
| OLD | NEW |