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

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

Issue 809903009: Fix NativeWidgetMacTest.HideAndShowExternally (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comment Created 6 years 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 | « no previous file | 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
index 9cdcbe429d1039257f22c009b584d1e271e25f2c..6c3daca9f5f92ae5290544926d7b28b92beb7012 100644
--- a/ui/views/widget/native_widget_mac_unittest.mm
+++ b/ui/views/widget/native_widget_mac_unittest.mm
@@ -6,6 +6,7 @@
#import <Cocoa/Cocoa.h>
+#include "base/run_loop.h"
#include "ui/views/test/test_widget_observer.h"
#include "ui/views/test/widget_test.h"
@@ -85,12 +86,18 @@ TEST_F(NativeWidgetMacTest, HideAndShowExternally) {
// Test when hiding the entire application. This doesn't send an orderOut:
// to the NSWindow.
[NSApp hide:nil];
+ // When the activation policy is NSApplicationActivationPolicyRegular, the
+ // calls via NSApp are asynchronous, and the run loop needs to be flushed.
+ // With NSApplicationActivationPolicyProhibited, the following RunUntilIdle
+ // calls are superfluous, but don't hurt.
+ base::RunLoop().RunUntilIdle();
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];
+ base::RunLoop().RunUntilIdle();
EXPECT_TRUE(widget->IsVisible());
EXPECT_TRUE([ns_window isVisible]);
EXPECT_EQ(4, observer.gained_visible_count());
@@ -98,14 +105,29 @@ TEST_F(NativeWidgetMacTest, HideAndShowExternally) {
// Hide again to test unhiding with an activation.
[NSApp hide:nil];
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(4, observer.lost_visible_count());
[NSApp unhide:nil];
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(5, observer.gained_visible_count());
+ // Hide again to test makeKeyAndOrderFront:.
+ [ns_window orderOut:nil];
+ EXPECT_FALSE(widget->IsVisible());
+ EXPECT_FALSE([ns_window isVisible]);
+ EXPECT_EQ(5, observer.gained_visible_count());
+ EXPECT_EQ(5, observer.lost_visible_count());
+
+ [ns_window makeKeyAndOrderFront:nil];
+ EXPECT_TRUE(widget->IsVisible());
+ EXPECT_TRUE([ns_window isVisible]);
+ EXPECT_EQ(6, observer.gained_visible_count());
+ EXPECT_EQ(5, observer.lost_visible_count());
+
// No change when closing.
widget->CloseNow();
- EXPECT_EQ(4, observer.lost_visible_count());
- EXPECT_EQ(5, observer.gained_visible_count());
+ EXPECT_EQ(5, observer.lost_visible_count());
+ EXPECT_EQ(6, observer.gained_visible_count());
}
// A view that counts calls to OnPaint().
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698