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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
// Copyright (c) 2012 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.
#include "ash/system/tray/system_tray.h"
#include <vector>
#include "ash/system/tray/system_tray_item.h"
#include "ash/test/ash_test_base.h"
#include "ui/views/view.h"
namespace ash {
namespace test {
namespace {
SystemTray* CreateSystemTray() {
SystemTray* tray = new SystemTray;
tray->CreateItems();
tray->CreateWidget();
return tray;
}
// Trivial item implementation that tracks its views for testing.
class TestItem : public SystemTrayItem {
public:
TestItem() : tray_view_(NULL) {}
virtual views::View* CreateTrayView(user::LoginStatus status) {
tray_view_ = new views::View;
return tray_view_;
}
virtual views::View* CreateDefaultView(user::LoginStatus status) {
default_view_ = new views::View;
return default_view_;
}
virtual views::View* CreateDetailedView(user::LoginStatus status) {
detailed_view_ = new views::View;
return detailed_view_;
}
virtual views::View* CreateNotificationView(user::LoginStatus status) {
notification_view_ = new views::View;
return notification_view_;
}
virtual void DestroyTrayView() {
tray_view_ = NULL;
}
virtual void DestroyDefaultView() {
default_view_ = NULL;
}
virtual void DestroyDetailedView() {
detailed_view_ = NULL;
}
virtual void DestroyNotificationView() {
notification_view_ = NULL;
}
virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) {
}
views::View* tray_view() const { return tray_view_; }
views::View* default_view() const { return default_view_; }
views::View* detailed_view() const { return detailed_view_; }
views::View* notification_view() const { return notification_view_; }
private:
views::View* tray_view_;
views::View* default_view_;
views::View* detailed_view_;
views::View* notification_view_;
};
} // namespace
typedef AshTestBase SystemTrayTest;
TEST_F(SystemTrayTest, SystemTrayDefaultView) {
scoped_ptr<SystemTray> tray(CreateSystemTray());
ASSERT_TRUE(tray->widget());
tray->ShowDefaultView();
// Ensure that closing the bubble destroys it.
ASSERT_TRUE(tray->CloseBubbleForTest());
RunAllPendingInMessageLoop();
ASSERT_FALSE(tray->CloseBubbleForTest());
}
TEST_F(SystemTrayTest, SystemTrayTestItems) {
scoped_ptr<SystemTray> tray(CreateSystemTray());
ASSERT_TRUE(tray->widget());
TestItem* test_item = new TestItem;
TestItem* detailed_item = new TestItem;
tray->AddTrayItem(test_item);
tray->AddTrayItem(detailed_item);
// Ensure the tray views are created.
ASSERT_TRUE(test_item->tray_view() != NULL);
ASSERT_TRUE(detailed_item->tray_view() != NULL);
// Ensure a default views are created.
tray->ShowDefaultView();
ASSERT_TRUE(test_item->default_view() != NULL);
ASSERT_TRUE(detailed_item->default_view() != NULL);
// Show the detailed view, ensure it's created and the default view destroyed.
tray->ShowDetailedView(detailed_item, 0, false);
RunAllPendingInMessageLoop();
ASSERT_TRUE(test_item->default_view() == NULL);
ASSERT_TRUE(detailed_item->detailed_view() != NULL);
// Show the default view, ensure it's created and the detailed view destroyed.
tray->ShowDefaultView();
RunAllPendingInMessageLoop();
ASSERT_TRUE(test_item->default_view() != NULL);
ASSERT_TRUE(detailed_item->detailed_view() == NULL);
}
// Disabled due to a use-after-free, see http://crbug.com/127539.
TEST_F(SystemTrayTest, DISABLED_SystemTrayNotifications) {
scoped_ptr<SystemTray> tray(CreateSystemTray());
ASSERT_TRUE(tray->widget());
TestItem* test_item = new TestItem;
TestItem* detailed_item = new TestItem;
tray->AddTrayItem(test_item);
tray->AddTrayItem(detailed_item);
// Ensure the tray views are created.
ASSERT_TRUE(test_item->tray_view() != NULL);
ASSERT_TRUE(detailed_item->tray_view() != NULL);
// Ensure a notification view is created.
tray->ShowNotificationView(test_item);
ASSERT_TRUE(test_item->notification_view() != NULL);
// Show the default view, ensure the notification view is destroyed.
tray->ShowDefaultView();
RunAllPendingInMessageLoop();
ASSERT_TRUE(test_item->notification_view() == NULL);
// Show the detailed view, ensure the notificaiton view is created again.
tray->ShowDetailedView(detailed_item, 0, false);
RunAllPendingInMessageLoop();
ASSERT_TRUE(detailed_item->detailed_view() != NULL);
ASSERT_TRUE(test_item->notification_view() != NULL);
// Hide the detailed view, ensure the notificaiton view still exists.
ASSERT_TRUE(tray->CloseBubbleForTest());
RunAllPendingInMessageLoop();
ASSERT_TRUE(detailed_item->detailed_view() == NULL);
ASSERT_TRUE(test_item->notification_view() != NULL);
}
} // namespace test
} // namespace ash
|