Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / info_bubble_window_unittest.mm
blob4c0f5fb490808ee093b1ad445416ceab87b20516
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;
16 @end
18 @implementation InfoBubbleWindowController
19 - (IBAction)cancel:(id)sender {
20   [self close];
22 @end
24 class InfoBubbleWindowTest : public CocoaTest {
25  public:
26   void SetUp() override {
27     CocoaTest::SetUp();
28     window_.reset(
29         [[InfoBubbleWindow alloc] initWithContentRect:NSMakeRect(0, 0, 10, 10)
30                                             styleMask:NSBorderlessWindowMask
31                                               backing:NSBackingStoreBuffered
32                                                 defer:NO]);
33     [window_ setAllowedAnimations:info_bubble::kAnimateNone];
34     controller_.reset(
35         [[InfoBubbleWindowController alloc] initWithWindow:window_]);
36   }
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
41     // close.
42     [controller_ close];
43     chrome::testing::NSRunLoopRunAllPending();
44     controller_.reset();
45     window_.reset();
47     CocoaTest::TearDown();
48   }
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,
76                                     NSCommandKeyMask)];
77   EXPECT_FALSE([window_ isVisible]);