1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 #include <Carbon/Carbon.h>
6 #include "base/debug/debugger.h"
7 #include "base/mac/scoped_nsobject.h"
8 #include "base/run_loop.h"
9 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
10 #include "chrome/browser/ui/cocoa/info_bubble_window.h"
11 #include "chrome/browser/ui/cocoa/run_loop_testing.h"
12 #include "ui/events/test/cocoa_test_event_utils.h"
14 @interface InfoBubbleWindowController : NSWindowController
15 - (IBAction)cancel:(id)sender;
18 @implementation InfoBubbleWindowController
19 - (IBAction)cancel:(id)sender {
24 class InfoBubbleWindowTest : public CocoaTest {
26 void SetUp() override {
29 [[InfoBubbleWindow alloc] initWithContentRect:NSMakeRect(0, 0, 10, 10)
30 styleMask:NSBorderlessWindowMask
31 backing:NSBackingStoreBuffered
33 [window_ setAllowedAnimations:info_bubble::kAnimateNone];
35 [[InfoBubbleWindowController alloc] initWithWindow:window_]);
38 void TearDown() override {
39 // Both controller and window need to be closed & released before TearDown,
40 // or CocoaTest will consider the window still open and spinwait for it to
43 chrome::testing::NSRunLoopRunAllPending();
47 CocoaTest::TearDown();
50 base::scoped_nsobject<InfoBubbleWindow> window_;
51 base::scoped_nsobject<NSWindowController> controller_;
54 TEST_F(InfoBubbleWindowTest, Basics2) {
55 EXPECT_TRUE([window_ canBecomeKeyWindow]);
56 EXPECT_FALSE([window_ canBecomeMainWindow]);
58 EXPECT_TRUE([window_ isExcludedFromWindowsMenu]);
61 TEST_F(InfoBubbleWindowTest, EscapeCloses) {
62 [controller_ showWindow:nil];
63 EXPECT_TRUE([window_ isVisible]);
65 [window_ performKeyEquivalent:cocoa_test_event_utils::KeyEventWithKeyCode(
66 kVK_Escape, '\e', NSKeyDown, 0)];
67 EXPECT_FALSE([window_ isVisible]);
70 TEST_F(InfoBubbleWindowTest, CommandPeriodCloses) {
71 [controller_ showWindow:nil];
72 EXPECT_TRUE([window_ isVisible]);
74 [window_ performKeyEquivalent:cocoa_test_event_utils::KeyEventWithKeyCode(
75 kVK_ANSI_Period, '.', NSKeyDown,
77 EXPECT_FALSE([window_ isVisible]);