| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #import "ui/message_center/cocoa/tray_controller.h" | |
| 6 | |
| 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" | |
| 12 | |
| 13 namespace message_center { | |
| 14 | |
| 15 class TrayControllerTest : public ui::CocoaTest { | |
| 16 public: | |
| 17 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())); | |
| 22 controller_.reset( | |
| 23 [[MCTrayController alloc] initWithMessageCenterTray:tray_.get()]); | |
| 24 } | |
| 25 | |
| 26 void TearDown() override { | |
| 27 controller_.reset(); | |
| 28 tray_.reset(); | |
| 29 message_center::MessageCenter::Shutdown(); | |
| 30 ui::CocoaTest::TearDown(); | |
| 31 } | |
| 32 | |
| 33 protected: | |
| 34 scoped_ptr<message_center::MessageCenterTray> tray_; | |
| 35 base::scoped_nsobject<MCTrayController> controller_; | |
| 36 }; | |
| 37 | |
| 38 TEST_F(TrayControllerTest, OpenLeftRight) { | |
| 39 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | |
| 40 NSRect screen_frame = [screen visibleFrame]; | |
| 41 | |
| 42 const CGFloat y = NSMaxY(screen_frame); | |
| 43 | |
| 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); | |
| 47 | |
| 48 [controller_ showTrayAtRightOf:right_point atLeftOf:left_point]; | |
| 49 NSRect window_frame = [[controller_ window] frame]; | |
| 50 EXPECT_EQ(right_point.x, NSMinX(window_frame)); | |
| 51 | |
| 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)); | |
| 57 } | |
| 58 | |
| 59 } // namespace message_center | |
| OLD | NEW |