Chromium Code Reviews| Index: ui/views/widget/native_widget_mac_interactive_uitest.mm |
| diff --git a/ui/views/widget/native_widget_mac_interactive_uitest.mm b/ui/views/widget/native_widget_mac_interactive_uitest.mm |
| index 8f192662b248fed767728b6c73fb9181ff582065..ead489c8fe1626a35704040656092210ec580967 100644 |
| --- a/ui/views/widget/native_widget_mac_interactive_uitest.mm |
| +++ b/ui/views/widget/native_widget_mac_interactive_uitest.mm |
| @@ -6,9 +6,11 @@ |
| #import <Cocoa/Cocoa.h> |
| +#import "base/mac/mac_util.h" |
| #import "base/mac/scoped_nsobject.h" |
| #include "base/macros.h" |
| #import "ui/base/test/windowed_nsnotification_observer.h" |
| +#include "ui/views/bubble/bubble_delegate.h" |
| #include "ui/views/test/test_widget_observer.h" |
| #include "ui/views/test/widget_test.h" |
| @@ -133,6 +135,82 @@ TEST_P(NativeWidgetMacInteractiveUITest, ShowInactiveIgnoresKeyStatus) { |
| widget->CloseNow(); |
| } |
| +namespace { |
| + |
| +// Show |widget| and wait for it to become the key window. |
| +void ShowKeyWindow(Widget* widget) { |
| + base::scoped_nsobject<WindowedNSNotificationObserver> waiter( |
| + [[WindowedNSNotificationObserver alloc] |
| + initForNotification:NSWindowDidBecomeKeyNotification |
| + object:widget->GetNativeWindow()]); |
| + widget->Show(); |
| + EXPECT_TRUE([waiter wait]); |
| + EXPECT_TRUE([widget->GetNativeWindow() isKeyWindow]); |
| +} |
| + |
| +NSData* ViewAsTIFF(NSView* view) { |
| + NSBitmapImageRep* bitmap = |
| + [view bitmapImageRepForCachingDisplayInRect:[view bounds]]; |
| + [view cacheDisplayInRect:[view bounds] toBitmapImageRep:bitmap]; |
| + return [bitmap TIFFRepresentation]; |
| +} |
| +} |
|
Robert Sesek
2016/01/21 23:41:35
" // namespace" and a line before
tapted
2016/01/22 00:28:06
Done.
|
| + |
| +// Test that parent windows keep their traffic lights enabled when showing |
| +// dialogs. |
| +TEST_F(NativeWidgetMacInteractiveUITest, ParentWindowTrafficLights) { |
| + // Snow leopard doesn't have -[NSWindow _sharesParentKeyState]. |
| + if (base::mac::IsOSSnowLeopard()) |
| + return; |
| + |
| + Widget* parent_widget = CreateTopLevelPlatformWidget(); |
| + parent_widget->SetBounds(gfx::Rect(100, 100, 100, 100)); |
| + ShowKeyWindow(parent_widget); |
| + |
| + NSWindow* parent = parent_widget->GetNativeWindow(); |
| + EXPECT_TRUE([parent isMainWindow]); |
| + |
| + NSButton* button = [parent standardWindowButton:NSWindowCloseButton]; |
| + EXPECT_TRUE(button); |
| + NSData* active_button_image = ViewAsTIFF(button); |
| + EXPECT_TRUE(active_button_image); |
| + |
| + // Create an activatable frameless child. Frameless so that it doesn't have |
| + // traffic lights of its own, and activatable so that it can take key status. |
| + Widget* child_widget = new Widget; |
| + Widget::InitParams params(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| + params.native_widget = new NativeWidgetMac(child_widget); |
| + params.bounds = gfx::Rect(130, 130, 100, 100); |
| + params.parent = parent_widget->GetNativeView(); |
| + child_widget->Init(params); |
| + ShowKeyWindow(child_widget); |
| + |
| + // Ensure the button instance is still valid. |
| + EXPECT_EQ(button, [parent standardWindowButton:NSWindowCloseButton]); |
| + |
| + // Parent window should still be main, and have its traffic lights active. |
| + EXPECT_TRUE([parent isMainWindow]); |
|
tapted
2016/01/22 00:28:06
yegads AppKit. So with the bridge()->parent() => [
|
| + EXPECT_FALSE([parent isKeyWindow]); |
| + |
| + // Enabled status doesn't actually change, but check anyway. |
| + EXPECT_TRUE([button isEnabled]); |
| + NSData* button_image_with_child = ViewAsTIFF(button); |
| + EXPECT_TRUE([active_button_image isEqualToData:button_image_with_child]); |
|
tapted
2016/01/21 23:02:27
oops#2 - I meant to comment on this too that this
|
| + |
| + // Verify that activating some other random window does change the button. |
| + Widget* other_widget = CreateTopLevelPlatformWidget(); |
| + other_widget->SetBounds(gfx::Rect(200, 200, 100, 100)); |
| + ShowKeyWindow(other_widget); |
| + EXPECT_FALSE([parent isMainWindow]); |
| + EXPECT_FALSE([parent isKeyWindow]); |
| + EXPECT_TRUE([button isEnabled]); |
| + NSData* inactive_button_image = ViewAsTIFF(button); |
| + EXPECT_FALSE([active_button_image isEqualToData:inactive_button_image]); |
| + |
| + other_widget->CloseNow(); |
| + parent_widget->CloseNow(); |
| +} |
| + |
| INSTANTIATE_TEST_CASE_P(NativeWidgetMacInteractiveUITestInstance, |
| NativeWidgetMacInteractiveUITest, |
| ::testing::Bool()); |