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" |
(...skipping 24 matching lines...) Expand all Loading... |
35 virtual views::View* CreateDefaultView(user::LoginStatus status) { | 35 virtual views::View* CreateDefaultView(user::LoginStatus status) { |
36 default_view_ = new views::View; | 36 default_view_ = new views::View; |
37 return default_view_; | 37 return default_view_; |
38 } | 38 } |
39 | 39 |
40 virtual views::View* CreateDetailedView(user::LoginStatus status) { | 40 virtual views::View* CreateDetailedView(user::LoginStatus status) { |
41 detailed_view_ = new views::View; | 41 detailed_view_ = new views::View; |
42 return detailed_view_; | 42 return detailed_view_; |
43 } | 43 } |
44 | 44 |
| 45 virtual views::View* CreateNotificationView(user::LoginStatus status) { |
| 46 notification_view_ = new views::View; |
| 47 return notification_view_; |
| 48 } |
| 49 |
45 virtual void DestroyTrayView() { | 50 virtual void DestroyTrayView() { |
46 tray_view_ = NULL; | 51 tray_view_ = NULL; |
47 } | 52 } |
48 | 53 |
49 virtual void DestroyDefaultView() { | 54 virtual void DestroyDefaultView() { |
50 default_view_ = NULL; | 55 default_view_ = NULL; |
51 } | 56 } |
52 | 57 |
53 virtual void DestroyDetailedView() { | 58 virtual void DestroyDetailedView() { |
54 detailed_view_ = NULL; | 59 detailed_view_ = NULL; |
55 } | 60 } |
56 | 61 |
| 62 virtual void DestroyNotificationView() { |
| 63 notification_view_ = NULL; |
| 64 } |
| 65 |
57 virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) { | 66 virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) { |
58 } | 67 } |
59 | 68 |
60 views::View* tray_view() const { return tray_view_; } | 69 views::View* tray_view() const { return tray_view_; } |
61 views::View* default_view() const { return default_view_; } | 70 views::View* default_view() const { return default_view_; } |
62 views::View* detailed_view() const { return detailed_view_; } | 71 views::View* detailed_view() const { return detailed_view_; } |
| 72 views::View* notification_view() const { return notification_view_; } |
63 | 73 |
64 private: | 74 private: |
65 views::View* tray_view_; | 75 views::View* tray_view_; |
66 views::View* default_view_; | 76 views::View* default_view_; |
67 views::View* detailed_view_; | 77 views::View* detailed_view_; |
| 78 views::View* notification_view_; |
68 }; | 79 }; |
69 | 80 |
70 } // namespace | 81 } // namespace |
71 | 82 |
72 typedef AshTestBase SystemTrayTest; | 83 typedef AshTestBase SystemTrayTest; |
73 | 84 |
74 TEST_F(SystemTrayTest, SystemTrayDefaultView) { | 85 TEST_F(SystemTrayTest, SystemTrayDefaultView) { |
75 scoped_ptr<SystemTray> tray(CreateSystemTray()); | 86 scoped_ptr<SystemTray> tray(CreateSystemTray()); |
76 ASSERT_TRUE(tray->widget()); | 87 ASSERT_TRUE(tray->widget()); |
77 | 88 |
(...skipping 16 matching lines...) Expand all Loading... |
94 | 105 |
95 // Ensure the tray views are created. | 106 // Ensure the tray views are created. |
96 ASSERT_TRUE(test_item->tray_view() != NULL); | 107 ASSERT_TRUE(test_item->tray_view() != NULL); |
97 ASSERT_TRUE(detailed_item->tray_view() != NULL); | 108 ASSERT_TRUE(detailed_item->tray_view() != NULL); |
98 | 109 |
99 // Ensure a default views are created. | 110 // Ensure a default views are created. |
100 tray->ShowDefaultView(); | 111 tray->ShowDefaultView(); |
101 ASSERT_TRUE(test_item->default_view() != NULL); | 112 ASSERT_TRUE(test_item->default_view() != NULL); |
102 ASSERT_TRUE(detailed_item->default_view() != NULL); | 113 ASSERT_TRUE(detailed_item->default_view() != NULL); |
103 | 114 |
104 // Show the detailed view, ensure its created and the default view destroyed. | 115 // Show the detailed view, ensure it's created and the default view destroyed. |
105 tray->ShowDetailedView(detailed_item, 0, false); | 116 tray->ShowDetailedView(detailed_item, 0, false); |
106 RunAllPendingInMessageLoop(); | 117 RunAllPendingInMessageLoop(); |
107 ASSERT_TRUE(test_item->default_view() == NULL); | 118 ASSERT_TRUE(test_item->default_view() == NULL); |
108 ASSERT_TRUE(detailed_item->detailed_view() != NULL); | 119 ASSERT_TRUE(detailed_item->detailed_view() != NULL); |
109 | 120 |
110 // Show the default view, ensure its created and the detailed view destroyed. | 121 // Show the default view, ensure it's created and the detailed view destroyed. |
111 tray->ShowDefaultView(); | 122 tray->ShowDefaultView(); |
112 RunAllPendingInMessageLoop(); | 123 RunAllPendingInMessageLoop(); |
113 ASSERT_TRUE(test_item->default_view() != NULL); | 124 ASSERT_TRUE(test_item->default_view() != NULL); |
114 ASSERT_TRUE(detailed_item->detailed_view() == NULL); | 125 ASSERT_TRUE(detailed_item->detailed_view() == NULL); |
115 } | 126 } |
116 | 127 |
| 128 TEST_F(SystemTrayTest, SystemTrayNotifications) { |
| 129 scoped_ptr<SystemTray> tray(CreateSystemTray()); |
| 130 ASSERT_TRUE(tray->widget()); |
| 131 |
| 132 TestItem* test_item = new TestItem; |
| 133 TestItem* detailed_item = new TestItem; |
| 134 tray->AddTrayItem(test_item); |
| 135 tray->AddTrayItem(detailed_item); |
| 136 |
| 137 // Ensure the tray views are created. |
| 138 ASSERT_TRUE(test_item->tray_view() != NULL); |
| 139 ASSERT_TRUE(detailed_item->tray_view() != NULL); |
| 140 |
| 141 // Ensure a notification view is created. |
| 142 tray->ShowNotificationView(test_item); |
| 143 ASSERT_TRUE(test_item->notification_view() != NULL); |
| 144 |
| 145 // Show the default view, ensure the notification view is destroyed. |
| 146 tray->ShowDefaultView(); |
| 147 RunAllPendingInMessageLoop(); |
| 148 ASSERT_TRUE(test_item->notification_view() == NULL); |
| 149 |
| 150 // Show the detailed view, ensure the notificaiton view is created again. |
| 151 tray->ShowDetailedView(detailed_item, 0, false); |
| 152 RunAllPendingInMessageLoop(); |
| 153 ASSERT_TRUE(detailed_item->detailed_view() != NULL); |
| 154 ASSERT_TRUE(test_item->notification_view() != NULL); |
| 155 |
| 156 // Hide the detailed view, ensure the notificaiton view still exists. |
| 157 ASSERT_TRUE(tray->CloseBubbleForTest()); |
| 158 RunAllPendingInMessageLoop(); |
| 159 ASSERT_TRUE(detailed_item->detailed_view() == NULL); |
| 160 ASSERT_TRUE(test_item->notification_view() != NULL); |
| 161 } |
| 162 |
117 } // namespace test | 163 } // namespace test |
118 } // namespace ash | 164 } // namespace ash |
OLD | NEW |