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/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
10 #include "ash/system/status_area_widget.h" | 10 #include "ash/system/status_area_widget.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 views::View* detailed_view() const { return detailed_view_; } | 82 views::View* detailed_view() const { return detailed_view_; } |
83 views::View* notification_view() const { return notification_view_; } | 83 views::View* notification_view() const { return notification_view_; } |
84 | 84 |
85 private: | 85 private: |
86 views::View* tray_view_; | 86 views::View* tray_view_; |
87 views::View* default_view_; | 87 views::View* default_view_; |
88 views::View* detailed_view_; | 88 views::View* detailed_view_; |
89 views::View* notification_view_; | 89 views::View* notification_view_; |
90 }; | 90 }; |
91 | 91 |
| 92 // Trivial item implementation that returns NULL from tray/default/detailed view |
| 93 // creation methods. |
| 94 class TestNoViewItem : public SystemTrayItem { |
| 95 public: |
| 96 TestNoViewItem() : SystemTrayItem(GetSystemTray()) {} |
| 97 |
| 98 virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE { |
| 99 return NULL; |
| 100 } |
| 101 |
| 102 virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE { |
| 103 return NULL; |
| 104 } |
| 105 |
| 106 virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE { |
| 107 return NULL; |
| 108 } |
| 109 |
| 110 virtual views::View* CreateNotificationView( |
| 111 user::LoginStatus status) OVERRIDE { |
| 112 return NULL; |
| 113 } |
| 114 |
| 115 virtual void DestroyTrayView() OVERRIDE {} |
| 116 virtual void DestroyDefaultView() OVERRIDE {} |
| 117 virtual void DestroyDetailedView() OVERRIDE {} |
| 118 virtual void DestroyNotificationView() OVERRIDE {} |
| 119 virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE { |
| 120 } |
| 121 }; |
| 122 |
92 } // namespace | 123 } // namespace |
93 | 124 |
94 typedef AshTestBase SystemTrayTest; | 125 typedef AshTestBase SystemTrayTest; |
95 | 126 |
96 TEST_F(SystemTrayTest, SystemTrayDefaultView) { | 127 TEST_F(SystemTrayTest, SystemTrayDefaultView) { |
97 SystemTray* tray = GetSystemTray(); | 128 SystemTray* tray = GetSystemTray(); |
98 ASSERT_TRUE(tray->GetWidget()); | 129 ASSERT_TRUE(tray->GetWidget()); |
99 | 130 |
100 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 131 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
101 | 132 |
(...skipping 27 matching lines...) Expand all Loading... |
129 ASSERT_TRUE(test_item->default_view() == NULL); | 160 ASSERT_TRUE(test_item->default_view() == NULL); |
130 ASSERT_TRUE(detailed_item->detailed_view() != NULL); | 161 ASSERT_TRUE(detailed_item->detailed_view() != NULL); |
131 | 162 |
132 // Show the default view, ensure it's created and the detailed view destroyed. | 163 // Show the default view, ensure it's created and the detailed view destroyed. |
133 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 164 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
134 RunAllPendingInMessageLoop(); | 165 RunAllPendingInMessageLoop(); |
135 ASSERT_TRUE(test_item->default_view() != NULL); | 166 ASSERT_TRUE(test_item->default_view() != NULL); |
136 ASSERT_TRUE(detailed_item->detailed_view() == NULL); | 167 ASSERT_TRUE(detailed_item->detailed_view() == NULL); |
137 } | 168 } |
138 | 169 |
| 170 TEST_F(SystemTrayTest, SystemTrayNoViewItems) { |
| 171 SystemTray* tray = GetSystemTray(); |
| 172 ASSERT_TRUE(tray->GetWidget()); |
| 173 |
| 174 // Verify that no crashes occur on items lacking some views. |
| 175 TestNoViewItem* no_view_item = new TestNoViewItem; |
| 176 tray->AddTrayItem(no_view_item); |
| 177 tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 178 tray->ShowDetailedView(no_view_item, 0, false, BUBBLE_USE_EXISTING); |
| 179 RunAllPendingInMessageLoop(); |
| 180 } |
| 181 |
139 TEST_F(SystemTrayTest, TrayWidgetAutoResizes) { | 182 TEST_F(SystemTrayTest, TrayWidgetAutoResizes) { |
140 SystemTray* tray = GetSystemTray(); | 183 SystemTray* tray = GetSystemTray(); |
141 ASSERT_TRUE(tray->GetWidget()); | 184 ASSERT_TRUE(tray->GetWidget()); |
142 | 185 |
143 // Add an initial tray item so that the tray gets laid out correctly. | 186 // Add an initial tray item so that the tray gets laid out correctly. |
144 TestItem* initial_item = new TestItem; | 187 TestItem* initial_item = new TestItem; |
145 tray->AddTrayItem(initial_item); | 188 tray->AddTrayItem(initial_item); |
146 | 189 |
147 gfx::Size initial_size = tray->GetWidget()->GetWindowBoundsInScreen().size(); | 190 gfx::Size initial_size = tray->GetWidget()->GetWindowBoundsInScreen().size(); |
148 | 191 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 tray->ShowDefaultView(BUBBLE_USE_EXISTING); | 272 tray->ShowDefaultView(BUBBLE_USE_EXISTING); |
230 RunAllPendingInMessageLoop(); | 273 RunAllPendingInMessageLoop(); |
231 | 274 |
232 EXPECT_EQ(bubble_bounds.ToString(), test_item->default_view()->GetWidget()-> | 275 EXPECT_EQ(bubble_bounds.ToString(), test_item->default_view()->GetWidget()-> |
233 GetWindowBoundsInScreen().ToString()); | 276 GetWindowBoundsInScreen().ToString()); |
234 EXPECT_EQ(widget, test_item->default_view()->GetWidget()); | 277 EXPECT_EQ(widget, test_item->default_view()->GetWidget()); |
235 } | 278 } |
236 | 279 |
237 } // namespace test | 280 } // namespace test |
238 } // namespace ash | 281 } // namespace ash |
OLD | NEW |