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

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: Copy delegate in notification update too. 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/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 29 matching lines...) Expand all
40 } 40 }
41 41
42 void AddThreeNotifications() { 42 void AddThreeNotifications() {
43 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 43 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
44 "1", 44 "1",
45 ASCIIToUTF16("One"), 45 ASCIIToUTF16("One"),
46 ASCIIToUTF16("This is the first notification to" 46 ASCIIToUTF16("This is the first notification to"
47 " be displayed"), 47 " be displayed"),
48 string16(), 48 string16(),
49 std::string(), 49 std::string(),
50 NULL,
50 NULL); 51 NULL);
51 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 52 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
52 "2", 53 "2",
53 ASCIIToUTF16("Two"), 54 ASCIIToUTF16("Two"),
54 ASCIIToUTF16("This is the second notification."), 55 ASCIIToUTF16("This is the second notification."),
55 string16(), 56 string16(),
56 std::string(), 57 std::string(),
58 NULL,
57 NULL); 59 NULL);
58 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 60 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
59 "3", 61 "3",
60 ASCIIToUTF16("Three"), 62 ASCIIToUTF16("Three"),
61 ASCIIToUTF16("This is the third notification " 63 ASCIIToUTF16("This is the third notification "
62 "that has a much longer body " 64 "that has a much longer body "
63 "than the other notifications. It " 65 "than the other notifications. It "
64 "may not fit on the screen if we " 66 "may not fit on the screen if we "
65 "set the screen size too small."), 67 "set the screen size too small."),
66 string16(), 68 string16(),
67 std::string(), 69 std::string(),
70 NULL,
68 NULL); 71 NULL);
69 } 72 }
70 73
71 bool CheckSpacingBetween(MCPopupController* upper, MCPopupController* lower) { 74 bool CheckSpacingBetween(MCPopupController* upper, MCPopupController* lower) {
72 CGFloat minY = NSMinY([[upper window] frame]); 75 CGFloat minY = NSMinY([[upper window] frame]);
73 CGFloat maxY = NSMaxY([[lower window] frame]); 76 CGFloat maxY = NSMaxY([[lower window] frame]);
74 CGFloat delta = minY - maxY; 77 CGFloat delta = minY - maxY;
75 EXPECT_EQ(message_center::kMarginBetweenItems, delta); 78 EXPECT_EQ(message_center::kMarginBetweenItems, delta);
76 return delta == message_center::kMarginBetweenItems; 79 return delta == message_center::kMarginBetweenItems;
77 } 80 }
(...skipping 17 matching lines...) Expand all
95 EXPECT_EQ(0u, [[collection_ popups] count]); 98 EXPECT_EQ(0u, [[collection_ popups] count]);
96 AddThreeNotifications(); 99 AddThreeNotifications();
97 EXPECT_EQ(2u, [[collection_ popups] count]); // "3" does not fit on screen. 100 EXPECT_EQ(2u, [[collection_ popups] count]); // "3" does not fit on screen.
98 101
99 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 102 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
100 "4", 103 "4",
101 ASCIIToUTF16("Four"), 104 ASCIIToUTF16("Four"),
102 ASCIIToUTF16("This is the fourth notification."), 105 ASCIIToUTF16("This is the fourth notification."),
103 string16(), 106 string16(),
104 std::string(), 107 std::string(),
108 NULL,
105 NULL); 109 NULL);
106 110
107 // Remove "1" and "4" should fit on screen. 111 // Remove "1" and "4" should fit on screen.
108 center_->RemoveNotification("1", true); 112 center_->RemoveNotification("1", true);
109 ASSERT_EQ(2u, [[collection_ popups] count]); 113 ASSERT_EQ(2u, [[collection_ popups] count]);
110 114
111 EXPECT_EQ("2", [[[collection_ popups] objectAtIndex:0] notificationID]); 115 EXPECT_EQ("2", [[[collection_ popups] objectAtIndex:0] notificationID]);
112 EXPECT_EQ("4", [[[collection_ popups] objectAtIndex:1] notificationID]); 116 EXPECT_EQ("4", [[[collection_ popups] objectAtIndex:1] notificationID]);
113 117
114 // Remove "2" and "3" should fit on screen. 118 // Remove "2" and "3" should fit on screen.
(...skipping 22 matching lines...) Expand all
137 // Set priority so that kMaxVisiblePopupNotifications does not hide it. 141 // Set priority so that kMaxVisiblePopupNotifications does not hide it.
138 scoped_ptr<base::DictionaryValue> optional(new base::DictionaryValue); 142 scoped_ptr<base::DictionaryValue> optional(new base::DictionaryValue);
139 optional->SetInteger(message_center::kPriorityKey, 143 optional->SetInteger(message_center::kPriorityKey,
140 message_center::HIGH_PRIORITY); 144 message_center::HIGH_PRIORITY);
141 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 145 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
142 "4", 146 "4",
143 ASCIIToUTF16("Four"), 147 ASCIIToUTF16("Four"),
144 ASCIIToUTF16("This is the fourth notification."), 148 ASCIIToUTF16("This is the fourth notification."),
145 string16(), 149 string16(),
146 std::string(), 150 std::string(),
147 optional.get()); 151 optional.get(),
152 NULL);
148 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:2], 153 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:2],
149 [popups objectAtIndex:3])); 154 [popups objectAtIndex:3]));
150 155
151 // Remove "2". 156 // Remove "2".
152 center_->RemoveNotification("2", true); 157 center_->RemoveNotification("2", true);
153 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0], 158 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0],
154 [popups objectAtIndex:1])); 159 [popups objectAtIndex:1]));
155 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1], 160 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1],
156 [popups objectAtIndex:2])); 161 [popups objectAtIndex:2]));
157 162
158 // Remove "1". 163 // Remove "1".
159 center_->RemoveNotification("2", true); 164 center_->RemoveNotification("2", true);
160 EXPECT_EQ(message_center::kMarginBetweenItems, 165 EXPECT_EQ(message_center::kMarginBetweenItems,
161 kScreenSize - NSMaxY([[[popups objectAtIndex:0] window] frame])); 166 kScreenSize - NSMaxY([[[popups objectAtIndex:0] window] frame]));
162 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0], 167 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0],
163 [popups objectAtIndex:1])); 168 [popups objectAtIndex:1]));
164 } 169 }
165 170
166 TEST_F(PopupCollectionTest, TinyScreen) { 171 TEST_F(PopupCollectionTest, TinyScreen) {
167 [collection_ setScreenFrame:NSMakeRect(0, 0, 800, 100)]; 172 [collection_ setScreenFrame:NSMakeRect(0, 0, 800, 100)];
168 173
169 EXPECT_EQ(0u, [[collection_ popups] count]); 174 EXPECT_EQ(0u, [[collection_ popups] count]);
170 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 175 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
171 "1", 176 "1",
172 ASCIIToUTF16("One"), 177 ASCIIToUTF16("One"),
173 ASCIIToUTF16("This is the first notification to" 178 ASCIIToUTF16("This is the first notification to"
174 " be displayed"), 179 " be displayed"),
175 string16(), 180 string16(),
176 std::string(), 181 std::string(),
182 NULL,
177 NULL); 183 NULL);
178 EXPECT_EQ(1u, [[collection_ popups] count]); 184 EXPECT_EQ(1u, [[collection_ popups] count]);
179 185
180 // Now give the notification a longer message so that it no longer fits. 186 // Now give the notification a longer message so that it no longer fits.
181 center_->UpdateNotification("1", 187 center_->UpdateNotification("1",
182 "1", 188 "1",
183 ASCIIToUTF16("One"), 189 ASCIIToUTF16("One"),
184 ASCIIToUTF16("This is now a very very very very " 190 ASCIIToUTF16("This is now a very very very very "
185 "very very very very very very very " 191 "very very very very very very very "
186 "very very very very very very very " 192 "very very very very very very very "
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, 225 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
220 "1", 226 "1",
221 ASCIIToUTF16("One is going to get a much longer " 227 ASCIIToUTF16("One is going to get a much longer "
222 "title than it previously had."), 228 "title than it previously had."),
223 ASCIIToUTF16("This is the first notification to " 229 ASCIIToUTF16("This is the first notification to "
224 "be displayed, but it will also be " 230 "be displayed, but it will also be "
225 "updated to have a significantly " 231 "updated to have a significantly "
226 "longer body"), 232 "longer body"),
227 string16(), 233 string16(),
228 std::string(), 234 std::string(),
235 NULL,
229 NULL); 236 NULL);
230 EXPECT_GT(NSHeight([[controller view] frame]), NSHeight(old_frame)); 237 EXPECT_GT(NSHeight([[controller view] frame]), NSHeight(old_frame));
231 238
232 // Test updated spacing. 239 // Test updated spacing.
233 EXPECT_EQ(3u, [popups count]); 240 EXPECT_EQ(3u, [popups count]);
234 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0], 241 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0],
235 [popups objectAtIndex:1])); 242 [popups objectAtIndex:1]));
236 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1], 243 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1],
237 [popups objectAtIndex:2])); 244 [popups objectAtIndex:2]));
238 EXPECT_EQ("1", [[popups objectAtIndex:0] notificationID]); 245 EXPECT_EQ("1", [[popups objectAtIndex:0] notificationID]);
239 EXPECT_EQ("2", [[popups objectAtIndex:1] notificationID]); 246 EXPECT_EQ("2", [[popups objectAtIndex:1] notificationID]);
240 EXPECT_EQ("3", [[popups objectAtIndex:2] notificationID]); 247 EXPECT_EQ("3", [[popups objectAtIndex:2] notificationID]);
241 } 248 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698