OLD | NEW |
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 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
10 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 10 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 225 |
226 NSRect frame = [[controller_ window] frame]; | 226 NSRect frame = [[controller_ window] frame]; |
227 // Make sure the bubble size hasn't changed. | 227 // Make sure the bubble size hasn't changed. |
228 EXPECT_EQ(frame.size.width, kBubbleWindowWidth); | 228 EXPECT_EQ(frame.size.width, kBubbleWindowWidth); |
229 EXPECT_EQ(frame.size.height, kBubbleWindowHeight); | 229 EXPECT_EQ(frame.size.height, kBubbleWindowHeight); |
230 // Make sure the bubble arrow points to the anchor. | 230 // Make sure the bubble arrow points to the anchor. |
231 EXPECT_EQ(NSMidX(frame), kAnchorPointX); | 231 EXPECT_EQ(NSMidX(frame), kAnchorPointX); |
232 EXPECT_GE(NSMaxY(frame), kAnchorPointY); | 232 EXPECT_GE(NSMaxY(frame), kAnchorPointY); |
233 } | 233 } |
234 | 234 |
| 235 // Test that the window is given an initial position before being shown. This |
| 236 // ensures offscreen initialization is done using correct screen metrics. |
| 237 TEST_F(BaseBubbleControllerTest, PositionedBeforeShow) { |
| 238 // Verify default alignment settings, used when initialized in SetUp(). |
| 239 EXPECT_EQ(info_bubble::kTopRight, [[controller_ bubble] arrowLocation]); |
| 240 EXPECT_EQ(info_bubble::kAlignArrowToAnchor, [[controller_ bubble] alignment]); |
| 241 |
| 242 // Verify the default frame (positioned relative to the test_window() origin). |
| 243 NSRect frame = [[controller_ window] frame]; |
| 244 EXPECT_EQ(NSMaxX(frame) - info_bubble::kBubbleArrowXOffset - |
| 245 floorf(info_bubble::kBubbleArrowWidth / 2.0), kAnchorPointX); |
| 246 EXPECT_EQ(NSMaxY(frame), kAnchorPointY); |
| 247 } |
| 248 |
235 // Tests that when a new window gets key state (and the bubble resigns) that | 249 // Tests that when a new window gets key state (and the bubble resigns) that |
236 // the key window changes. | 250 // the key window changes. |
237 TEST_F(BaseBubbleControllerTest, ResignKeyCloses) { | 251 TEST_F(BaseBubbleControllerTest, ResignKeyCloses) { |
238 base::scoped_nsobject<NSWindow> other_window( | 252 base::scoped_nsobject<NSWindow> other_window( |
239 [[NSWindow alloc] initWithContentRect:NSMakeRect(500, 500, 500, 500) | 253 [[NSWindow alloc] initWithContentRect:NSMakeRect(500, 500, 500, 500) |
240 styleMask:NSTitledWindowMask | 254 styleMask:NSTitledWindowMask |
241 backing:NSBackingStoreBuffered | 255 backing:NSBackingStoreBuffered |
242 defer:YES]); | 256 defer:YES]); |
243 | 257 |
244 base::scoped_nsobject<BaseBubbleController> keep_alive = ShowBubble(); | 258 base::scoped_nsobject<BaseBubbleController> keep_alive = ShowBubble(); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 [panel close]; | 388 [panel close]; |
375 | 389 |
376 EXPECT_FALSE([bubble_window_ attachedSheet]); | 390 EXPECT_FALSE([bubble_window_ attachedSheet]); |
377 EXPECT_TRUE([bubble_window_ isVisible]); | 391 EXPECT_TRUE([bubble_window_ isVisible]); |
378 EXPECT_FALSE([panel isVisible]); | 392 EXPECT_FALSE([panel isVisible]); |
379 | 393 |
380 // Now that the sheet is gone, a key status change should close the bubble. | 394 // Now that the sheet is gone, a key status change should close the bubble. |
381 SimulateKeyStatusChange(); | 395 SimulateKeyStatusChange(); |
382 EXPECT_FALSE([bubble_window_ isVisible]); | 396 EXPECT_FALSE([bubble_window_ isVisible]); |
383 } | 397 } |
OLD | NEW |