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

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

Issue 15582004: Move NotificationDelegate into message_center. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix the ever-changing Mac unit tests. Created 7 years, 7 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/popup_collection.h" 5 #import "ui/message_center/cocoa/popup_collection.h"
6 6
7 #include "base/memory/scoped_nsobject.h" 7 #include "base/memory/scoped_nsobject.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 } 47 }
48 48
49 void AddThreeNotifications() { 49 void AddThreeNotifications() {
50 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 50 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
51 "1", 51 "1",
52 ASCIIToUTF16("One"), 52 ASCIIToUTF16("One"),
53 ASCIIToUTF16("This is the first notification to" 53 ASCIIToUTF16("This is the first notification to"
54 " be displayed"), 54 " be displayed"),
55 string16(), 55 string16(),
56 std::string(), 56 std::string(),
57 NULL,
57 NULL); 58 NULL);
58 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 59 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
59 "2", 60 "2",
60 ASCIIToUTF16("Two"), 61 ASCIIToUTF16("Two"),
61 ASCIIToUTF16("This is the second notification."), 62 ASCIIToUTF16("This is the second notification."),
62 string16(), 63 string16(),
63 std::string(), 64 std::string(),
65 NULL,
64 NULL); 66 NULL);
65 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 67 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
66 "3", 68 "3",
67 ASCIIToUTF16("Three"), 69 ASCIIToUTF16("Three"),
68 ASCIIToUTF16("This is the third notification " 70 ASCIIToUTF16("This is the third notification "
69 "that has a much longer body " 71 "that has a much longer body "
70 "than the other notifications. It " 72 "than the other notifications. It "
71 "may not fit on the screen if we " 73 "may not fit on the screen if we "
72 "set the screen size too small."), 74 "set the screen size too small."),
73 string16(), 75 string16(),
74 std::string(), 76 std::string(),
77 NULL,
75 NULL); 78 NULL);
76 79
77 WaitForAnimationEnded(); 80 WaitForAnimationEnded();
78 } 81 }
79 82
80 bool CheckSpacingBetween(MCPopupController* upper, MCPopupController* lower) { 83 bool CheckSpacingBetween(MCPopupController* upper, MCPopupController* lower) {
81 CGFloat minY = NSMinY([[upper window] frame]); 84 CGFloat minY = NSMinY([[upper window] frame]);
82 CGFloat maxY = NSMaxY([[lower window] frame]); 85 CGFloat maxY = NSMaxY([[lower window] frame]);
83 CGFloat delta = minY - maxY; 86 CGFloat delta = minY - maxY;
84 EXPECT_EQ(message_center::kMarginBetweenItems, delta); 87 EXPECT_EQ(message_center::kMarginBetweenItems, delta);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 EXPECT_EQ(0u, [[collection_ popups] count]); 123 EXPECT_EQ(0u, [[collection_ popups] count]);
121 AddThreeNotifications(); 124 AddThreeNotifications();
122 EXPECT_EQ(2u, [[collection_ popups] count]); // "3" does not fit on screen. 125 EXPECT_EQ(2u, [[collection_ popups] count]); // "3" does not fit on screen.
123 126
124 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 127 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
125 "4", 128 "4",
126 ASCIIToUTF16("Four"), 129 ASCIIToUTF16("Four"),
127 ASCIIToUTF16("This is the fourth notification."), 130 ASCIIToUTF16("This is the fourth notification."),
128 string16(), 131 string16(),
129 std::string(), 132 std::string(),
133 NULL,
130 NULL); 134 NULL);
131 WaitForAnimationEnded(); 135 WaitForAnimationEnded();
132 136
133 // Remove "1" and "3" should fit on screen. 137 // Remove "1" and "3" should fit on screen.
134 center_->RemoveNotification("1", true); 138 center_->RemoveNotification("1", true);
135 WaitForAnimationEnded(); 139 WaitForAnimationEnded();
136 ASSERT_EQ(2u, [[collection_ popups] count]); 140 ASSERT_EQ(2u, [[collection_ popups] count]);
137 141
138 EXPECT_EQ("2", [[[collection_ popups] objectAtIndex:0] notificationID]); 142 EXPECT_EQ("2", [[[collection_ popups] objectAtIndex:0] notificationID]);
139 EXPECT_EQ("3", [[[collection_ popups] objectAtIndex:1] notificationID]); 143 EXPECT_EQ("3", [[[collection_ popups] objectAtIndex:1] notificationID]);
(...skipping 25 matching lines...) Expand all
165 // Set priority so that kMaxVisiblePopupNotifications does not hide it. 169 // Set priority so that kMaxVisiblePopupNotifications does not hide it.
166 scoped_ptr<base::DictionaryValue> optional(new base::DictionaryValue); 170 scoped_ptr<base::DictionaryValue> optional(new base::DictionaryValue);
167 optional->SetInteger(message_center::kPriorityKey, 171 optional->SetInteger(message_center::kPriorityKey,
168 message_center::HIGH_PRIORITY); 172 message_center::HIGH_PRIORITY);
169 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 173 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
170 "4", 174 "4",
171 ASCIIToUTF16("Four"), 175 ASCIIToUTF16("Four"),
172 ASCIIToUTF16("This is the fourth notification."), 176 ASCIIToUTF16("This is the fourth notification."),
173 string16(), 177 string16(),
174 std::string(), 178 std::string(),
175 optional.get()); 179 optional.get(),
180 NULL);
176 WaitForAnimationEnded(); 181 WaitForAnimationEnded();
177 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:2], 182 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:2],
178 [popups objectAtIndex:3])); 183 [popups objectAtIndex:3]));
179 184
180 // Remove "2". 185 // Remove "2".
181 center_->RemoveNotification("2", true); 186 center_->RemoveNotification("2", true);
182 WaitForAnimationEnded(); 187 WaitForAnimationEnded();
183 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0], 188 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0],
184 [popups objectAtIndex:1])); 189 [popups objectAtIndex:1]));
185 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1], 190 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1],
(...skipping 12 matching lines...) Expand all
198 [collection_ setScreenFrame:NSMakeRect(0, 0, 800, 100)]; 203 [collection_ setScreenFrame:NSMakeRect(0, 0, 800, 100)];
199 204
200 EXPECT_EQ(0u, [[collection_ popups] count]); 205 EXPECT_EQ(0u, [[collection_ popups] count]);
201 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 206 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
202 "1", 207 "1",
203 ASCIIToUTF16("One"), 208 ASCIIToUTF16("One"),
204 ASCIIToUTF16("This is the first notification to" 209 ASCIIToUTF16("This is the first notification to"
205 " be displayed"), 210 " be displayed"),
206 string16(), 211 string16(),
207 std::string(), 212 std::string(),
213 NULL,
208 NULL); 214 NULL);
209 WaitForAnimationEnded(); 215 WaitForAnimationEnded();
210 EXPECT_EQ(1u, [[collection_ popups] count]); 216 EXPECT_EQ(1u, [[collection_ popups] count]);
211 217
212 // Now give the notification a longer message so that it no longer fits. 218 // Now give the notification a longer message so that it no longer fits.
213 center_->UpdateNotification("1", 219 center_->UpdateNotification("1",
214 "1", 220 "1",
215 ASCIIToUTF16("One"), 221 ASCIIToUTF16("One"),
216 ASCIIToUTF16("This is now a very very very very " 222 ASCIIToUTF16("This is now a very very very very "
217 "very very very very very very very " 223 "very very very very very very very "
218 "very very very very very very very " 224 "very very very very very very very "
219 "very very very very very very very " 225 "very very very very very very very "
220 "very very very very very very very " 226 "very very very very very very very "
221 "very very very very very very very " 227 "very very very very very very very "
222 "very very very very very very very " 228 "very very very very very very very "
223 "long notification."), 229 "long notification."),
230 NULL,
224 NULL); 231 NULL);
225 WaitForAnimationEnded(); 232 WaitForAnimationEnded();
226 EXPECT_EQ(0u, [[collection_ popups] count]); 233 EXPECT_EQ(0u, [[collection_ popups] count]);
227 } 234 }
228 235
229 TEST_F(PopupCollectionTest, UpdateIconAndBody) { 236 TEST_F(PopupCollectionTest, UpdateIconAndBody) {
230 AddThreeNotifications(); 237 AddThreeNotifications();
231 NSArray* popups = [collection_ popups]; 238 NSArray* popups = [collection_ popups];
232 239
233 EXPECT_EQ(3u, [popups count]); 240 EXPECT_EQ(3u, [popups count]);
(...skipping 19 matching lines...) Expand all
253 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 260 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
254 "1", 261 "1",
255 ASCIIToUTF16("One is going to get a much longer " 262 ASCIIToUTF16("One is going to get a much longer "
256 "title than it previously had."), 263 "title than it previously had."),
257 ASCIIToUTF16("This is the first notification to " 264 ASCIIToUTF16("This is the first notification to "
258 "be displayed, but it will also be " 265 "be displayed, but it will also be "
259 "updated to have a significantly " 266 "updated to have a significantly "
260 "longer body"), 267 "longer body"),
261 string16(), 268 string16(),
262 std::string(), 269 std::string(),
270 NULL,
263 NULL); 271 NULL);
264 WaitForAnimationEnded(); 272 WaitForAnimationEnded();
265 EXPECT_GT(NSHeight([[controller view] frame]), NSHeight(old_frame)); 273 EXPECT_GT(NSHeight([[controller view] frame]), NSHeight(old_frame));
266 274
267 // Test updated spacing. 275 // Test updated spacing.
268 EXPECT_EQ(3u, [popups count]); 276 EXPECT_EQ(3u, [popups count]);
269 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0], 277 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0],
270 [popups objectAtIndex:1])); 278 [popups objectAtIndex:1]));
271 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1], 279 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1],
272 [popups objectAtIndex:2])); 280 [popups objectAtIndex:2]));
273 EXPECT_EQ("1", [[popups objectAtIndex:0] notificationID]); 281 EXPECT_EQ("1", [[popups objectAtIndex:0] notificationID]);
274 EXPECT_EQ("2", [[popups objectAtIndex:1] notificationID]); 282 EXPECT_EQ("2", [[popups objectAtIndex:1] notificationID]);
275 EXPECT_EQ("3", [[popups objectAtIndex:2] notificationID]); 283 EXPECT_EQ("3", [[popups objectAtIndex:2] notificationID]);
276 } 284 }
OLDNEW
« no previous file with comments | « ui/message_center/cocoa/notification_controller_unittest.mm ('k') | ui/message_center/cocoa/popup_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698