Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: ui/message_center/cocoa/tray_view_controller_unittest.mm

Issue 14631005: Enable users of NotificationUIManager to specify binary images. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase for relanding. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 18 matching lines...) Expand all
29 29
30 protected: 30 protected:
31 message_center::MessageCenter* center_; // Weak, global. 31 message_center::MessageCenter* center_; // Weak, global.
32 32
33 scoped_nsobject<MCTrayViewController> tray_; 33 scoped_nsobject<MCTrayViewController> tray_;
34 }; 34 };
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 scoped_ptr<message_center::Notification> notification_data;
40 "1", 40 notification_data.reset(new message_center::Notification(
41 ASCIIToUTF16("First notification"), 41 message_center::NOTIFICATION_TYPE_SIMPLE,
42 ASCIIToUTF16("This is a simple test."), 42 "1",
43 string16(), 43 ASCIIToUTF16("First notification"),
44 std::string(), 44 ASCIIToUTF16("This is a simple test."),
45 NULL, 45 gfx::Image(),
46 NULL); 46 string16(),
47 std::string(),
48 NULL,
49 NULL));
50 center_->AddNotification(notification_data.Pass());
47 [tray_ onMessageCenterTrayChanged]; 51 [tray_ onMessageCenterTrayChanged];
48 ASSERT_EQ(1u, [[view subviews] count]); 52 ASSERT_EQ(1u, [[view subviews] count]);
49 53
50 // The view should have padding around it. 54 // The view should have padding around it.
51 NSView* notification = [[view subviews] objectAtIndex:0]; 55 NSView* notification = [[view subviews] objectAtIndex:0];
52 NSRect notification_frame = [notification frame]; 56 NSRect notification_frame = [notification frame];
53 EXPECT_CGFLOAT_EQ(2 * message_center::kMarginBetweenItems, 57 EXPECT_CGFLOAT_EQ(2 * message_center::kMarginBetweenItems,
54 NSHeight([view frame]) - NSHeight(notification_frame)); 58 NSHeight([view frame]) - NSHeight(notification_frame));
55 EXPECT_CGFLOAT_EQ(2 * message_center::kMarginBetweenItems, 59 EXPECT_CGFLOAT_EQ(2 * message_center::kMarginBetweenItems,
56 NSWidth([view frame]) - NSWidth(notification_frame)); 60 NSWidth([view frame]) - NSWidth(notification_frame));
57 EXPECT_GT(NSHeight([[tray_ view] frame]), 61 EXPECT_GT(NSHeight([[tray_ view] frame]),
58 NSHeight([[tray_ scrollView] frame])); 62 NSHeight([[tray_ scrollView] frame]));
59 63
60 center_->RemoveNotification("1", true); 64 center_->RemoveNotification("1", true);
61 [tray_ onMessageCenterTrayChanged]; 65 [tray_ onMessageCenterTrayChanged];
62 EXPECT_EQ(0u, [[view subviews] count]); 66 EXPECT_EQ(0u, [[view subviews] count]);
63 EXPECT_CGFLOAT_EQ(0, NSHeight([view frame])); 67 EXPECT_CGFLOAT_EQ(0, NSHeight([view frame]));
64 } 68 }
65 69
66 TEST_F(TrayViewControllerTest, AddThreeClearAll) { 70 TEST_F(TrayViewControllerTest, AddThreeClearAll) {
67 NSScrollView* view = [[tray_ scrollView] documentView]; 71 NSScrollView* view = [[tray_ scrollView] documentView];
68 EXPECT_EQ(0u, [[view subviews] count]); 72 EXPECT_EQ(0u, [[view subviews] count]);
69 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 73 scoped_ptr<message_center::Notification> notification;
70 "1", 74 notification.reset(new message_center::Notification(
71 ASCIIToUTF16("First notification"), 75 message_center::NOTIFICATION_TYPE_SIMPLE,
72 ASCIIToUTF16("This is a simple test."), 76 "1",
73 string16(), 77 ASCIIToUTF16("First notification"),
74 std::string(), 78 ASCIIToUTF16("This is a simple test."),
75 NULL, 79 gfx::Image(),
76 NULL); 80 string16(),
77 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 81 std::string(),
78 "2", 82 NULL,
79 ASCIIToUTF16("Second notification"), 83 NULL));
80 ASCIIToUTF16("This is a simple test."), 84 center_->AddNotification(notification.Pass());
81 string16(), 85 notification.reset(new message_center::Notification(
82 std::string(), 86 message_center::NOTIFICATION_TYPE_SIMPLE,
83 NULL, 87 "2",
84 NULL); 88 ASCIIToUTF16("Second notification"),
85 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 89 ASCIIToUTF16("This is a simple test."),
86 "3", 90 gfx::Image(),
87 ASCIIToUTF16("Third notification"), 91 string16(),
88 ASCIIToUTF16("This is a simple test."), 92 std::string(),
89 string16(), 93 NULL,
90 std::string(), 94 NULL));
91 NULL, 95 center_->AddNotification(notification.Pass());
92 NULL); 96 notification.reset(new message_center::Notification(
97 message_center::NOTIFICATION_TYPE_SIMPLE,
98 "3",
99 ASCIIToUTF16("Third notification"),
100 ASCIIToUTF16("This is a simple test."),
101 gfx::Image(),
102 string16(),
103 std::string(),
104 NULL,
105 NULL));
106 center_->AddNotification(notification.Pass());
93 [tray_ onMessageCenterTrayChanged]; 107 [tray_ onMessageCenterTrayChanged];
94 ASSERT_EQ(3u, [[view subviews] count]); 108 ASSERT_EQ(3u, [[view subviews] count]);
95 109
96 [tray_ clearAllNotifications:nil]; 110 [tray_ clearAllNotifications:nil];
97 [tray_ onMessageCenterTrayChanged]; 111 [tray_ onMessageCenterTrayChanged];
98 112
99 EXPECT_EQ(0u, [[view subviews] count]); 113 EXPECT_EQ(0u, [[view subviews] count]);
100 EXPECT_CGFLOAT_EQ(0, NSHeight([view frame])); 114 EXPECT_CGFLOAT_EQ(0, NSHeight([view frame]));
101 } 115 }
102 116
103 TEST_F(TrayViewControllerTest, NoClearAllWhenNoNotifications) { 117 TEST_F(TrayViewControllerTest, NoClearAllWhenNoNotifications) {
104 EXPECT_TRUE([tray_ pauseButton]); 118 EXPECT_TRUE([tray_ pauseButton]);
105 EXPECT_TRUE([tray_ clearAllButton]); 119 EXPECT_TRUE([tray_ clearAllButton]);
106 120
107 // With no notifications, the clear all button should be hidden. 121 // With no notifications, the clear all button should be hidden.
108 EXPECT_TRUE([[tray_ clearAllButton] isHidden]); 122 EXPECT_TRUE([[tray_ clearAllButton] isHidden]);
109 EXPECT_LT(NSMinX([[tray_ clearAllButton] frame]), 123 EXPECT_LT(NSMinX([[tray_ clearAllButton] frame]),
110 NSMinX([[tray_ pauseButton] frame])); 124 NSMinX([[tray_ pauseButton] frame]));
111 125
112 // Add a notification. 126 // Add a notification.
113 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 127 scoped_ptr<message_center::Notification> notification;
114 "1", 128 notification.reset(new message_center::Notification(
115 ASCIIToUTF16("First notification"), 129 message_center::NOTIFICATION_TYPE_SIMPLE,
116 ASCIIToUTF16("This is a simple test."), 130 "1",
117 string16(), 131 ASCIIToUTF16("First notification"),
118 std::string(), 132 ASCIIToUTF16("This is a simple test."),
119 NULL, 133 gfx::Image(),
120 NULL); 134 string16(),
135 std::string(),
136 NULL,
137 NULL));
138 center_->AddNotification(notification.Pass());
121 [tray_ onMessageCenterTrayChanged]; 139 [tray_ onMessageCenterTrayChanged];
122 140
123 // Clear all should now be visible. 141 // Clear all should now be visible.
124 EXPECT_FALSE([[tray_ clearAllButton] isHidden]); 142 EXPECT_FALSE([[tray_ clearAllButton] isHidden]);
125 EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]), 143 EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]),
126 NSMinX([[tray_ pauseButton] frame])); 144 NSMinX([[tray_ pauseButton] frame]));
127 145
128 // Adding a second notification should keep things still visible. 146 // Adding a second notification should keep things still visible.
129 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 147 notification.reset(new message_center::Notification(
130 "2", 148 message_center::NOTIFICATION_TYPE_SIMPLE,
131 ASCIIToUTF16("Second notification"), 149 "2",
132 ASCIIToUTF16("This is a simple test."), 150 ASCIIToUTF16("Second notification"),
133 string16(), 151 ASCIIToUTF16("This is a simple test."),
134 std::string(), 152 gfx::Image(),
135 NULL, 153 string16(),
136 NULL); 154 std::string(),
155 NULL,
156 NULL));
157 center_->AddNotification(notification.Pass());
137 [tray_ onMessageCenterTrayChanged]; 158 [tray_ onMessageCenterTrayChanged];
138 EXPECT_FALSE([[tray_ clearAllButton] isHidden]); 159 EXPECT_FALSE([[tray_ clearAllButton] isHidden]);
139 EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]), 160 EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]),
140 NSMinX([[tray_ pauseButton] frame])); 161 NSMinX([[tray_ pauseButton] frame]));
141 162
142 // Clear all notifications. 163 // Clear all notifications.
143 [tray_ clearAllNotifications:nil]; 164 [tray_ clearAllNotifications:nil];
144 [tray_ onMessageCenterTrayChanged]; 165 [tray_ onMessageCenterTrayChanged];
145 166
146 // The button should be hidden again. 167 // The button should be hidden again.
147 EXPECT_TRUE([[tray_ clearAllButton] isHidden]); 168 EXPECT_TRUE([[tray_ clearAllButton] isHidden]);
148 EXPECT_LT(NSMinX([[tray_ clearAllButton] frame]), 169 EXPECT_LT(NSMinX([[tray_ clearAllButton] frame]),
149 NSMinX([[tray_ pauseButton] frame])); 170 NSMinX([[tray_ pauseButton] frame]));
150 } 171 }
OLDNEW
« no previous file with comments | « ui/message_center/cocoa/popup_controller_unittest.mm ('k') | ui/message_center/fake_message_center.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698