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

Unified Diff: ui/views/mus/native_widget_mus_unittest.cc

Issue 1863523006: mash: Make system tray bubble close when another window is activated (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase again 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/mus/native_widget_mus_unittest.cc
diff --git a/ui/views/mus/native_widget_mus_unittest.cc b/ui/views/mus/native_widget_mus_unittest.cc
index 8dcebbcd8015e20124e8ab3bb7c1dd944a37160b..5f5df30c7c6f1ef42b08d5d8ba5478984b11e36c 100644
--- a/ui/views/mus/native_widget_mus_unittest.cc
+++ b/ui/views/mus/native_widget_mus_unittest.cc
@@ -31,6 +31,43 @@ SkBitmap MakeBitmap(SkColor color) {
return bitmap;
}
+// A Widget that tracks activation changes.
sky 2016/04/07 17:55:10 Rather than creating a widget subclass can you use
James Cook 2016/04/07 20:43:43 Switched to using TestWidgetFocusChangeListener an
+class TestWidget : public Widget {
+ public:
+ TestWidget() {}
+ ~TestWidget() override {}
+
+ bool last_activation_change() const { return last_activation_change_; }
+ int focus_count() const { return focus_count_; }
+ int blur_count() const { return blur_count_; }
+
+ void ResetCounts() {
+ focus_count_ = 0;
+ blur_count_ = 0;
+ }
+
+ // views::internal::NativeWidgetDelegate:
+ void OnNativeWidgetActivationChanged(bool active) override {
+ last_activation_change_ = active;
+ Widget::OnNativeWidgetActivationChanged(active);
+ }
+ void OnNativeFocus() override {
+ focus_count_++;
+ Widget::OnNativeFocus();
+ }
+ void OnNativeBlur() override {
+ blur_count_++;
+ Widget::OnNativeBlur();
+ }
+
+ private:
+ bool last_activation_change_ = false;
+ int focus_count_ = 0;
+ int blur_count_ = 0;
+
+ DISALLOW_COPY_AND_ASSIGN(TestWidget);
+};
+
// A WidgetDelegate that supplies an app icon.
class TestWidgetDelegate : public WidgetDelegateView {
public:
@@ -58,8 +95,8 @@ class NativeWidgetMusTest : public ViewsTestBase {
~NativeWidgetMusTest() override {}
// Creates a test widget. Takes ownership of |delegate|.
- Widget* CreateWidget(TestWidgetDelegate* delegate) {
- Widget* widget = new Widget();
+ TestWidget* CreateWidget(TestWidgetDelegate* delegate) {
sky 2016/04/07 17:55:10 Make this return a scoped_ptr
James Cook 2016/04/07 20:43:43 Done.
+ TestWidget* widget = new TestWidget();
Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
params.delegate = delegate;
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
@@ -72,6 +109,27 @@ class NativeWidgetMusTest : public ViewsTestBase {
DISALLOW_COPY_AND_ASSIGN(NativeWidgetMusTest);
};
+// Tests that native window activation and focus is passed to the Widget.
+TEST_F(NativeWidgetMusTest, OnActivationChanged) {
+ scoped_ptr<TestWidget> widget(CreateWidget(nullptr));
+ NativeWidgetMus* native_widget = static_cast<NativeWidgetMus*>(widget
+ ->native_widget_private());
+
+ // Simulate native widget being activated.
+ native_widget->OnActivationChanged(true);
sky 2016/04/07 17:55:10 If you call widget->Activate() does it call this?
James Cook 2016/04/07 20:43:43 Yes. Changed test to start the widget in the shown
+ EXPECT_EQ(1, widget->focus_count());
+ EXPECT_EQ(0, widget->blur_count());
+ EXPECT_TRUE(widget->last_activation_change());
+
+ widget->ResetCounts();
+
+ // Simulate native widget being deactivated.
+ native_widget->OnActivationChanged(false);
+ EXPECT_EQ(0, widget->focus_count());
+ EXPECT_EQ(1, widget->blur_count());
+ EXPECT_FALSE(widget->last_activation_change());
+}
+
// 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.
« mash/wm/public/interfaces/container.mojom ('K') | « 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