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

Side by Side Diff: chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_controller_unittest.mm

Issue 11416309: Fix constrained window position for inactive tab (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_controller.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con troller.h" 5 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con troller.h"
6 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 6 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
7 #import "testing/gtest_mac.h" 7 #import "testing/gtest_mac.h"
8 8
9 class ConstrainedWindowSheetControllerTest : public CocoaTest { 9 class ConstrainedWindowSheetControllerTest : public CocoaTest {
10 protected: 10 protected:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 EXPECT_TRUE(controller); 59 EXPECT_TRUE(controller);
60 [controller parentViewDidBecomeActive:active_tab_view_]; 60 [controller parentViewDidBecomeActive:active_tab_view_];
61 } 61 }
62 62
63 NSRect GetViewFrameInScreenCoordinates(NSView* view) { 63 NSRect GetViewFrameInScreenCoordinates(NSView* view) {
64 NSRect rect = [view convertRect:[view bounds] toView:nil]; 64 NSRect rect = [view convertRect:[view bounds] toView:nil];
65 rect.origin = [[view window] convertBaseToScreen:rect.origin]; 65 rect.origin = [[view window] convertBaseToScreen:rect.origin];
66 return rect; 66 return rect;
67 } 67 }
68 68
69 void VerifySheetXPosition(NSRect sheet_frame, NSView* parent_view) {
70 NSRect parent_frame = GetViewFrameInScreenCoordinates(parent_view);
71 CGFloat expected_x = NSMinX(parent_frame) +
72 (NSWidth(parent_frame) - NSWidth(sheet_frame)) / 2.0;
73 EXPECT_EQ(expected_x, NSMinX(sheet_frame));
74 }
75
69 scoped_nsobject<NSWindow> sheet_; 76 scoped_nsobject<NSWindow> sheet_;
70 scoped_nsobject<ConstrainedWindowSheetController> controller_; 77 scoped_nsobject<ConstrainedWindowSheetController> controller_;
71 scoped_nsobject<NSMutableArray> tab_views_; 78 scoped_nsobject<NSMutableArray> tab_views_;
72 scoped_nsobject<NSView> active_tab_view_; 79 scoped_nsobject<NSView> active_tab_view_;
73 scoped_nsobject<NSView> tab0_; 80 scoped_nsobject<NSView> tab0_;
74 scoped_nsobject<NSView> tab1_; 81 scoped_nsobject<NSView> tab1_;
75 }; 82 };
76 83
77 // Test showing then hiding the sheet. 84 // Test showing then hiding the sheet.
78 TEST_F(ConstrainedWindowSheetControllerTest, ShowHide) { 85 TEST_F(ConstrainedWindowSheetControllerTest, ShowHide) {
(...skipping 22 matching lines...) Expand all
101 } 108 }
102 109
103 // Test that adding a sheet to an inactive view doesn't show it. 110 // Test that adding a sheet to an inactive view doesn't show it.
104 TEST_F(ConstrainedWindowSheetControllerTest, AddToInactiveTab) { 111 TEST_F(ConstrainedWindowSheetControllerTest, AddToInactiveTab) {
105 ActivateTabView(tab0_); 112 ActivateTabView(tab0_);
106 [controller_ showSheet:sheet_ forParentView:tab1_]; 113 [controller_ showSheet:sheet_ forParentView:tab1_];
107 EXPECT_EQ(0.0, [sheet_ alphaValue]); 114 EXPECT_EQ(0.0, [sheet_ alphaValue]);
108 115
109 ActivateTabView(tab1_); 116 ActivateTabView(tab1_);
110 EXPECT_EQ(1.0, [sheet_ alphaValue]); 117 EXPECT_EQ(1.0, [sheet_ alphaValue]);
118 VerifySheetXPosition([sheet_ frame], tab1_);
111 } 119 }
112 120
113 // Test that two parent windows with two sheet controllers don't conflict. 121 // Test that two parent windows with two sheet controllers don't conflict.
114 TEST_F(ConstrainedWindowSheetControllerTest, TwoParentWindows) { 122 TEST_F(ConstrainedWindowSheetControllerTest, TwoParentWindows) {
115 scoped_nsobject<NSWindow> parent_window2([[NSWindow alloc] 123 scoped_nsobject<NSWindow> parent_window2([[NSWindow alloc]
116 initWithContentRect:NSMakeRect(0, 0, 30, 30) 124 initWithContentRect:NSMakeRect(0, 0, 30, 30)
117 styleMask:NSTitledWindowMask 125 styleMask:NSTitledWindowMask
118 backing:NSBackingStoreBuffered 126 backing:NSBackingStoreBuffered
119 defer:NO]); 127 defer:NO]);
120 [parent_window2 setReleasedWhenClosed:NO]; 128 [parent_window2 setReleasedWhenClosed:NO];
(...skipping 13 matching lines...) Expand all
134 142
135 // Test that using a top level parent view works. 143 // Test that using a top level parent view works.
136 TEST_F(ConstrainedWindowSheetControllerTest, TopLevelView) { 144 TEST_F(ConstrainedWindowSheetControllerTest, TopLevelView) {
137 NSView* parentView = [[test_window() contentView] superview]; 145 NSView* parentView = [[test_window() contentView] superview];
138 [controller_ parentViewDidBecomeActive:parentView]; 146 [controller_ parentViewDidBecomeActive:parentView];
139 147
140 EXPECT_FALSE([sheet_ isVisible]); 148 EXPECT_FALSE([sheet_ isVisible]);
141 [controller_ showSheet:sheet_ forParentView:parentView]; 149 [controller_ showSheet:sheet_ forParentView:parentView];
142 EXPECT_TRUE([ConstrainedWindowSheetController controllerForSheet:sheet_]); 150 EXPECT_TRUE([ConstrainedWindowSheetController controllerForSheet:sheet_]);
143 EXPECT_TRUE([sheet_ isVisible]); 151 EXPECT_TRUE([sheet_ isVisible]);
144 152 VerifySheetXPosition([sheet_ frame], parentView);
145 NSRect parent_frame = GetViewFrameInScreenCoordinates(parentView);
146 NSRect sheet_frame = [sheet_ frame];
147 CGFloat expected_x = NSMinX(parent_frame) +
148 (NSWidth(parent_frame) - NSWidth(sheet_frame)) / 2.0;
149 EXPECT_EQ(expected_x, NSMinX(sheet_frame));
150 } 153 }
151 154
152 // Test that resizing sheet works. 155 // Test that resizing sheet works.
153 TEST_F(ConstrainedWindowSheetControllerTest, Resize) { 156 TEST_F(ConstrainedWindowSheetControllerTest, Resize) {
154 [controller_ showSheet:sheet_ forParentView:active_tab_view_]; 157 [controller_ showSheet:sheet_ forParentView:active_tab_view_];
155 158
156 NSRect old_frame = [sheet_ frame]; 159 NSRect old_frame = [sheet_ frame];
157 160
158 NSRect sheet_frame; 161 NSRect sheet_frame;
159 sheet_frame.size = NSMakeSize(NSWidth(old_frame) + 100, 162 sheet_frame.size = NSMakeSize(NSWidth(old_frame) + 100,
160 NSHeight(old_frame) + 50); 163 NSHeight(old_frame) + 50);
161 sheet_frame.origin = [controller_ originForSheet:sheet_ 164 sheet_frame.origin = [controller_ originForSheet:sheet_
162 withWindowSize:sheet_frame.size]; 165 withWindowSize:sheet_frame.size];
163 166
164 // Y pos should not have changed. 167 // Y pos should not have changed.
165 EXPECT_EQ(NSMaxY(sheet_frame), NSMaxY(old_frame)); 168 EXPECT_EQ(NSMaxY(sheet_frame), NSMaxY(old_frame));
166 169
167 // X pos should be centered on parent view. 170 // X pos should be centered on parent view.
168 NSRect parent_frame = GetViewFrameInScreenCoordinates(active_tab_view_); 171 VerifySheetXPosition(sheet_frame, active_tab_view_);
169 CGFloat expected_x = NSMinX(parent_frame) +
170 (NSWidth(parent_frame) - NSWidth(sheet_frame)) / 2.0;
171 EXPECT_EQ(expected_x, NSMinX(sheet_frame));
172 } 172 }
173 173
174 // Test that resizing a hidden sheet works. 174 // Test that resizing a hidden sheet works.
175 TEST_F(ConstrainedWindowSheetControllerTest, ResizeHiddenSheet) { 175 TEST_F(ConstrainedWindowSheetControllerTest, ResizeHiddenSheet) {
176 [controller_ showSheet:sheet_ forParentView:tab0_]; 176 [controller_ showSheet:sheet_ forParentView:tab0_];
177 EXPECT_EQ(1.0, [sheet_ alphaValue]); 177 EXPECT_EQ(1.0, [sheet_ alphaValue]);
178 ActivateTabView(tab1_); 178 ActivateTabView(tab1_);
179 EXPECT_EQ(0.0, [sheet_ alphaValue]); 179 EXPECT_EQ(0.0, [sheet_ alphaValue]);
180 180
181 NSRect old_frame = [sheet_ frame]; 181 NSRect old_frame = [sheet_ frame];
182 NSRect new_inactive_frame = NSInsetRect(old_frame, -30, -40); 182 NSRect new_inactive_frame = NSInsetRect(old_frame, -30, -40);
183 [sheet_ setFrame:new_inactive_frame display:YES]; 183 [sheet_ setFrame:new_inactive_frame display:YES];
184 184
185 ActivateTabView(tab0_); 185 ActivateTabView(tab0_);
186 EXPECT_EQ(1.0, [sheet_ alphaValue]); 186 EXPECT_EQ(1.0, [sheet_ alphaValue]);
187 187
188 NSRect new_active_frame = [sheet_ frame]; 188 NSRect new_active_frame = [sheet_ frame];
189 EXPECT_TRUE(NSEqualRects(new_inactive_frame, new_active_frame)); 189 EXPECT_EQ(NSWidth(new_inactive_frame), NSWidth(new_active_frame));
190 EXPECT_EQ(NSHeight(new_inactive_frame), NSHeight(new_active_frame));
190 } 191 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698