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/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" |
11 #import "ui/base/test/ui_cocoa_test_helper.h" | 11 #import "ui/base/test/ui_cocoa_test_helper.h" |
| 12 #import "ui/message_center/cocoa/notification_controller.h" |
12 #import "ui/message_center/cocoa/popup_controller.h" | 13 #import "ui/message_center/cocoa/popup_controller.h" |
13 #include "ui/message_center/message_center.h" | 14 #include "ui/message_center/message_center.h" |
14 #include "ui/message_center/message_center_constants.h" | 15 #include "ui/message_center/message_center_constants.h" |
15 #include "ui/message_center/notification.h" | 16 #include "ui/message_center/notification.h" |
16 | 17 |
17 @implementation MCPopupCollection (TestingAPI) | 18 @implementation MCPopupCollection (TestingAPI) |
18 - (NSArray*)popups { | 19 - (NSArray*)popups { |
19 return popups_.get(); | 20 return popups_.get(); |
20 } | 21 } |
21 @end | 22 @end |
22 | 23 |
| 24 |
| 25 @implementation MCNotificationController (TestingInterface) |
| 26 - (NSImageView*)iconView { |
| 27 return icon_.get(); |
| 28 } |
| 29 @end |
| 30 |
23 class PopupCollectionTest : public ui::CocoaTest { | 31 class PopupCollectionTest : public ui::CocoaTest { |
24 public: | 32 public: |
25 PopupCollectionTest() { | 33 PopupCollectionTest() { |
26 message_center::MessageCenter::Initialize(); | 34 message_center::MessageCenter::Initialize(); |
27 center_ = message_center::MessageCenter::Get(); | 35 center_ = message_center::MessageCenter::Get(); |
28 collection_.reset( | 36 collection_.reset( |
29 [[MCPopupCollection alloc] initWithMessageCenter:center_]); | 37 [[MCPopupCollection alloc] initWithMessageCenter:center_]); |
30 } | 38 } |
31 | 39 |
32 virtual void TearDown() OVERRIDE { | 40 virtual void TearDown() OVERRIDE { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1], | 162 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1], |
155 [popups objectAtIndex:2])); | 163 [popups objectAtIndex:2])); |
156 | 164 |
157 // Remove "1". | 165 // Remove "1". |
158 center_->RemoveNotification("2", true); | 166 center_->RemoveNotification("2", true); |
159 EXPECT_EQ(message_center::kMarginBetweenItems, | 167 EXPECT_EQ(message_center::kMarginBetweenItems, |
160 kScreenSize - NSMaxY([[[popups objectAtIndex:0] window] frame])); | 168 kScreenSize - NSMaxY([[[popups objectAtIndex:0] window] frame])); |
161 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0], | 169 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0], |
162 [popups objectAtIndex:1])); | 170 [popups objectAtIndex:1])); |
163 } | 171 } |
| 172 |
| 173 TEST_F(PopupCollectionTest, UpdateIconAndBody) { |
| 174 AddThreeNotifications(); |
| 175 NSArray* popups = [collection_ popups]; |
| 176 |
| 177 EXPECT_EQ(3u, [popups count]); |
| 178 |
| 179 // Update "2" icon. |
| 180 MCNotificationController* controller = |
| 181 [[popups objectAtIndex:1] notificationController]; |
| 182 EXPECT_FALSE([[controller iconView] image]); |
| 183 center_->SetNotificationIcon("2", |
| 184 gfx::Image([[NSImage imageNamed:NSImageNameUser] retain])); |
| 185 EXPECT_TRUE([[controller iconView] image]); |
| 186 |
| 187 EXPECT_EQ(3u, [popups count]); |
| 188 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0], |
| 189 [popups objectAtIndex:1])); |
| 190 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1], |
| 191 [popups objectAtIndex:2])); |
| 192 |
| 193 // Replace "1". |
| 194 controller = [[popups objectAtIndex:0] notificationController]; |
| 195 NSRect old_frame = [[controller view] frame]; |
| 196 center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, |
| 197 "1", |
| 198 ASCIIToUTF16("One is going to get a much longer " |
| 199 "title than it previously had."), |
| 200 ASCIIToUTF16("This is the first notification to " |
| 201 "be displayed, but it will also be " |
| 202 "updated to have a significantly " |
| 203 "longer body"), |
| 204 string16(), |
| 205 std::string(), |
| 206 NULL); |
| 207 EXPECT_GT(NSHeight([[controller view] frame]), NSHeight(old_frame)); |
| 208 |
| 209 // Test updated spacing. |
| 210 EXPECT_EQ(3u, [popups count]); |
| 211 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0], |
| 212 [popups objectAtIndex:1])); |
| 213 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1], |
| 214 [popups objectAtIndex:2])); |
| 215 EXPECT_EQ("1", [[popups objectAtIndex:0] notificationID]); |
| 216 EXPECT_EQ("2", [[popups objectAtIndex:1] notificationID]); |
| 217 EXPECT_EQ("3", [[popups objectAtIndex:2] notificationID]); |
| 218 } |
OLD | NEW |