1 // Copyright 2013 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.
5 #import "ui/message_center/cocoa/tray_controller.h"
7 #include "base/mac/scoped_nsobject.h"
8 #include "base/memory/scoped_ptr.h"
9 #import "ui/gfx/test/ui_cocoa_test_helper.h"
10 #include "ui/message_center/message_center.h"
11 #include "ui/message_center/message_center_tray.h"
13 namespace message_center {
15 class TrayControllerTest : public ui::CocoaTest {
17 virtual void SetUp() OVERRIDE {
18 ui::CocoaTest::SetUp();
19 message_center::MessageCenter::Initialize();
20 tray_.reset(new message_center::MessageCenterTray(
21 NULL, message_center::MessageCenter::Get()));
23 [[MCTrayController alloc] initWithMessageCenterTray:tray_.get()]);
26 virtual void TearDown() OVERRIDE {
29 message_center::MessageCenter::Shutdown();
30 ui::CocoaTest::TearDown();
34 scoped_ptr<message_center::MessageCenterTray> tray_;
35 base::scoped_nsobject<MCTrayController> controller_;
38 TEST_F(TrayControllerTest, OpenLeftRight) {
39 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
40 NSRect screen_frame = [screen visibleFrame];
42 const CGFloat y = NSMaxY(screen_frame);
44 // With ample room to the right, it should open to the right.
45 NSPoint right_point = NSMakePoint(0, y);
46 NSPoint left_point = NSMakePoint(NSMaxX(screen_frame), y);
48 [controller_ showTrayAtRightOf:right_point atLeftOf:left_point];
49 NSRect window_frame = [[controller_ window] frame];
50 EXPECT_EQ(right_point.x, NSMinX(window_frame));
52 // With little room on the right, it should open to the left.
53 right_point = NSMakePoint(NSMaxX(screen_frame) - 10, y);
54 [controller_ showTrayAtRightOf:right_point atLeftOf:left_point];
55 window_frame = [[controller_ window] frame];
56 EXPECT_EQ(left_point.x - NSWidth(window_frame), NSMinX(window_frame));
59 } // namespace message_center