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

Side by Side Diff: chrome/browser/ui/cocoa/base_bubble_controller_unittest.mm

Issue 2717603003: [Mac] Make bubble arrow location/position RTL-aware (Closed)
Patch Set: Now with proper enum formatting Created 3 years, 9 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 (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/base_bubble_controller.h" 5 #import "chrome/browser/ui/cocoa/base_bubble_controller.h"
6 6
7 #import "base/mac/scoped_nsobject.h" 7 #import "base/mac/scoped_nsobject.h"
8 #import "base/mac/scoped_objc_class_swizzler.h" 8 #import "base/mac/scoped_objc_class_swizzler.h"
9 #import "base/mac/sdk_forward_declarations.h" 9 #import "base/mac/sdk_forward_declarations.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 base::scoped_nsobject<InfoBubbleWindow> bubble_window_; 158 base::scoped_nsobject<InfoBubbleWindow> bubble_window_;
159 BaseBubbleController* controller_; 159 BaseBubbleController* controller_;
160 160
161 private: 161 private:
162 DISALLOW_COPY_AND_ASSIGN(BaseBubbleControllerTest); 162 DISALLOW_COPY_AND_ASSIGN(BaseBubbleControllerTest);
163 }; 163 };
164 164
165 // Test that kAlignEdgeToAnchorEdge and a left bubble arrow correctly aligns the 165 // Test that kAlignEdgeToAnchorEdge and a left bubble arrow correctly aligns the
166 // left edge of the buble to the anchor point. 166 // left edge of the buble to the anchor point.
167 TEST_F(BaseBubbleControllerTest, LeftAlign) { 167 TEST_F(BaseBubbleControllerTest, LeftAlign) {
168 [[controller_ bubble] setArrowLocation:info_bubble::kTopLeft]; 168 [[controller_ bubble] setArrowLocation:info_bubble::kTopLeading];
169 [[controller_ bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; 169 [[controller_ bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge];
170 [controller_ showWindow:nil]; 170 [controller_ showWindow:nil];
171 171
172 NSRect frame = [[controller_ window] frame]; 172 NSRect frame = [[controller_ window] frame];
173 // Make sure the bubble size hasn't changed. 173 // Make sure the bubble size hasn't changed.
174 EXPECT_EQ(frame.size.width, kBubbleWindowWidth); 174 EXPECT_EQ(frame.size.width, kBubbleWindowWidth);
175 EXPECT_EQ(frame.size.height, kBubbleWindowHeight); 175 EXPECT_EQ(frame.size.height, kBubbleWindowHeight);
176 // Make sure the bubble is left aligned. 176 // Make sure the bubble is left aligned.
177 EXPECT_EQ(NSMinX(frame), kAnchorPointX); 177 EXPECT_EQ(NSMinX(frame), kAnchorPointX);
178 EXPECT_GE(NSMaxY(frame), kAnchorPointY); 178 EXPECT_GE(NSMaxY(frame), kAnchorPointY);
179 } 179 }
180 180
181 // Test that kAlignEdgeToAnchorEdge and a right bubble arrow correctly aligns 181 // Test that kAlignEdgeToAnchorEdge and a right bubble arrow correctly aligns
182 // the right edge of the buble to the anchor point. 182 // the right edge of the buble to the anchor point.
183 TEST_F(BaseBubbleControllerTest, RightAlign) { 183 TEST_F(BaseBubbleControllerTest, RightAlign) {
184 [[controller_ bubble] setArrowLocation:info_bubble::kTopRight]; 184 [[controller_ bubble] setArrowLocation:info_bubble::kTopTrailing];
185 [[controller_ bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; 185 [[controller_ bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge];
186 [controller_ showWindow:nil]; 186 [controller_ showWindow:nil];
187 187
188 NSRect frame = [[controller_ window] frame]; 188 NSRect frame = [[controller_ window] frame];
189 // Make sure the bubble size hasn't changed. 189 // Make sure the bubble size hasn't changed.
190 EXPECT_EQ(frame.size.width, kBubbleWindowWidth); 190 EXPECT_EQ(frame.size.width, kBubbleWindowWidth);
191 EXPECT_EQ(frame.size.height, kBubbleWindowHeight); 191 EXPECT_EQ(frame.size.height, kBubbleWindowHeight);
192 // Make sure the bubble is left aligned. 192 // Make sure the bubble is left aligned.
193 EXPECT_EQ(NSMaxX(frame), kAnchorPointX); 193 EXPECT_EQ(NSMaxX(frame), kAnchorPointX);
194 EXPECT_GE(NSMaxY(frame), kAnchorPointY); 194 EXPECT_GE(NSMaxY(frame), kAnchorPointY);
195 } 195 }
196 196
197 // Test that kAlignArrowToAnchor and a left bubble arrow correctly aligns 197 // Test that kAlignArrowToAnchor and a left bubble arrow correctly aligns
198 // the bubble arrow to the anchor point. 198 // the bubble arrow to the anchor point.
199 TEST_F(BaseBubbleControllerTest, AnchorAlignLeftArrow) { 199 TEST_F(BaseBubbleControllerTest, AnchorAlignLeftArrow) {
200 [[controller_ bubble] setArrowLocation:info_bubble::kTopLeft]; 200 [[controller_ bubble] setArrowLocation:info_bubble::kTopLeading];
201 [[controller_ bubble] setAlignment:info_bubble::kAlignArrowToAnchor]; 201 [[controller_ bubble] setAlignment:info_bubble::kAlignArrowToAnchor];
202 [controller_ showWindow:nil]; 202 [controller_ showWindow:nil];
203 203
204 NSRect frame = [[controller_ window] frame]; 204 NSRect frame = [[controller_ window] frame];
205 // Make sure the bubble size hasn't changed. 205 // Make sure the bubble size hasn't changed.
206 EXPECT_EQ(frame.size.width, kBubbleWindowWidth); 206 EXPECT_EQ(frame.size.width, kBubbleWindowWidth);
207 EXPECT_EQ(frame.size.height, kBubbleWindowHeight); 207 EXPECT_EQ(frame.size.height, kBubbleWindowHeight);
208 // Make sure the bubble arrow points to the anchor. 208 // Make sure the bubble arrow points to the anchor.
209 EXPECT_EQ(NSMinX(frame) + info_bubble::kBubbleArrowXOffset + 209 EXPECT_EQ(NSMinX(frame) + info_bubble::kBubbleArrowXOffset +
210 roundf(info_bubble::kBubbleArrowWidth / 2.0), kAnchorPointX); 210 roundf(info_bubble::kBubbleArrowWidth / 2.0), kAnchorPointX);
211 EXPECT_GE(NSMaxY(frame), kAnchorPointY); 211 EXPECT_GE(NSMaxY(frame), kAnchorPointY);
212 } 212 }
213 213
214 // Test that kAlignArrowToAnchor and a right bubble arrow correctly aligns 214 // Test that kAlignArrowToAnchor and a right bubble arrow correctly aligns
215 // the bubble arrow to the anchor point. 215 // the bubble arrow to the anchor point.
216 TEST_F(BaseBubbleControllerTest, AnchorAlignRightArrow) { 216 TEST_F(BaseBubbleControllerTest, AnchorAlignRightArrow) {
217 [[controller_ bubble] setArrowLocation:info_bubble::kTopRight]; 217 [[controller_ bubble] setArrowLocation:info_bubble::kTopTrailing];
218 [[controller_ bubble] setAlignment:info_bubble::kAlignArrowToAnchor]; 218 [[controller_ bubble] setAlignment:info_bubble::kAlignArrowToAnchor];
219 [controller_ showWindow:nil]; 219 [controller_ showWindow:nil];
220 220
221 NSRect frame = [[controller_ window] frame]; 221 NSRect frame = [[controller_ window] frame];
222 // Make sure the bubble size hasn't changed. 222 // Make sure the bubble size hasn't changed.
223 EXPECT_EQ(frame.size.width, kBubbleWindowWidth); 223 EXPECT_EQ(frame.size.width, kBubbleWindowWidth);
224 EXPECT_EQ(frame.size.height, kBubbleWindowHeight); 224 EXPECT_EQ(frame.size.height, kBubbleWindowHeight);
225 // Make sure the bubble arrow points to the anchor. 225 // Make sure the bubble arrow points to the anchor.
226 EXPECT_EQ(NSMaxX(frame) - info_bubble::kBubbleArrowXOffset - 226 EXPECT_EQ(NSMaxX(frame) - info_bubble::kBubbleArrowXOffset -
227 floorf(info_bubble::kBubbleArrowWidth / 2.0), kAnchorPointX); 227 floorf(info_bubble::kBubbleArrowWidth / 2.0), kAnchorPointX);
(...skipping 13 matching lines...) Expand all
241 EXPECT_EQ(frame.size.height, kBubbleWindowHeight); 241 EXPECT_EQ(frame.size.height, kBubbleWindowHeight);
242 // Make sure the bubble arrow points to the anchor. 242 // Make sure the bubble arrow points to the anchor.
243 EXPECT_EQ(NSMidX(frame), kAnchorPointX); 243 EXPECT_EQ(NSMidX(frame), kAnchorPointX);
244 EXPECT_GE(NSMaxY(frame), kAnchorPointY); 244 EXPECT_GE(NSMaxY(frame), kAnchorPointY);
245 } 245 }
246 246
247 // Test that the window is given an initial position before being shown. This 247 // Test that the window is given an initial position before being shown. This
248 // ensures offscreen initialization is done using correct screen metrics. 248 // ensures offscreen initialization is done using correct screen metrics.
249 TEST_F(BaseBubbleControllerTest, PositionedBeforeShow) { 249 TEST_F(BaseBubbleControllerTest, PositionedBeforeShow) {
250 // Verify default alignment settings, used when initialized in SetUp(). 250 // Verify default alignment settings, used when initialized in SetUp().
251 EXPECT_EQ(info_bubble::kTopRight, [[controller_ bubble] arrowLocation]); 251 EXPECT_EQ(info_bubble::kTopTrailing, [[controller_ bubble] arrowLocation]);
252 EXPECT_EQ(info_bubble::kAlignArrowToAnchor, [[controller_ bubble] alignment]); 252 EXPECT_EQ(info_bubble::kAlignArrowToAnchor, [[controller_ bubble] alignment]);
253 253
254 // Verify the default frame (positioned relative to the test_window() origin). 254 // Verify the default frame (positioned relative to the test_window() origin).
255 NSRect frame = [[controller_ window] frame]; 255 NSRect frame = [[controller_ window] frame];
256 EXPECT_EQ(NSMaxX(frame) - info_bubble::kBubbleArrowXOffset - 256 EXPECT_EQ(NSMaxX(frame) - info_bubble::kBubbleArrowXOffset -
257 floorf(info_bubble::kBubbleArrowWidth / 2.0), kAnchorPointX); 257 floorf(info_bubble::kBubbleArrowWidth / 2.0), kAnchorPointX);
258 EXPECT_EQ(NSMaxY(frame), kAnchorPointY); 258 EXPECT_EQ(NSMaxY(frame), kAnchorPointY);
259 } 259 }
260 260
261 // Tests that when a new window gets key state (and the bubble resigns) that 261 // Tests that when a new window gets key state (and the bubble resigns) that
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 443
444 // Post the "resign key" notification for another window. 444 // Post the "resign key" notification for another window.
445 NSNotification* notif = 445 NSNotification* notif =
446 [NSNotification notificationWithName:NSWindowDidResignKeyNotification 446 [NSNotification notificationWithName:NSWindowDidResignKeyNotification
447 object:test_window()]; 447 object:test_window()];
448 [[NSNotificationCenter defaultCenter] postNotification:notif]; 448 [[NSNotificationCenter defaultCenter] postNotification:notif];
449 449
450 EXPECT_TRUE([bubble_window_ isVisible]); 450 EXPECT_TRUE([bubble_window_ isVisible]);
451 g_key_window = nil; 451 g_key_window = nil;
452 } 452 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/base_bubble_controller.mm ('k') | chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698