| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 if (base::mac::IsOSLionOrLater()) | 149 if (base::mac::IsOSLionOrLater()) |
| 150 [[NSNotificationCenter defaultCenter] postNotification:notif]; | 150 [[NSNotificationCenter defaultCenter] postNotification:notif]; |
| 151 else | 151 else |
| 152 [controller_ windowDidResignKey:notif]; | 152 [controller_ windowDidResignKey:notif]; |
| 153 | 153 |
| 154 | 154 |
| 155 EXPECT_FALSE([bubble_window isVisible]); | 155 EXPECT_FALSE([bubble_window isVisible]); |
| 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 if |
| 160 // shouldCloseOnResignKey is YES. |
| 160 TEST_F(BaseBubbleControllerTest, LionClickOutsideCloses) { | 161 TEST_F(BaseBubbleControllerTest, LionClickOutsideCloses) { |
| 161 // The event tap is only installed on 10.7+. | 162 // The event tap is only installed on 10.7+. |
| 162 if (!base::mac::IsOSLionOrLater()) | 163 if (!base::mac::IsOSLionOrLater()) |
| 163 return; | 164 return; |
| 164 | 165 |
| 165 // Closing the bubble will autorelease the controller. | 166 // Closing the bubble will autorelease the controller. |
| 166 base::scoped_nsobject<BaseBubbleController> keep_alive([controller_ retain]); | 167 base::scoped_nsobject<BaseBubbleController> keep_alive([controller_ retain]); |
| 167 NSWindow* window = [controller_ window]; | 168 NSWindow* window = [controller_ window]; |
| 168 | 169 |
| 170 EXPECT_TRUE([controller_ shouldCloseOnResignKey]); // Verify default value. |
| 169 EXPECT_FALSE([window isVisible]); | 171 EXPECT_FALSE([window isVisible]); |
| 170 | 172 |
| 171 [controller_ showWindow:nil]; | 173 [controller_ showWindow:nil]; |
| 172 | 174 |
| 173 EXPECT_TRUE([window isVisible]); | 175 EXPECT_TRUE([window isVisible]); |
| 174 | 176 |
| 177 [controller_ setShouldCloseOnResignKey:NO]; |
| 175 NSEvent* event = cocoa_test_event_utils::LeftMouseDownAtPointInWindow( | 178 NSEvent* event = cocoa_test_event_utils::LeftMouseDownAtPointInWindow( |
| 176 NSMakePoint(10, 10), test_window()); | 179 NSMakePoint(10, 10), test_window()); |
| 177 [NSApp sendEvent:event]; | 180 [NSApp sendEvent:event]; |
| 178 chrome::testing::NSRunLoopRunAllPending(); | 181 chrome::testing::NSRunLoopRunAllPending(); |
| 179 | 182 |
| 183 EXPECT_TRUE([window isVisible]); |
| 184 |
| 185 [controller_ setShouldCloseOnResignKey:YES]; |
| 186 event = cocoa_test_event_utils::LeftMouseDownAtPointInWindow( |
| 187 NSMakePoint(10, 10), test_window()); |
| 188 [NSApp sendEvent:event]; |
| 189 chrome::testing::NSRunLoopRunAllPending(); |
| 190 |
| 180 EXPECT_FALSE([window isVisible]); | 191 EXPECT_FALSE([window isVisible]); |
| 181 } | 192 } |
| OLD | NEW |