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