1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ui/message_center/cocoa/tray_view_controller.h"
#include "base/memory/scoped_nsobject.h"
#include "base/utf_string_conversions.h"
#import "ui/base/test/ui_cocoa_test_helper.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_style.h"
#include "ui/message_center/notification.h"
class TrayViewControllerTest : public ui::CocoaTest {
public:
virtual void SetUp() OVERRIDE {
ui::CocoaTest::SetUp();
message_center::MessageCenter::Initialize();
center_ = message_center::MessageCenter::Get();
tray_.reset([[MCTrayViewController alloc] initWithMessageCenter:center_]);
[tray_ view]; // Create the view.
}
virtual void TearDown() OVERRIDE {
tray_.reset();
message_center::MessageCenter::Shutdown();
ui::CocoaTest::TearDown();
}
protected:
message_center::MessageCenter* center_; // Weak, global.
scoped_nsobject<MCTrayViewController> tray_;
};
TEST_F(TrayViewControllerTest, AddRemoveOne) {
NSScrollView* view = [[tray_ scrollView] documentView];
EXPECT_EQ(0u, [[view subviews] count]);
center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
"1",
ASCIIToUTF16("First notification"),
ASCIIToUTF16("This is a simple test."),
string16(),
std::string(),
NULL,
NULL);
[tray_ onMessageCenterTrayChanged];
ASSERT_EQ(1u, [[view subviews] count]);
// The view should have padding around it.
NSView* notification = [[view subviews] objectAtIndex:0];
NSRect notification_frame = [notification frame];
EXPECT_CGFLOAT_EQ(2 * message_center::kMarginBetweenItems,
NSHeight([view frame]) - NSHeight(notification_frame));
EXPECT_CGFLOAT_EQ(2 * message_center::kMarginBetweenItems,
NSWidth([view frame]) - NSWidth(notification_frame));
EXPECT_GT(NSHeight([[tray_ view] frame]),
NSHeight([[tray_ scrollView] frame]));
center_->RemoveNotification("1", true);
[tray_ onMessageCenterTrayChanged];
EXPECT_EQ(0u, [[view subviews] count]);
EXPECT_CGFLOAT_EQ(0, NSHeight([view frame]));
}
TEST_F(TrayViewControllerTest, AddThreeClearAll) {
NSScrollView* view = [[tray_ scrollView] documentView];
EXPECT_EQ(0u, [[view subviews] count]);
center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
"1",
ASCIIToUTF16("First notification"),
ASCIIToUTF16("This is a simple test."),
string16(),
std::string(),
NULL,
NULL);
center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
"2",
ASCIIToUTF16("Second notification"),
ASCIIToUTF16("This is a simple test."),
string16(),
std::string(),
NULL,
NULL);
center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
"3",
ASCIIToUTF16("Third notification"),
ASCIIToUTF16("This is a simple test."),
string16(),
std::string(),
NULL,
NULL);
[tray_ onMessageCenterTrayChanged];
ASSERT_EQ(3u, [[view subviews] count]);
[tray_ clearAllNotifications:nil];
[tray_ onMessageCenterTrayChanged];
EXPECT_EQ(0u, [[view subviews] count]);
EXPECT_CGFLOAT_EQ(0, NSHeight([view frame]));
}
TEST_F(TrayViewControllerTest, NoClearAllWhenNoNotifications) {
EXPECT_TRUE([tray_ pauseButton]);
EXPECT_TRUE([tray_ clearAllButton]);
// With no notifications, the clear all button should be hidden.
EXPECT_TRUE([[tray_ clearAllButton] isHidden]);
EXPECT_LT(NSMinX([[tray_ clearAllButton] frame]),
NSMinX([[tray_ pauseButton] frame]));
// Add a notification.
center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
"1",
ASCIIToUTF16("First notification"),
ASCIIToUTF16("This is a simple test."),
string16(),
std::string(),
NULL,
NULL);
[tray_ onMessageCenterTrayChanged];
// Clear all should now be visible.
EXPECT_FALSE([[tray_ clearAllButton] isHidden]);
EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]),
NSMinX([[tray_ pauseButton] frame]));
// Adding a second notification should keep things still visible.
center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
"2",
ASCIIToUTF16("Second notification"),
ASCIIToUTF16("This is a simple test."),
string16(),
std::string(),
NULL,
NULL);
[tray_ onMessageCenterTrayChanged];
EXPECT_FALSE([[tray_ clearAllButton] isHidden]);
EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]),
NSMinX([[tray_ pauseButton] frame]));
// Clear all notifications.
[tray_ clearAllNotifications:nil];
[tray_ onMessageCenterTrayChanged];
// The button should be hidden again.
EXPECT_TRUE([[tray_ clearAllButton] isHidden]);
EXPECT_LT(NSMinX([[tray_ clearAllButton] frame]),
NSMinX([[tray_ pauseButton] frame]));
}
|