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

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

Issue 1955343002: Mac: Use a "less" private API for keeping traffic lights lit while bubbles are showing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20160509-MacViews-HasActiveAppearance-upstream
Patch Set: Add a comment Created 4 years, 7 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
« no previous file with comments | « ui/views/cocoa/native_widget_mac_nswindow.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/mac_util.h"
10 #import "base/mac/scoped_nsobject.h" 10 #import "base/mac/scoped_nsobject.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "ui/base/test/ui_controls.h" 12 #include "ui/base/test/ui_controls.h"
13 #import "ui/base/test/windowed_nsnotification_observer.h" 13 #import "ui/base/test/windowed_nsnotification_observer.h"
14 #include "ui/views/bubble/bubble_dialog_delegate.h"
14 #include "ui/views/test/test_widget_observer.h" 15 #include "ui/views/test/test_widget_observer.h"
15 #include "ui/views/test/widget_test.h" 16 #include "ui/views/test/widget_test.h"
16 17
17 namespace views { 18 namespace views {
18 namespace test { 19 namespace test {
19 20
20 // Tests for NativeWidgetMac that rely on global window manager state, and can 21 // Tests for NativeWidgetMac that rely on global window manager state, and can
21 // not be parallelized. 22 // not be parallelized.
22 class NativeWidgetMacInteractiveUITest 23 class NativeWidgetMacInteractiveUITest
23 : public WidgetTest, 24 : public WidgetTest,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 EXPECT_TRUE([widget->GetNativeWindow() isKeyWindow]); 153 EXPECT_TRUE([widget->GetNativeWindow() isKeyWindow]);
153 } 154 }
154 155
155 NSData* ViewAsTIFF(NSView* view) { 156 NSData* ViewAsTIFF(NSView* view) {
156 NSBitmapImageRep* bitmap = 157 NSBitmapImageRep* bitmap =
157 [view bitmapImageRepForCachingDisplayInRect:[view bounds]]; 158 [view bitmapImageRepForCachingDisplayInRect:[view bounds]];
158 [view cacheDisplayInRect:[view bounds] toBitmapImageRep:bitmap]; 159 [view cacheDisplayInRect:[view bounds] toBitmapImageRep:bitmap];
159 return [bitmap TIFFRepresentation]; 160 return [bitmap TIFFRepresentation];
160 } 161 }
161 162
163 class TestBubbleView : public BubbleDialogDelegateView {
164 public:
165 explicit TestBubbleView(Widget* parent) {
166 SetAnchorView(parent->GetContentsView());
167 }
168
169 private:
170 DISALLOW_COPY_AND_ASSIGN(TestBubbleView);
171 };
172
162 } // namespace 173 } // namespace
163 174
164 // Test that parent windows keep their traffic lights enabled when showing 175 // Test that parent windows keep their traffic lights enabled when showing
165 // dialogs. 176 // dialogs.
166 TEST_F(NativeWidgetMacInteractiveUITest, ParentWindowTrafficLights) { 177 TEST_F(NativeWidgetMacInteractiveUITest, ParentWindowTrafficLights) {
167 Widget* parent_widget = CreateTopLevelPlatformWidget(); 178 Widget* parent_widget = CreateTopLevelPlatformWidget();
168 parent_widget->SetBounds(gfx::Rect(100, 100, 100, 100)); 179 parent_widget->SetBounds(gfx::Rect(100, 100, 100, 100));
169 ShowKeyWindow(parent_widget); 180 ShowKeyWindow(parent_widget);
170 181
171 NSWindow* parent = parent_widget->GetNativeWindow(); 182 NSWindow* parent = parent_widget->GetNativeWindow();
172 EXPECT_TRUE([parent isMainWindow]); 183 EXPECT_TRUE([parent isMainWindow]);
173 184
174 NSButton* button = [parent standardWindowButton:NSWindowCloseButton]; 185 NSButton* button = [parent standardWindowButton:NSWindowCloseButton];
175 EXPECT_TRUE(button); 186 EXPECT_TRUE(button);
176 NSData* active_button_image = ViewAsTIFF(button); 187 NSData* active_button_image = ViewAsTIFF(button);
177 EXPECT_TRUE(active_button_image); 188 EXPECT_TRUE(active_button_image);
178 189
179 // Create an activatable frameless child. Frameless so that it doesn't have 190 // Pop open a bubble on the parent Widget. When the visibility of Bubbles with
180 // traffic lights of its own, and activatable so that it can take key status. 191 // an anchor View changes, BubbleDialogDelegateView::HandleVisibilityChanged()
181 Widget* child_widget = new Widget; 192 // updates Widget::SetAlwaysRenderAsActive(..) accordingly.
182 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW_FRAMELESS); 193 ShowKeyWindow(BubbleDialogDelegateView::CreateBubble(
183 params.native_widget = new NativeWidgetMac(child_widget); 194 new TestBubbleView(parent_widget)));
184 params.bounds = gfx::Rect(130, 130, 100, 100);
185 params.parent = parent_widget->GetNativeView();
186 child_widget->Init(params);
187 ShowKeyWindow(child_widget);
188 195
189 // Ensure the button instance is still valid. 196 // Ensure the button instance is still valid.
190 EXPECT_EQ(button, [parent standardWindowButton:NSWindowCloseButton]); 197 EXPECT_EQ(button, [parent standardWindowButton:NSWindowCloseButton]);
191 198
192 // Parent window should still be main, and have its traffic lights active. 199 // Parent window should still be main, and have its traffic lights active.
193 EXPECT_TRUE([parent isMainWindow]); 200 EXPECT_TRUE([parent isMainWindow]);
194 EXPECT_FALSE([parent isKeyWindow]); 201 EXPECT_FALSE([parent isKeyWindow]);
195 202
196 // Enabled status doesn't actually change, but check anyway. 203 // Enabled status doesn't actually change, but check anyway.
197 EXPECT_TRUE([button isEnabled]); 204 EXPECT_TRUE([button isEnabled]);
198 NSData* button_image_with_child = ViewAsTIFF(button); 205 NSData* button_image_with_child = ViewAsTIFF(button);
199 EXPECT_TRUE([active_button_image isEqualToData:button_image_with_child]); 206 EXPECT_TRUE([active_button_image isEqualToData:button_image_with_child]);
200 207
201 // Verify that activating some other random window does change the button. 208 // Verify that activating some other random window does change the button.
209 // When the bubble loses activation, it will dismiss itself and update
210 // Widget::SetAlwaysRenderAsActive().
202 Widget* other_widget = CreateTopLevelPlatformWidget(); 211 Widget* other_widget = CreateTopLevelPlatformWidget();
203 other_widget->SetBounds(gfx::Rect(200, 200, 100, 100)); 212 other_widget->SetBounds(gfx::Rect(200, 200, 100, 100));
204 ShowKeyWindow(other_widget); 213 ShowKeyWindow(other_widget);
205 EXPECT_FALSE([parent isMainWindow]); 214 EXPECT_FALSE([parent isMainWindow]);
206 EXPECT_FALSE([parent isKeyWindow]); 215 EXPECT_FALSE([parent isKeyWindow]);
207 EXPECT_TRUE([button isEnabled]); 216 EXPECT_TRUE([button isEnabled]);
208 NSData* inactive_button_image = ViewAsTIFF(button); 217 NSData* inactive_button_image = ViewAsTIFF(button);
209 EXPECT_FALSE([active_button_image isEqualToData:inactive_button_image]); 218 EXPECT_FALSE([active_button_image isEqualToData:inactive_button_image]);
210 219
211 other_widget->CloseNow(); 220 other_widget->CloseNow();
212 parent_widget->CloseNow(); 221 parent_widget->CloseNow();
213 } 222 }
214 223
215 INSTANTIATE_TEST_CASE_P(NativeWidgetMacInteractiveUITestInstance, 224 INSTANTIATE_TEST_CASE_P(NativeWidgetMacInteractiveUITestInstance,
216 NativeWidgetMacInteractiveUITest, 225 NativeWidgetMacInteractiveUITest,
217 ::testing::Bool()); 226 ::testing::Bool());
218 227
219 } // namespace test 228 } // namespace test
220 } // namespace views 229 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/cocoa/native_widget_mac_nswindow.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698