| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_view_controller.h" | 5 #import "ui/message_center/cocoa/tray_view_controller.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/memory/scoped_nsobject.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.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" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 TEST_F(TrayViewControllerTest, AddRemoveOne) { | 36 TEST_F(TrayViewControllerTest, AddRemoveOne) { |
| 37 NSScrollView* view = [[tray_ scrollView] documentView]; | 37 NSScrollView* view = [[tray_ scrollView] documentView]; |
| 38 EXPECT_EQ(0u, [[view subviews] count]); | 38 EXPECT_EQ(0u, [[view subviews] count]); |
| 39 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, | 39 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, |
| 40 "1", | 40 "1", |
| 41 ASCIIToUTF16("First notification"), | 41 ASCIIToUTF16("First notification"), |
| 42 ASCIIToUTF16("This is a simple test."), | 42 ASCIIToUTF16("This is a simple test."), |
| 43 string16(), | 43 string16(), |
| 44 std::string(), | 44 std::string(), |
| 45 NULL, |
| 45 NULL); | 46 NULL); |
| 46 [tray_ onMessageCenterTrayChanged]; | 47 [tray_ onMessageCenterTrayChanged]; |
| 47 ASSERT_EQ(1u, [[view subviews] count]); | 48 ASSERT_EQ(1u, [[view subviews] count]); |
| 48 | 49 |
| 49 // The view should have padding around it. | 50 // The view should have padding around it. |
| 50 NSView* notification = [[view subviews] objectAtIndex:0]; | 51 NSView* notification = [[view subviews] objectAtIndex:0]; |
| 51 NSRect notification_frame = [notification frame]; | 52 NSRect notification_frame = [notification frame]; |
| 52 EXPECT_CGFLOAT_EQ(2 * message_center::kMarginBetweenItems, | 53 EXPECT_CGFLOAT_EQ(2 * message_center::kMarginBetweenItems, |
| 53 NSHeight([view frame]) - NSHeight(notification_frame)); | 54 NSHeight([view frame]) - NSHeight(notification_frame)); |
| 54 EXPECT_CGFLOAT_EQ(2 * message_center::kMarginBetweenItems, | 55 EXPECT_CGFLOAT_EQ(2 * message_center::kMarginBetweenItems, |
| 55 NSWidth([view frame]) - NSWidth(notification_frame)); | 56 NSWidth([view frame]) - NSWidth(notification_frame)); |
| 56 EXPECT_GT(NSHeight([[tray_ view] frame]), | 57 EXPECT_GT(NSHeight([[tray_ view] frame]), |
| 57 NSHeight([[tray_ scrollView] frame])); | 58 NSHeight([[tray_ scrollView] frame])); |
| 58 | 59 |
| 59 center_->RemoveNotification("1", true); | 60 center_->RemoveNotification("1", true); |
| 60 [tray_ onMessageCenterTrayChanged]; | 61 [tray_ onMessageCenterTrayChanged]; |
| 61 EXPECT_EQ(0u, [[view subviews] count]); | 62 EXPECT_EQ(0u, [[view subviews] count]); |
| 62 EXPECT_CGFLOAT_EQ(0, NSHeight([view frame])); | 63 EXPECT_CGFLOAT_EQ(0, NSHeight([view frame])); |
| 63 } | 64 } |
| 64 | 65 |
| 65 TEST_F(TrayViewControllerTest, AddThreeClearAll) { | 66 TEST_F(TrayViewControllerTest, AddThreeClearAll) { |
| 66 NSScrollView* view = [[tray_ scrollView] documentView]; | 67 NSScrollView* view = [[tray_ scrollView] documentView]; |
| 67 EXPECT_EQ(0u, [[view subviews] count]); | 68 EXPECT_EQ(0u, [[view subviews] count]); |
| 68 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, | 69 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, |
| 69 "1", | 70 "1", |
| 70 ASCIIToUTF16("First notification"), | 71 ASCIIToUTF16("First notification"), |
| 71 ASCIIToUTF16("This is a simple test."), | 72 ASCIIToUTF16("This is a simple test."), |
| 72 string16(), | 73 string16(), |
| 73 std::string(), | 74 std::string(), |
| 75 NULL, |
| 74 NULL); | 76 NULL); |
| 75 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, | 77 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, |
| 76 "2", | 78 "2", |
| 77 ASCIIToUTF16("Second notification"), | 79 ASCIIToUTF16("Second notification"), |
| 78 ASCIIToUTF16("This is a simple test."), | 80 ASCIIToUTF16("This is a simple test."), |
| 79 string16(), | 81 string16(), |
| 80 std::string(), | 82 std::string(), |
| 83 NULL, |
| 81 NULL); | 84 NULL); |
| 82 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, | 85 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, |
| 83 "3", | 86 "3", |
| 84 ASCIIToUTF16("Third notification"), | 87 ASCIIToUTF16("Third notification"), |
| 85 ASCIIToUTF16("This is a simple test."), | 88 ASCIIToUTF16("This is a simple test."), |
| 86 string16(), | 89 string16(), |
| 87 std::string(), | 90 std::string(), |
| 91 NULL, |
| 88 NULL); | 92 NULL); |
| 89 [tray_ onMessageCenterTrayChanged]; | 93 [tray_ onMessageCenterTrayChanged]; |
| 90 ASSERT_EQ(3u, [[view subviews] count]); | 94 ASSERT_EQ(3u, [[view subviews] count]); |
| 91 | 95 |
| 92 [tray_ clearAllNotifications:nil]; | 96 [tray_ clearAllNotifications:nil]; |
| 93 [tray_ onMessageCenterTrayChanged]; | 97 [tray_ onMessageCenterTrayChanged]; |
| 94 | 98 |
| 95 EXPECT_EQ(0u, [[view subviews] count]); | 99 EXPECT_EQ(0u, [[view subviews] count]); |
| 96 EXPECT_CGFLOAT_EQ(0, NSHeight([view frame])); | 100 EXPECT_CGFLOAT_EQ(0, NSHeight([view frame])); |
| 97 } | 101 } |
| 98 | 102 |
| 99 TEST_F(TrayViewControllerTest, NoClearAllWhenNoNotifications) { | 103 TEST_F(TrayViewControllerTest, NoClearAllWhenNoNotifications) { |
| 100 EXPECT_TRUE([tray_ pauseButton]); | 104 EXPECT_TRUE([tray_ pauseButton]); |
| 101 EXPECT_TRUE([tray_ clearAllButton]); | 105 EXPECT_TRUE([tray_ clearAllButton]); |
| 102 | 106 |
| 103 // With no notifications, the clear all button should be hidden. | 107 // With no notifications, the clear all button should be hidden. |
| 104 EXPECT_TRUE([[tray_ clearAllButton] isHidden]); | 108 EXPECT_TRUE([[tray_ clearAllButton] isHidden]); |
| 105 EXPECT_LT(NSMinX([[tray_ clearAllButton] frame]), | 109 EXPECT_LT(NSMinX([[tray_ clearAllButton] frame]), |
| 106 NSMinX([[tray_ pauseButton] frame])); | 110 NSMinX([[tray_ pauseButton] frame])); |
| 107 | 111 |
| 108 // Add a notification. | 112 // Add a notification. |
| 109 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, | 113 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, |
| 110 "1", | 114 "1", |
| 111 ASCIIToUTF16("First notification"), | 115 ASCIIToUTF16("First notification"), |
| 112 ASCIIToUTF16("This is a simple test."), | 116 ASCIIToUTF16("This is a simple test."), |
| 113 string16(), | 117 string16(), |
| 114 std::string(), | 118 std::string(), |
| 119 NULL, |
| 115 NULL); | 120 NULL); |
| 116 [tray_ onMessageCenterTrayChanged]; | 121 [tray_ onMessageCenterTrayChanged]; |
| 117 | 122 |
| 118 // Clear all should now be visible. | 123 // Clear all should now be visible. |
| 119 EXPECT_FALSE([[tray_ clearAllButton] isHidden]); | 124 EXPECT_FALSE([[tray_ clearAllButton] isHidden]); |
| 120 EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]), | 125 EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]), |
| 121 NSMinX([[tray_ pauseButton] frame])); | 126 NSMinX([[tray_ pauseButton] frame])); |
| 122 | 127 |
| 123 // Adding a second notification should keep things still visible. | 128 // Adding a second notification should keep things still visible. |
| 124 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, | 129 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, |
| 125 "2", | 130 "2", |
| 126 ASCIIToUTF16("Second notification"), | 131 ASCIIToUTF16("Second notification"), |
| 127 ASCIIToUTF16("This is a simple test."), | 132 ASCIIToUTF16("This is a simple test."), |
| 128 string16(), | 133 string16(), |
| 129 std::string(), | 134 std::string(), |
| 135 NULL, |
| 130 NULL); | 136 NULL); |
| 131 [tray_ onMessageCenterTrayChanged]; | 137 [tray_ onMessageCenterTrayChanged]; |
| 132 EXPECT_FALSE([[tray_ clearAllButton] isHidden]); | 138 EXPECT_FALSE([[tray_ clearAllButton] isHidden]); |
| 133 EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]), | 139 EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]), |
| 134 NSMinX([[tray_ pauseButton] frame])); | 140 NSMinX([[tray_ pauseButton] frame])); |
| 135 | 141 |
| 136 // Clear all notifications. | 142 // Clear all notifications. |
| 137 [tray_ clearAllNotifications:nil]; | 143 [tray_ clearAllNotifications:nil]; |
| 138 [tray_ onMessageCenterTrayChanged]; | 144 [tray_ onMessageCenterTrayChanged]; |
| 139 | 145 |
| 140 // The button should be hidden again. | 146 // The button should be hidden again. |
| 141 EXPECT_TRUE([[tray_ clearAllButton] isHidden]); | 147 EXPECT_TRUE([[tray_ clearAllButton] isHidden]); |
| 142 EXPECT_LT(NSMinX([[tray_ clearAllButton] frame]), | 148 EXPECT_LT(NSMinX([[tray_ clearAllButton] frame]), |
| 143 NSMinX([[tray_ pauseButton] frame])); | 149 NSMinX([[tray_ pauseButton] frame])); |
| 144 } | 150 } |
| OLD | NEW |