| 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/memory/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" |
| 11 #import "chrome/browser/ui/cocoa/run_loop_testing.h" | 11 #import "chrome/browser/ui/cocoa/run_loop_testing.h" |
| 12 #import "ui/base/test/cocoa_test_event_utils.h" | 12 #import "ui/base/test/cocoa_test_event_utils.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 const CGFloat kBubbleWindowWidth = 100; | 15 const CGFloat kBubbleWindowWidth = 100; |
| 16 const CGFloat kBubbleWindowHeight = 50; | 16 const CGFloat kBubbleWindowHeight = 50; |
| 17 const CGFloat kAnchorPointX = 400; | 17 const CGFloat kAnchorPointX = 400; |
| 18 const CGFloat kAnchorPointY = 300; | 18 const CGFloat kAnchorPointY = 300; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 37 } | 37 } |
| 38 | 38 |
| 39 virtual void TearDown() OVERRIDE { | 39 virtual void TearDown() OVERRIDE { |
| 40 // Close our windows. | 40 // Close our windows. |
| 41 [controller_ close]; | 41 [controller_ close]; |
| 42 bubbleWindow_.reset(NULL); | 42 bubbleWindow_.reset(NULL); |
| 43 CocoaTest::TearDown(); | 43 CocoaTest::TearDown(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 public: | 46 public: |
| 47 scoped_nsobject<NSWindow> bubbleWindow_; | 47 base::scoped_nsobject<NSWindow> bubbleWindow_; |
| 48 BaseBubbleController* controller_; | 48 BaseBubbleController* controller_; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 // Test that kAlignEdgeToAnchorEdge and a left bubble arrow correctly aligns the | 51 // Test that kAlignEdgeToAnchorEdge and a left bubble arrow correctly aligns the |
| 52 // left edge of the buble to the anchor point. | 52 // left edge of the buble to the anchor point. |
| 53 TEST_F(BaseBubbleControllerTest, LeftAlign) { | 53 TEST_F(BaseBubbleControllerTest, LeftAlign) { |
| 54 [[controller_ bubble] setArrowLocation:info_bubble::kTopLeft]; | 54 [[controller_ bubble] setArrowLocation:info_bubble::kTopLeft]; |
| 55 [[controller_ bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; | 55 [[controller_ bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; |
| 56 [controller_ showWindow:nil]; | 56 [controller_ showWindow:nil]; |
| 57 | 57 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // Make sure the bubble arrow points to the anchor. | 111 // Make sure the bubble arrow points to the anchor. |
| 112 EXPECT_EQ(NSMaxX(frame) - info_bubble::kBubbleArrowXOffset - | 112 EXPECT_EQ(NSMaxX(frame) - info_bubble::kBubbleArrowXOffset - |
| 113 floorf(info_bubble::kBubbleArrowWidth / 2.0), kAnchorPointX); | 113 floorf(info_bubble::kBubbleArrowWidth / 2.0), kAnchorPointX); |
| 114 EXPECT_GE(NSMaxY(frame), kAnchorPointY); | 114 EXPECT_GE(NSMaxY(frame), kAnchorPointY); |
| 115 } | 115 } |
| 116 | 116 |
| 117 // Tests that when a new window gets key state (and the bubble resigns) that | 117 // Tests that when a new window gets key state (and the bubble resigns) that |
| 118 // the key window changes. | 118 // the key window changes. |
| 119 TEST_F(BaseBubbleControllerTest, ResignKeyCloses) { | 119 TEST_F(BaseBubbleControllerTest, ResignKeyCloses) { |
| 120 // Closing the bubble will autorelease the controller. | 120 // Closing the bubble will autorelease the controller. |
| 121 scoped_nsobject<BaseBubbleController> keep_alive([controller_ retain]); | 121 base::scoped_nsobject<BaseBubbleController> keep_alive([controller_ retain]); |
| 122 | 122 |
| 123 NSWindow* bubble_window = [controller_ window]; | 123 NSWindow* bubble_window = [controller_ window]; |
| 124 EXPECT_FALSE([bubble_window isVisible]); | 124 EXPECT_FALSE([bubble_window isVisible]); |
| 125 | 125 |
| 126 scoped_nsobject<NSWindow> other_window( | 126 base::scoped_nsobject<NSWindow> other_window( |
| 127 [[NSWindow alloc] initWithContentRect:NSMakeRect(500, 500, 500, 500) | 127 [[NSWindow alloc] initWithContentRect:NSMakeRect(500, 500, 500, 500) |
| 128 styleMask:NSTitledWindowMask | 128 styleMask:NSTitledWindowMask |
| 129 backing:NSBackingStoreBuffered | 129 backing:NSBackingStoreBuffered |
| 130 defer:YES]); | 130 defer:YES]); |
| 131 EXPECT_FALSE([other_window isVisible]); | 131 EXPECT_FALSE([other_window isVisible]); |
| 132 | 132 |
| 133 [controller_ showWindow:nil]; | 133 [controller_ showWindow:nil]; |
| 134 EXPECT_TRUE([bubble_window isVisible]); | 134 EXPECT_TRUE([bubble_window isVisible]); |
| 135 EXPECT_FALSE([other_window isVisible]); | 135 EXPECT_FALSE([other_window isVisible]); |
| 136 | 136 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 156 EXPECT_TRUE([other_window isVisible]); | 156 EXPECT_TRUE([other_window isVisible]); |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Test that clicking outside the window causes the bubble to close. | 159 // Test that clicking outside the window causes the bubble to close. |
| 160 TEST_F(BaseBubbleControllerTest, LionClickOutsideCloses) { | 160 TEST_F(BaseBubbleControllerTest, LionClickOutsideCloses) { |
| 161 // The event tap is only installed on 10.7+. | 161 // The event tap is only installed on 10.7+. |
| 162 if (!base::mac::IsOSLionOrLater()) | 162 if (!base::mac::IsOSLionOrLater()) |
| 163 return; | 163 return; |
| 164 | 164 |
| 165 // Closing the bubble will autorelease the controller. | 165 // Closing the bubble will autorelease the controller. |
| 166 scoped_nsobject<BaseBubbleController> keep_alive([controller_ retain]); | 166 base::scoped_nsobject<BaseBubbleController> keep_alive([controller_ retain]); |
| 167 NSWindow* window = [controller_ window]; | 167 NSWindow* window = [controller_ window]; |
| 168 | 168 |
| 169 EXPECT_FALSE([window isVisible]); | 169 EXPECT_FALSE([window isVisible]); |
| 170 | 170 |
| 171 [controller_ showWindow:nil]; | 171 [controller_ showWindow:nil]; |
| 172 | 172 |
| 173 EXPECT_TRUE([window isVisible]); | 173 EXPECT_TRUE([window isVisible]); |
| 174 | 174 |
| 175 NSEvent* event = cocoa_test_event_utils::LeftMouseDownAtPointInWindow( | 175 NSEvent* event = cocoa_test_event_utils::LeftMouseDownAtPointInWindow( |
| 176 NSMakePoint(10, 10), test_window()); | 176 NSMakePoint(10, 10), test_window()); |
| 177 [NSApp sendEvent:event]; | 177 [NSApp sendEvent:event]; |
| 178 chrome::testing::NSRunLoopRunAllPending(); | 178 chrome::testing::NSRunLoopRunAllPending(); |
| 179 | 179 |
| 180 EXPECT_FALSE([window isVisible]); | 180 EXPECT_FALSE([window isVisible]); |
| 181 } | 181 } |
| OLD | NEW |