OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ash/system/tray/system_tray.h" | 5 #include "ash/system/tray/system_tray.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/system/tray/system_tray_item.h" | 9 #include "ash/system/tray/system_tray_item.h" |
10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
| 11 #include "base/utf_string_conversions.h" |
| 12 #include "ui/views/controls/label.h" |
| 13 #include "ui/views/layout/fill_layout.h" |
11 #include "ui/views/view.h" | 14 #include "ui/views/view.h" |
| 15 #include "ui/views/widget/widget.h" |
12 | 16 |
13 namespace ash { | 17 namespace ash { |
14 namespace test { | 18 namespace test { |
15 | 19 |
16 namespace { | 20 namespace { |
17 | 21 |
18 SystemTray* CreateSystemTray() { | 22 SystemTray* CreateSystemTray() { |
19 SystemTray* tray = new SystemTray; | 23 SystemTray* tray = new SystemTray; |
20 tray->CreateItems(); | 24 tray->CreateItems(); |
21 tray->CreateWidget(); | 25 tray->CreateWidget(); |
22 return tray; | 26 return tray; |
23 } | 27 } |
24 | 28 |
25 // Trivial item implementation that tracks its views for testing. | 29 // Trivial item implementation that tracks its views for testing. |
26 class TestItem : public SystemTrayItem { | 30 class TestItem : public SystemTrayItem { |
27 public: | 31 public: |
28 TestItem() : tray_view_(NULL) {} | 32 TestItem() : tray_view_(NULL) {} |
29 | 33 |
30 virtual views::View* CreateTrayView(user::LoginStatus status) { | 34 virtual views::View* CreateTrayView(user::LoginStatus status) { |
31 tray_view_ = new views::View; | 35 tray_view_ = new views::View; |
| 36 // Add a label so it has non-zero width. |
| 37 tray_view_->SetLayoutManager(new views::FillLayout); |
| 38 tray_view_->AddChildView(new views::Label(UTF8ToUTF16("Tray"))); |
32 return tray_view_; | 39 return tray_view_; |
33 } | 40 } |
34 | 41 |
35 virtual views::View* CreateDefaultView(user::LoginStatus status) { | 42 virtual views::View* CreateDefaultView(user::LoginStatus status) { |
36 default_view_ = new views::View; | 43 default_view_ = new views::View; |
| 44 default_view_->SetLayoutManager(new views::FillLayout); |
| 45 default_view_->AddChildView(new views::Label(UTF8ToUTF16("Default"))); |
37 return default_view_; | 46 return default_view_; |
38 } | 47 } |
39 | 48 |
40 virtual views::View* CreateDetailedView(user::LoginStatus status) { | 49 virtual views::View* CreateDetailedView(user::LoginStatus status) { |
41 detailed_view_ = new views::View; | 50 detailed_view_ = new views::View; |
| 51 detailed_view_->SetLayoutManager(new views::FillLayout); |
| 52 detailed_view_->AddChildView(new views::Label(UTF8ToUTF16("Detailed"))); |
42 return detailed_view_; | 53 return detailed_view_; |
43 } | 54 } |
44 | 55 |
45 virtual views::View* CreateNotificationView(user::LoginStatus status) { | 56 virtual views::View* CreateNotificationView(user::LoginStatus status) { |
46 notification_view_ = new views::View; | 57 notification_view_ = new views::View; |
47 return notification_view_; | 58 return notification_view_; |
48 } | 59 } |
49 | 60 |
50 virtual void DestroyTrayView() { | 61 virtual void DestroyTrayView() { |
51 tray_view_ = NULL; | 62 tray_view_ = NULL; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 ASSERT_TRUE(test_item->default_view() == NULL); | 129 ASSERT_TRUE(test_item->default_view() == NULL); |
119 ASSERT_TRUE(detailed_item->detailed_view() != NULL); | 130 ASSERT_TRUE(detailed_item->detailed_view() != NULL); |
120 | 131 |
121 // Show the default view, ensure it's created and the detailed view destroyed. | 132 // Show the default view, ensure it's created and the detailed view destroyed. |
122 tray->ShowDefaultView(); | 133 tray->ShowDefaultView(); |
123 RunAllPendingInMessageLoop(); | 134 RunAllPendingInMessageLoop(); |
124 ASSERT_TRUE(test_item->default_view() != NULL); | 135 ASSERT_TRUE(test_item->default_view() != NULL); |
125 ASSERT_TRUE(detailed_item->detailed_view() == NULL); | 136 ASSERT_TRUE(detailed_item->detailed_view() == NULL); |
126 } | 137 } |
127 | 138 |
| 139 TEST_F(SystemTrayTest, TrayWidgetAutoResizes) { |
| 140 scoped_ptr<SystemTray> tray(CreateSystemTray()); |
| 141 ASSERT_TRUE(tray->widget()); |
| 142 |
| 143 gfx::Size widget_size = tray->widget()->GetWindowScreenBounds().size(); |
| 144 |
| 145 TestItem* test_item = new TestItem; |
| 146 tray->AddTrayItem(test_item); |
| 147 |
| 148 gfx::Size new_size = tray->widget()->GetWindowScreenBounds().size(); |
| 149 |
| 150 // Adding the new item should change the size of the tray. |
| 151 EXPECT_NE(widget_size.ToString(), new_size.ToString()); |
| 152 |
| 153 // Hiding the tray view of the new item should also change the size of the |
| 154 // tray. |
| 155 test_item->tray_view()->SetVisible(false); |
| 156 EXPECT_EQ(widget_size.ToString(), |
| 157 tray->widget()->GetWindowScreenBounds().size().ToString()); |
| 158 |
| 159 test_item->tray_view()->SetVisible(true); |
| 160 EXPECT_EQ(new_size.ToString(), |
| 161 tray->widget()->GetWindowScreenBounds().size().ToString()); |
| 162 } |
| 163 |
128 // Disabled due to a use-after-free, see http://crbug.com/127539. | 164 // Disabled due to a use-after-free, see http://crbug.com/127539. |
129 TEST_F(SystemTrayTest, DISABLED_SystemTrayNotifications) { | 165 TEST_F(SystemTrayTest, DISABLED_SystemTrayNotifications) { |
130 scoped_ptr<SystemTray> tray(CreateSystemTray()); | 166 scoped_ptr<SystemTray> tray(CreateSystemTray()); |
131 ASSERT_TRUE(tray->widget()); | 167 ASSERT_TRUE(tray->widget()); |
132 | 168 |
133 TestItem* test_item = new TestItem; | 169 TestItem* test_item = new TestItem; |
134 TestItem* detailed_item = new TestItem; | 170 TestItem* detailed_item = new TestItem; |
135 tray->AddTrayItem(test_item); | 171 tray->AddTrayItem(test_item); |
136 tray->AddTrayItem(detailed_item); | 172 tray->AddTrayItem(detailed_item); |
137 | 173 |
(...skipping 18 matching lines...) Expand all Loading... |
156 | 192 |
157 // Hide the detailed view, ensure the notificaiton view still exists. | 193 // Hide the detailed view, ensure the notificaiton view still exists. |
158 ASSERT_TRUE(tray->CloseBubbleForTest()); | 194 ASSERT_TRUE(tray->CloseBubbleForTest()); |
159 RunAllPendingInMessageLoop(); | 195 RunAllPendingInMessageLoop(); |
160 ASSERT_TRUE(detailed_item->detailed_view() == NULL); | 196 ASSERT_TRUE(detailed_item->detailed_view() == NULL); |
161 ASSERT_TRUE(test_item->notification_view() != NULL); | 197 ASSERT_TRUE(test_item->notification_view() != NULL); |
162 } | 198 } |
163 | 199 |
164 } // namespace test | 200 } // namespace test |
165 } // namespace ash | 201 } // namespace ash |
OLD | NEW |