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

Unified Diff: ui/views/widget/native_widget_mac_unittest.mm

Issue 630363003: More NativeWidget -> Widget notifications: visibility, minimize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20140704-Mac-VIEWS-ActivationChanges
Patch Set: rebase on crrev/654393002 Created 6 years, 2 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
« no previous file with comments | « ui/views/widget/native_widget_mac.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/widget/native_widget_mac_unittest.mm
diff --git a/ui/views/widget/native_widget_mac_unittest.mm b/ui/views/widget/native_widget_mac_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..9a761cdfc6d8670f501b873a4acfe014f9db3e12
--- /dev/null
+++ b/ui/views/widget/native_widget_mac_unittest.mm
@@ -0,0 +1,163 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ui/views/widget/native_widget_mac.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "ui/views/test/test_widget_observer.h"
+#include "ui/views/test/widget_test.h"
+
+namespace views {
+namespace test {
+
+// Tests for parts of NativeWidgetMac not covered by BridgedNativeWidget, which
+// need access to Cocoa APIs.
+typedef WidgetTest NativeWidgetMacTest;
+
+class WidgetChangeObserver : public TestWidgetObserver {
+ public:
+ WidgetChangeObserver(Widget* widget)
+ : TestWidgetObserver(widget),
+ gained_visible_count_(0),
+ lost_visible_count_(0) {}
+
+ int gained_visible_count() const { return gained_visible_count_; }
+ int lost_visible_count() const { return lost_visible_count_; }
+
+ private:
+ // WidgetObserver:
+ virtual void OnWidgetVisibilityChanged(Widget* widget,
+ bool visible) OVERRIDE {
+ ++(visible ? gained_visible_count_ : lost_visible_count_);
+ }
+
+ int gained_visible_count_;
+ int lost_visible_count_;
+
+ DISALLOW_COPY_AND_ASSIGN(WidgetChangeObserver);
+};
+
+// Test visibility states triggered externally.
+TEST_F(NativeWidgetMacTest, HideAndShowExternally) {
+ Widget* widget = CreateTopLevelPlatformWidget();
+ NSWindow* ns_window = widget->GetNativeWindow();
+ WidgetChangeObserver observer(widget);
+
+ // Should initially be hidden.
+ EXPECT_FALSE(widget->IsVisible());
+ EXPECT_FALSE([ns_window isVisible]);
+ EXPECT_EQ(0, observer.gained_visible_count());
+ EXPECT_EQ(0, observer.lost_visible_count());
+
+ widget->Show();
+ EXPECT_TRUE(widget->IsVisible());
+ EXPECT_TRUE([ns_window isVisible]);
+ EXPECT_EQ(1, observer.gained_visible_count());
+ EXPECT_EQ(0, observer.lost_visible_count());
+
+ widget->Hide();
+ EXPECT_FALSE(widget->IsVisible());
+ EXPECT_FALSE([ns_window isVisible]);
+ EXPECT_EQ(1, observer.gained_visible_count());
+ EXPECT_EQ(1, observer.lost_visible_count());
+
+ widget->Show();
+ EXPECT_TRUE(widget->IsVisible());
+ EXPECT_TRUE([ns_window isVisible]);
+ EXPECT_EQ(2, observer.gained_visible_count());
+ EXPECT_EQ(1, observer.lost_visible_count());
+
+ // Test when hiding individual windows.
+ [ns_window orderOut:nil];
+ EXPECT_FALSE(widget->IsVisible());
+ EXPECT_FALSE([ns_window isVisible]);
+ EXPECT_EQ(2, observer.gained_visible_count());
+ EXPECT_EQ(2, observer.lost_visible_count());
+
+ [ns_window orderFront:nil];
+ EXPECT_TRUE(widget->IsVisible());
+ EXPECT_TRUE([ns_window isVisible]);
+ EXPECT_EQ(3, observer.gained_visible_count());
+ EXPECT_EQ(2, observer.lost_visible_count());
+
+ // Test when hiding the entire application. This doesn't send an orderOut:
+ // to the NSWindow.
+ [NSApp hide:nil];
+ EXPECT_FALSE(widget->IsVisible());
+ EXPECT_FALSE([ns_window isVisible]);
+ EXPECT_EQ(3, observer.gained_visible_count());
+ EXPECT_EQ(3, observer.lost_visible_count());
+
+ [NSApp unhideWithoutActivation];
+ EXPECT_TRUE(widget->IsVisible());
+ EXPECT_TRUE([ns_window isVisible]);
+ EXPECT_EQ(4, observer.gained_visible_count());
+ EXPECT_EQ(3, observer.lost_visible_count());
+
+ // Hide again to test unhiding with an activation.
+ [NSApp hide:nil];
+ EXPECT_EQ(4, observer.lost_visible_count());
+ [NSApp unhide:nil];
+ EXPECT_EQ(5, observer.gained_visible_count());
+
+ // No change when closing.
+ widget->CloseNow();
+ EXPECT_EQ(4, observer.lost_visible_count());
+ EXPECT_EQ(5, observer.gained_visible_count());
+}
+
+// Test minimized states triggered externally, implied visibility and restored
+// bounds whilst minimized.
+TEST_F(NativeWidgetMacTest, MiniaturizeExternally) {
+ Widget* widget = CreateTopLevelPlatformWidget();
+ NSWindow* ns_window = widget->GetNativeWindow();
+ WidgetChangeObserver observer(widget);
+
+ widget->Show();
+ EXPECT_EQ(1, observer.gained_visible_count());
+ EXPECT_EQ(0, observer.lost_visible_count());
+ const gfx::Rect restored_bounds = widget->GetRestoredBounds();
+ EXPECT_FALSE(restored_bounds.IsEmpty());
+
+ [ns_window miniaturize:nil];
+
+ EXPECT_TRUE(widget->IsMinimized());
+ EXPECT_FALSE(widget->IsVisible());
+ EXPECT_EQ(1, observer.gained_visible_count());
+ EXPECT_EQ(1, observer.lost_visible_count());
+ EXPECT_EQ(restored_bounds, widget->GetRestoredBounds());
+
+ [ns_window deminiaturize:nil];
+ EXPECT_FALSE(widget->IsMinimized());
+ EXPECT_TRUE(widget->IsVisible());
+ EXPECT_EQ(2, observer.gained_visible_count());
+ EXPECT_EQ(1, observer.lost_visible_count());
+ EXPECT_EQ(restored_bounds, widget->GetRestoredBounds());
+
+ EXPECT_FALSE([ns_window isMiniaturized]);
+ widget->Minimize();
+ EXPECT_TRUE(widget->IsMinimized());
+ EXPECT_TRUE([ns_window isMiniaturized]);
+ EXPECT_EQ(2, observer.gained_visible_count());
+ EXPECT_EQ(2, observer.lost_visible_count());
+ EXPECT_EQ(restored_bounds, widget->GetRestoredBounds());
+
+ widget->Restore(); // If miniaturized, should deminiaturize.
+ EXPECT_FALSE(widget->IsMinimized());
+ EXPECT_FALSE([ns_window isMiniaturized]);
+ EXPECT_EQ(3, observer.gained_visible_count());
+ EXPECT_EQ(2, observer.lost_visible_count());
+ EXPECT_EQ(restored_bounds, widget->GetRestoredBounds());
+
+ widget->Restore(); // If not miniaturized, does nothing.
+ EXPECT_FALSE(widget->IsMinimized());
+ EXPECT_FALSE([ns_window isMiniaturized]);
+ EXPECT_EQ(3, observer.gained_visible_count());
+ EXPECT_EQ(2, observer.lost_visible_count());
+ EXPECT_EQ(restored_bounds, widget->GetRestoredBounds());
+}
+
+} // namespace test
+} // namespace views
« no previous file with comments | « ui/views/widget/native_widget_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698