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

Side by Side Diff: ui/views/widget/native_widget_mac_interactive_uitest.mm

Issue 1614663002: MacViews: Bubbles and dialogs behave more like sheets wrt main status (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix crash - much nicer anyway :) Created 4 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/widget/native_widget_mac.h" 5 #include "ui/views/widget/native_widget_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #import "base/mac/mac_util.h"
9 #import "base/mac/scoped_nsobject.h" 10 #import "base/mac/scoped_nsobject.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #import "ui/base/test/windowed_nsnotification_observer.h" 12 #import "ui/base/test/windowed_nsnotification_observer.h"
13 #include "ui/views/bubble/bubble_delegate.h"
12 #include "ui/views/test/test_widget_observer.h" 14 #include "ui/views/test/test_widget_observer.h"
13 #include "ui/views/test/widget_test.h" 15 #include "ui/views/test/widget_test.h"
14 16
15 namespace views { 17 namespace views {
16 namespace test { 18 namespace test {
17 19
18 // Tests for NativeWidgetMac that rely on global window manager state, and can 20 // Tests for NativeWidgetMac that rely on global window manager state, and can
19 // not be parallelized. 21 // not be parallelized.
20 class NativeWidgetMacInteractiveUITest 22 class NativeWidgetMacInteractiveUITest
21 : public WidgetTest, 23 : public WidgetTest,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 // Activating the inactive widget should make it key, asynchronously. 128 // Activating the inactive widget should make it key, asynchronously.
127 widget->Activate(); 129 widget->Activate();
128 [waiter wait]; 130 [waiter wait];
129 EXPECT_EQ(1, [waiter notificationCount]); 131 EXPECT_EQ(1, [waiter notificationCount]);
130 EXPECT_TRUE(widget->IsActive()); 132 EXPECT_TRUE(widget->IsActive());
131 EXPECT_TRUE([widget->GetNativeWindow() isKeyWindow]); 133 EXPECT_TRUE([widget->GetNativeWindow() isKeyWindow]);
132 134
133 widget->CloseNow(); 135 widget->CloseNow();
134 } 136 }
135 137
138 namespace {
139
140 // Show |widget| and wait for it to become the key window.
141 void ShowKeyWindow(Widget* widget) {
142 base::scoped_nsobject<WindowedNSNotificationObserver> waiter(
143 [[WindowedNSNotificationObserver alloc]
144 initForNotification:NSWindowDidBecomeKeyNotification
145 object:widget->GetNativeWindow()]);
146 widget->Show();
147 EXPECT_TRUE([waiter wait]);
148 EXPECT_TRUE([widget->GetNativeWindow() isKeyWindow]);
149 }
150
151 NSData* ViewAsTIFF(NSView* view) {
152 NSBitmapImageRep* bitmap =
153 [view bitmapImageRepForCachingDisplayInRect:[view bounds]];
154 [view cacheDisplayInRect:[view bounds] toBitmapImageRep:bitmap];
155 return [bitmap TIFFRepresentation];
156 }
157 }
Robert Sesek 2016/01/21 23:41:35 " // namespace" and a line before
tapted 2016/01/22 00:28:06 Done.
158
159 // Test that parent windows keep their traffic lights enabled when showing
160 // dialogs.
161 TEST_F(NativeWidgetMacInteractiveUITest, ParentWindowTrafficLights) {
162 // Snow leopard doesn't have -[NSWindow _sharesParentKeyState].
163 if (base::mac::IsOSSnowLeopard())
164 return;
165
166 Widget* parent_widget = CreateTopLevelPlatformWidget();
167 parent_widget->SetBounds(gfx::Rect(100, 100, 100, 100));
168 ShowKeyWindow(parent_widget);
169
170 NSWindow* parent = parent_widget->GetNativeWindow();
171 EXPECT_TRUE([parent isMainWindow]);
172
173 NSButton* button = [parent standardWindowButton:NSWindowCloseButton];
174 EXPECT_TRUE(button);
175 NSData* active_button_image = ViewAsTIFF(button);
176 EXPECT_TRUE(active_button_image);
177
178 // Create an activatable frameless child. Frameless so that it doesn't have
179 // traffic lights of its own, and activatable so that it can take key status.
180 Widget* child_widget = new Widget;
181 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
182 params.native_widget = new NativeWidgetMac(child_widget);
183 params.bounds = gfx::Rect(130, 130, 100, 100);
184 params.parent = parent_widget->GetNativeView();
185 child_widget->Init(params);
186 ShowKeyWindow(child_widget);
187
188 // Ensure the button instance is still valid.
189 EXPECT_EQ(button, [parent standardWindowButton:NSWindowCloseButton]);
190
191 // Parent window should still be main, and have its traffic lights active.
192 EXPECT_TRUE([parent isMainWindow]);
tapted 2016/01/22 00:28:06 yegads AppKit. So with the bridge()->parent() => [
193 EXPECT_FALSE([parent isKeyWindow]);
194
195 // Enabled status doesn't actually change, but check anyway.
196 EXPECT_TRUE([button isEnabled]);
197 NSData* button_image_with_child = ViewAsTIFF(button);
198 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
199
200 // Verify that activating some other random window does change the button.
201 Widget* other_widget = CreateTopLevelPlatformWidget();
202 other_widget->SetBounds(gfx::Rect(200, 200, 100, 100));
203 ShowKeyWindow(other_widget);
204 EXPECT_FALSE([parent isMainWindow]);
205 EXPECT_FALSE([parent isKeyWindow]);
206 EXPECT_TRUE([button isEnabled]);
207 NSData* inactive_button_image = ViewAsTIFF(button);
208 EXPECT_FALSE([active_button_image isEqualToData:inactive_button_image]);
209
210 other_widget->CloseNow();
211 parent_widget->CloseNow();
212 }
213
136 INSTANTIATE_TEST_CASE_P(NativeWidgetMacInteractiveUITestInstance, 214 INSTANTIATE_TEST_CASE_P(NativeWidgetMacInteractiveUITestInstance,
137 NativeWidgetMacInteractiveUITest, 215 NativeWidgetMacInteractiveUITest,
138 ::testing::Bool()); 216 ::testing::Bool());
139 217
140 } // namespace test 218 } // namespace test
141 } // namespace views 219 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/cocoa/native_widget_mac_nswindow.mm ('k') | ui/views/widget/native_widget_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698