Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Side by Side Diff: ash/system/tray/system_tray_unittest.cc

Issue 2072023003: mash: Break ash system tray dependencies on ash::ShelfWidget (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/system/tray/system_tray.cc ('k') | ash/system/tray/tray_background_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common/accessibility_delegate.h" 9 #include "ash/common/accessibility_delegate.h"
10 #include "ash/common/system/tray/system_tray_item.h" 10 #include "ash/common/system/tray/system_tray_item.h"
11 #include "ash/common/system/tray/tray_constants.h" 11 #include "ash/common/system/tray/tray_constants.h"
12 #include "ash/common/system/tray/tray_popup_item_container.h" 12 #include "ash/common/system/tray/tray_popup_item_container.h"
13 #include "ash/root_window_controller.h" 13 #include "ash/root_window_controller.h"
14 #include "ash/shelf/shelf.h" 14 #include "ash/shelf/shelf.h"
15 #include "ash/shelf/shelf_widget.h"
16 #include "ash/shell.h" 15 #include "ash/shell.h"
17 #include "ash/system/status_area_widget.h" 16 #include "ash/system/status_area_widget.h"
18 #include "ash/system/tray/system_tray_bubble.h" 17 #include "ash/system/tray/system_tray_bubble.h"
19 #include "ash/system/web_notification/web_notification_tray.h" 18 #include "ash/system/web_notification/web_notification_tray.h"
20 #include "ash/test/ash_test_base.h" 19 #include "ash/test/ash_test_base.h"
20 #include "ash/test/status_area_widget_test_helper.h"
21 #include "ash/wm/window_util.h" 21 #include "ash/wm/window_util.h"
22 #include "base/run_loop.h" 22 #include "base/run_loop.h"
23 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
24 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
25 #include "ui/base/ui_base_types.h" 25 #include "ui/base/ui_base_types.h"
26 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 26 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
27 #include "ui/events/test/event_generator.h" 27 #include "ui/events/test/event_generator.h"
28 #include "ui/gfx/geometry/point.h" 28 #include "ui/gfx/geometry/point.h"
29 #include "ui/gfx/geometry/rect.h" 29 #include "ui/gfx/geometry/rect.h"
30 #include "ui/views/controls/label.h" 30 #include "ui/views/controls/label.h"
31 #include "ui/views/layout/fill_layout.h" 31 #include "ui/views/layout/fill_layout.h"
32 #include "ui/views/view.h" 32 #include "ui/views/view.h"
33 #include "ui/views/widget/widget.h" 33 #include "ui/views/widget/widget.h"
34 #include "ui/views/widget/widget_delegate.h" 34 #include "ui/views/widget/widget_delegate.h"
35 35
36 #if defined(OS_WIN) 36 #if defined(OS_WIN)
37 #include "base/win/windows_version.h" 37 #include "base/win/windows_version.h"
38 #endif 38 #endif
39 39
40 namespace ash { 40 namespace ash {
41 namespace test { 41 namespace test {
42 42
43 namespace { 43 namespace {
44 44
45 SystemTray* GetSystemTray() {
46 return Shell::GetPrimaryRootWindowController()
47 ->shelf_widget()
48 ->status_area_widget()
49 ->system_tray();
50 }
51
52 // Trivial item implementation that tracks its views for testing. 45 // Trivial item implementation that tracks its views for testing.
53 class TestItem : public SystemTrayItem { 46 class TestItem : public SystemTrayItem {
54 public: 47 public:
55 TestItem() : SystemTrayItem(GetSystemTray()), tray_view_(NULL) {} 48 TestItem()
49 : SystemTrayItem(AshTestBase::GetPrimarySystemTray()),
50 tray_view_(nullptr),
51 default_view_(nullptr),
52 detailed_view_(nullptr),
53 notification_view_(nullptr) {}
56 54
57 views::View* CreateTrayView(LoginStatus status) override { 55 views::View* CreateTrayView(LoginStatus status) override {
58 tray_view_ = new views::View; 56 tray_view_ = new views::View;
59 // Add a label so it has non-zero width. 57 // Add a label so it has non-zero width.
60 tray_view_->SetLayoutManager(new views::FillLayout); 58 tray_view_->SetLayoutManager(new views::FillLayout);
61 tray_view_->AddChildView(new views::Label(base::UTF8ToUTF16("Tray"))); 59 tray_view_->AddChildView(new views::Label(base::UTF8ToUTF16("Tray")));
62 return tray_view_; 60 return tray_view_;
63 } 61 }
64 62
65 views::View* CreateDefaultView(LoginStatus status) override { 63 views::View* CreateDefaultView(LoginStatus status) override {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 views::View* tray_view_; 99 views::View* tray_view_;
102 views::View* default_view_; 100 views::View* default_view_;
103 views::View* detailed_view_; 101 views::View* detailed_view_;
104 views::View* notification_view_; 102 views::View* notification_view_;
105 }; 103 };
106 104
107 // Trivial item implementation that returns NULL from tray/default/detailed 105 // Trivial item implementation that returns NULL from tray/default/detailed
108 // view creation methods. 106 // view creation methods.
109 class TestNoViewItem : public SystemTrayItem { 107 class TestNoViewItem : public SystemTrayItem {
110 public: 108 public:
111 TestNoViewItem() : SystemTrayItem(GetSystemTray()) {} 109 TestNoViewItem() : SystemTrayItem(AshTestBase::GetPrimarySystemTray()) {}
112 110
113 views::View* CreateTrayView(LoginStatus status) override { return nullptr; } 111 views::View* CreateTrayView(LoginStatus status) override { return nullptr; }
114 112
115 views::View* CreateDefaultView(LoginStatus status) override { 113 views::View* CreateDefaultView(LoginStatus status) override {
116 return nullptr; 114 return nullptr;
117 } 115 }
118 116
119 views::View* CreateDetailedView(LoginStatus status) override { 117 views::View* CreateDetailedView(LoginStatus status) override {
120 return nullptr; 118 return nullptr;
121 } 119 }
(...skipping 19 matching lines...) Expand all
141 139
142 private: 140 private:
143 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate); 141 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
144 }; 142 };
145 143
146 } // namespace 144 } // namespace
147 145
148 typedef AshTestBase SystemTrayTest; 146 typedef AshTestBase SystemTrayTest;
149 147
150 TEST_F(SystemTrayTest, SystemTrayDefaultView) { 148 TEST_F(SystemTrayTest, SystemTrayDefaultView) {
151 SystemTray* tray = GetSystemTray(); 149 SystemTray* tray = GetPrimarySystemTray();
152 ASSERT_TRUE(tray->GetWidget()); 150 ASSERT_TRUE(tray->GetWidget());
153 151
154 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 152 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
155 153
156 // Ensure that closing the bubble destroys it. 154 // Ensure that closing the bubble destroys it.
157 ASSERT_TRUE(tray->CloseSystemBubble()); 155 ASSERT_TRUE(tray->CloseSystemBubble());
158 RunAllPendingInMessageLoop(); 156 RunAllPendingInMessageLoop();
159 ASSERT_FALSE(tray->CloseSystemBubble()); 157 ASSERT_FALSE(tray->CloseSystemBubble());
160 } 158 }
161 159
162 // Opening and closing the bubble should change the coloring of the tray. 160 // Opening and closing the bubble should change the coloring of the tray.
163 TEST_F(SystemTrayTest, SystemTrayColoring) { 161 TEST_F(SystemTrayTest, SystemTrayColoring) {
164 SystemTray* tray = GetSystemTray(); 162 SystemTray* tray = GetPrimarySystemTray();
165 ASSERT_TRUE(tray->GetWidget()); 163 ASSERT_TRUE(tray->GetWidget());
166 // At the beginning the tray coloring is not active. 164 // At the beginning the tray coloring is not active.
167 ASSERT_FALSE(tray->draw_background_as_active()); 165 ASSERT_FALSE(tray->draw_background_as_active());
168 166
169 // Showing the system bubble should show the background as active. 167 // Showing the system bubble should show the background as active.
170 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 168 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
171 ASSERT_TRUE(tray->draw_background_as_active()); 169 ASSERT_TRUE(tray->draw_background_as_active());
172 170
173 // Closing the system menu should change the coloring back to normal. 171 // Closing the system menu should change the coloring back to normal.
174 ASSERT_TRUE(tray->CloseSystemBubble()); 172 ASSERT_TRUE(tray->CloseSystemBubble());
175 RunAllPendingInMessageLoop(); 173 RunAllPendingInMessageLoop();
176 ASSERT_FALSE(tray->draw_background_as_active()); 174 ASSERT_FALSE(tray->draw_background_as_active());
177 } 175 }
178 176
179 // Closing the system bubble through an alignment change should change the 177 // Closing the system bubble through an alignment change should change the
180 // system tray coloring back to normal. 178 // system tray coloring back to normal.
181 TEST_F(SystemTrayTest, SystemTrayColoringAfterAlignmentChange) { 179 TEST_F(SystemTrayTest, SystemTrayColoringAfterAlignmentChange) {
182 SystemTray* tray = GetSystemTray(); 180 SystemTray* tray = GetPrimarySystemTray();
183 ASSERT_TRUE(tray->GetWidget()); 181 ASSERT_TRUE(tray->GetWidget());
184 Shelf* shelf = Shelf::ForPrimaryDisplay(); 182 Shelf* shelf = Shelf::ForPrimaryDisplay();
185 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); 183 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM);
186 // At the beginning the tray coloring is not active. 184 // At the beginning the tray coloring is not active.
187 ASSERT_FALSE(tray->draw_background_as_active()); 185 ASSERT_FALSE(tray->draw_background_as_active());
188 186
189 // Showing the system bubble should show the background as active. 187 // Showing the system bubble should show the background as active.
190 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 188 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
191 ASSERT_TRUE(tray->draw_background_as_active()); 189 ASSERT_TRUE(tray->draw_background_as_active());
192 190
193 // Changing the alignment should close the system bubble and change the 191 // Changing the alignment should close the system bubble and change the
194 // background color. 192 // background color.
195 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); 193 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
196 ASSERT_FALSE(tray->draw_background_as_active()); 194 ASSERT_FALSE(tray->draw_background_as_active());
197 RunAllPendingInMessageLoop(); 195 RunAllPendingInMessageLoop();
198 // The bubble should already be closed by now. 196 // The bubble should already be closed by now.
199 ASSERT_FALSE(tray->CloseSystemBubble()); 197 ASSERT_FALSE(tray->CloseSystemBubble());
200 } 198 }
201 199
202 TEST_F(SystemTrayTest, SystemTrayTestItems) { 200 TEST_F(SystemTrayTest, SystemTrayTestItems) {
203 SystemTray* tray = GetSystemTray(); 201 SystemTray* tray = GetPrimarySystemTray();
204 ASSERT_TRUE(tray->GetWidget()); 202 ASSERT_TRUE(tray->GetWidget());
205 203
206 TestItem* test_item = new TestItem; 204 TestItem* test_item = new TestItem;
207 TestItem* detailed_item = new TestItem; 205 TestItem* detailed_item = new TestItem;
208 tray->AddTrayItem(test_item); 206 tray->AddTrayItem(test_item);
209 tray->AddTrayItem(detailed_item); 207 tray->AddTrayItem(detailed_item);
210 208
211 // Check items have been added 209 // Check items have been added
212 const std::vector<SystemTrayItem*>& items = tray->GetTrayItems(); 210 const std::vector<SystemTrayItem*>& items = tray->GetTrayItems();
213 ASSERT_TRUE( 211 ASSERT_TRUE(
(...skipping 17 matching lines...) Expand all
231 ASSERT_TRUE(detailed_item->detailed_view() != NULL); 229 ASSERT_TRUE(detailed_item->detailed_view() != NULL);
232 230
233 // Show the default view, ensure it's created and the detailed view destroyed. 231 // Show the default view, ensure it's created and the detailed view destroyed.
234 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 232 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
235 RunAllPendingInMessageLoop(); 233 RunAllPendingInMessageLoop();
236 ASSERT_TRUE(test_item->default_view() != NULL); 234 ASSERT_TRUE(test_item->default_view() != NULL);
237 ASSERT_TRUE(detailed_item->detailed_view() == NULL); 235 ASSERT_TRUE(detailed_item->detailed_view() == NULL);
238 } 236 }
239 237
240 TEST_F(SystemTrayTest, SystemTrayNoViewItems) { 238 TEST_F(SystemTrayTest, SystemTrayNoViewItems) {
241 SystemTray* tray = GetSystemTray(); 239 SystemTray* tray = GetPrimarySystemTray();
242 ASSERT_TRUE(tray->GetWidget()); 240 ASSERT_TRUE(tray->GetWidget());
243 241
244 // Verify that no crashes occur on items lacking some views. 242 // Verify that no crashes occur on items lacking some views.
245 TestNoViewItem* no_view_item = new TestNoViewItem; 243 TestNoViewItem* no_view_item = new TestNoViewItem;
246 tray->AddTrayItem(no_view_item); 244 tray->AddTrayItem(no_view_item);
247 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 245 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
248 tray->ShowDetailedView(no_view_item, 0, false, BUBBLE_USE_EXISTING); 246 tray->ShowDetailedView(no_view_item, 0, false, BUBBLE_USE_EXISTING);
249 RunAllPendingInMessageLoop(); 247 RunAllPendingInMessageLoop();
250 } 248 }
251 249
252 TEST_F(SystemTrayTest, TrayWidgetAutoResizes) { 250 TEST_F(SystemTrayTest, TrayWidgetAutoResizes) {
253 SystemTray* tray = GetSystemTray(); 251 SystemTray* tray = GetPrimarySystemTray();
254 ASSERT_TRUE(tray->GetWidget()); 252 ASSERT_TRUE(tray->GetWidget());
255 253
256 // Add an initial tray item so that the tray gets laid out correctly. 254 // Add an initial tray item so that the tray gets laid out correctly.
257 TestItem* initial_item = new TestItem; 255 TestItem* initial_item = new TestItem;
258 tray->AddTrayItem(initial_item); 256 tray->AddTrayItem(initial_item);
259 257
260 gfx::Size initial_size = tray->GetWidget()->GetWindowBoundsInScreen().size(); 258 gfx::Size initial_size = tray->GetWidget()->GetWindowBoundsInScreen().size();
261 259
262 TestItem* new_item = new TestItem; 260 TestItem* new_item = new TestItem;
263 tray->AddTrayItem(new_item); 261 tray->AddTrayItem(new_item);
264 262
265 gfx::Size new_size = tray->GetWidget()->GetWindowBoundsInScreen().size(); 263 gfx::Size new_size = tray->GetWidget()->GetWindowBoundsInScreen().size();
266 264
267 // Adding the new item should change the size of the tray. 265 // Adding the new item should change the size of the tray.
268 EXPECT_NE(initial_size.ToString(), new_size.ToString()); 266 EXPECT_NE(initial_size.ToString(), new_size.ToString());
269 267
270 // Hiding the tray view of the new item should also change the size of the 268 // Hiding the tray view of the new item should also change the size of the
271 // tray. 269 // tray.
272 new_item->tray_view()->SetVisible(false); 270 new_item->tray_view()->SetVisible(false);
273 EXPECT_EQ(initial_size.ToString(), 271 EXPECT_EQ(initial_size.ToString(),
274 tray->GetWidget()->GetWindowBoundsInScreen().size().ToString()); 272 tray->GetWidget()->GetWindowBoundsInScreen().size().ToString());
275 273
276 new_item->tray_view()->SetVisible(true); 274 new_item->tray_view()->SetVisible(true);
277 EXPECT_EQ(new_size.ToString(), 275 EXPECT_EQ(new_size.ToString(),
278 tray->GetWidget()->GetWindowBoundsInScreen().size().ToString()); 276 tray->GetWidget()->GetWindowBoundsInScreen().size().ToString());
279 } 277 }
280 278
281 TEST_F(SystemTrayTest, SystemTrayNotifications) { 279 TEST_F(SystemTrayTest, SystemTrayNotifications) {
282 SystemTray* tray = GetSystemTray(); 280 SystemTray* tray = GetPrimarySystemTray();
283 ASSERT_TRUE(tray->GetWidget()); 281 ASSERT_TRUE(tray->GetWidget());
284 282
285 TestItem* test_item = new TestItem; 283 TestItem* test_item = new TestItem;
286 TestItem* detailed_item = new TestItem; 284 TestItem* detailed_item = new TestItem;
287 tray->AddTrayItem(test_item); 285 tray->AddTrayItem(test_item);
288 tray->AddTrayItem(detailed_item); 286 tray->AddTrayItem(detailed_item);
289 287
290 // Ensure the tray views are created. 288 // Ensure the tray views are created.
291 ASSERT_TRUE(test_item->tray_view() != NULL); 289 ASSERT_TRUE(test_item->tray_view() != NULL);
292 ASSERT_TRUE(detailed_item->tray_view() != NULL); 290 ASSERT_TRUE(detailed_item->tray_view() != NULL);
(...skipping 14 matching lines...) Expand all
307 ASSERT_TRUE(test_item->notification_view() != NULL); 305 ASSERT_TRUE(test_item->notification_view() != NULL);
308 306
309 // Hide the detailed view, ensure the notification view still exists. 307 // Hide the detailed view, ensure the notification view still exists.
310 ASSERT_TRUE(tray->CloseSystemBubble()); 308 ASSERT_TRUE(tray->CloseSystemBubble());
311 RunAllPendingInMessageLoop(); 309 RunAllPendingInMessageLoop();
312 ASSERT_TRUE(detailed_item->detailed_view() == NULL); 310 ASSERT_TRUE(detailed_item->detailed_view() == NULL);
313 ASSERT_TRUE(test_item->notification_view() != NULL); 311 ASSERT_TRUE(test_item->notification_view() != NULL);
314 } 312 }
315 313
316 TEST_F(SystemTrayTest, BubbleCreationTypesTest) { 314 TEST_F(SystemTrayTest, BubbleCreationTypesTest) {
317 SystemTray* tray = GetSystemTray(); 315 SystemTray* tray = GetPrimarySystemTray();
318 ASSERT_TRUE(tray->GetWidget()); 316 ASSERT_TRUE(tray->GetWidget());
319 317
320 TestItem* test_item = new TestItem; 318 TestItem* test_item = new TestItem;
321 tray->AddTrayItem(test_item); 319 tray->AddTrayItem(test_item);
322 320
323 // Ensure the tray views are created. 321 // Ensure the tray views are created.
324 ASSERT_TRUE(test_item->tray_view() != NULL); 322 ASSERT_TRUE(test_item->tray_view() != NULL);
325 323
326 // Show the default view, ensure the notification view is destroyed. 324 // Show the default view, ensure the notification view is destroyed.
327 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 325 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
(...skipping 12 matching lines...) Expand all
340 EXPECT_EQ(widget, test_item->detailed_view()->GetWidget()); 338 EXPECT_EQ(widget, test_item->detailed_view()->GetWidget());
341 339
342 tray->ShowDefaultView(BUBBLE_USE_EXISTING); 340 tray->ShowDefaultView(BUBBLE_USE_EXISTING);
343 RunAllPendingInMessageLoop(); 341 RunAllPendingInMessageLoop();
344 342
345 EXPECT_EQ(bubble_bounds.ToString(), test_item->default_view()->GetWidget()-> 343 EXPECT_EQ(bubble_bounds.ToString(), test_item->default_view()->GetWidget()->
346 GetWindowBoundsInScreen().ToString()); 344 GetWindowBoundsInScreen().ToString());
347 EXPECT_EQ(widget, test_item->default_view()->GetWidget()); 345 EXPECT_EQ(widget, test_item->default_view()->GetWidget());
348 } 346 }
349 347
350 // Tests that the tray is laid out properly and is fully contained within 348 // Tests that the tray view is laid out properly and is fully contained within
351 // the shelf. 349 // the shelf widget.
352 TEST_F(SystemTrayTest, TrayBoundsInWidget) { 350 TEST_F(SystemTrayTest, TrayBoundsInWidget) {
353 Shelf* shelf = Shelf::ForPrimaryDisplay(); 351 Shelf* shelf = Shelf::ForPrimaryDisplay();
354 StatusAreaWidget* widget = Shell::GetPrimaryRootWindowController() 352 StatusAreaWidget* widget = StatusAreaWidgetTestHelper::GetStatusAreaWidget();
355 ->shelf_widget() 353 SystemTray* tray = GetPrimarySystemTray();
356 ->status_area_widget();
357 SystemTray* tray = widget->system_tray();
358 354
359 // Test in bottom alignment. 355 // Test in bottom alignment.
360 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); 356 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM);
361 gfx::Rect window_bounds = widget->GetWindowBoundsInScreen(); 357 gfx::Rect window_bounds = widget->GetWindowBoundsInScreen();
362 gfx::Rect tray_bounds = tray->GetBoundsInScreen(); 358 gfx::Rect tray_bounds = tray->GetBoundsInScreen();
363 EXPECT_TRUE(window_bounds.bottom() >= tray_bounds.bottom()); 359 EXPECT_TRUE(window_bounds.Contains(tray_bounds));
364 EXPECT_TRUE(window_bounds.right() >= tray_bounds.right());
365 EXPECT_TRUE(window_bounds.x() >= tray_bounds.x());
366 EXPECT_TRUE(window_bounds.y() >= tray_bounds.y());
367 360
368 // Test in locked alignment. 361 // Test in locked alignment.
369 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM_LOCKED); 362 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM_LOCKED);
370 window_bounds = widget->GetWindowBoundsInScreen(); 363 window_bounds = widget->GetWindowBoundsInScreen();
371 tray_bounds = tray->GetBoundsInScreen(); 364 tray_bounds = tray->GetBoundsInScreen();
372 EXPECT_TRUE(window_bounds.bottom() >= tray_bounds.bottom()); 365 EXPECT_TRUE(window_bounds.Contains(tray_bounds));
373 EXPECT_TRUE(window_bounds.right() >= tray_bounds.right());
374 EXPECT_TRUE(window_bounds.x() >= tray_bounds.x());
375 EXPECT_TRUE(window_bounds.y() >= tray_bounds.y());
376 366
377 // Test in the left alignment. 367 // Test in the left alignment.
378 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); 368 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
379 window_bounds = widget->GetWindowBoundsInScreen(); 369 window_bounds = widget->GetWindowBoundsInScreen();
380 tray_bounds = tray->GetBoundsInScreen(); 370 tray_bounds = tray->GetBoundsInScreen();
381 EXPECT_TRUE(window_bounds.bottom() >= tray_bounds.bottom()); 371 EXPECT_TRUE(window_bounds.Contains(tray_bounds));
382 EXPECT_TRUE(window_bounds.right() >= tray_bounds.right());
383 EXPECT_TRUE(window_bounds.x() >= tray_bounds.x());
384 EXPECT_TRUE(window_bounds.y() >= tray_bounds.y());
385 372
386 // Test in the right alignment. 373 // Test in the right alignment.
387 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); 374 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
388 window_bounds = widget->GetWindowBoundsInScreen(); 375 window_bounds = widget->GetWindowBoundsInScreen();
389 tray_bounds = tray->GetBoundsInScreen(); 376 tray_bounds = tray->GetBoundsInScreen();
390 EXPECT_TRUE(window_bounds.bottom() >= tray_bounds.bottom()); 377 EXPECT_TRUE(window_bounds.Contains(tray_bounds));
391 EXPECT_TRUE(window_bounds.right() >= tray_bounds.right());
392 EXPECT_TRUE(window_bounds.x() >= tray_bounds.x());
393 EXPECT_TRUE(window_bounds.y() >= tray_bounds.y());
394 } 378 }
395 379
396 TEST_F(SystemTrayTest, PersistentBubble) { 380 TEST_F(SystemTrayTest, PersistentBubble) {
397 SystemTray* tray = GetSystemTray(); 381 SystemTray* tray = GetPrimarySystemTray();
398 ASSERT_TRUE(tray->GetWidget()); 382 ASSERT_TRUE(tray->GetWidget());
399 383
400 TestItem* test_item = new TestItem; 384 TestItem* test_item = new TestItem;
401 tray->AddTrayItem(test_item); 385 tray->AddTrayItem(test_item);
402 386
403 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 387 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
404 388
405 // Tests for usual default view. 389 // Tests for usual default view.
406 // Activating window. 390 // Activating window.
407 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 391 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 // Check if the accessibility item is created even with system modal 428 // Check if the accessibility item is created even with system modal
445 // dialog. 429 // dialog.
446 Shell::GetInstance()->accessibility_delegate()->SetVirtualKeyboardEnabled( 430 Shell::GetInstance()->accessibility_delegate()->SetVirtualKeyboardEnabled(
447 true); 431 true);
448 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( 432 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
449 new ModalWidgetDelegate(), 433 new ModalWidgetDelegate(),
450 Shell::GetPrimaryRootWindow(), 434 Shell::GetPrimaryRootWindow(),
451 gfx::Rect(0, 0, 100, 100)); 435 gfx::Rect(0, 0, 100, 100));
452 widget->Show(); 436 widget->Show();
453 437
454 SystemTray* tray = GetSystemTray(); 438 SystemTray* tray = GetPrimarySystemTray();
455 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 439 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
456 440
457 ASSERT_TRUE(tray->HasSystemBubble()); 441 ASSERT_TRUE(tray->HasSystemBubble());
458 const views::View* accessibility = 442 const views::View* accessibility =
459 tray->GetSystemBubble()->bubble_view()->GetViewByID( 443 tray->GetSystemBubble()->bubble_view()->GetViewByID(
460 test::kAccessibilityTrayItemViewId); 444 test::kAccessibilityTrayItemViewId);
461 ASSERT_TRUE(accessibility); 445 ASSERT_TRUE(accessibility);
462 EXPECT_TRUE(accessibility->visible()); 446 EXPECT_TRUE(accessibility->visible());
463 EXPECT_FALSE(tray->GetSystemBubble()->bubble_view()->GetViewByID( 447 EXPECT_FALSE(tray->GetSystemBubble()->bubble_view()->GetViewByID(
464 test::kSettingsTrayItemViewId)); 448 test::kSettingsTrayItemViewId));
(...skipping 11 matching lines...) Expand all
476 const views::View* settings = 460 const views::View* settings =
477 tray->GetSystemBubble()->bubble_view()->GetViewByID( 461 tray->GetSystemBubble()->bubble_view()->GetViewByID(
478 test::kSettingsTrayItemViewId); 462 test::kSettingsTrayItemViewId);
479 ASSERT_TRUE(settings); 463 ASSERT_TRUE(settings);
480 EXPECT_TRUE(settings->visible()); 464 EXPECT_TRUE(settings->visible());
481 } 465 }
482 466
483 // Tests that if SetVisible(true) is called while animating to hidden that the 467 // Tests that if SetVisible(true) is called while animating to hidden that the
484 // tray becomes visible, and stops animating to hidden. 468 // tray becomes visible, and stops animating to hidden.
485 TEST_F(SystemTrayTest, SetVisibleDuringHideAnimation) { 469 TEST_F(SystemTrayTest, SetVisibleDuringHideAnimation) {
486 SystemTray* tray = GetSystemTray(); 470 SystemTray* tray = GetPrimarySystemTray();
487 ASSERT_TRUE(tray->visible()); 471 ASSERT_TRUE(tray->visible());
488 472
489 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> animation_duration; 473 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> animation_duration;
490 animation_duration.reset( 474 animation_duration.reset(
491 new ui::ScopedAnimationDurationScaleMode( 475 new ui::ScopedAnimationDurationScaleMode(
492 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); 476 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION));
493 tray->SetVisible(false); 477 tray->SetVisible(false);
494 EXPECT_TRUE(tray->visible()); 478 EXPECT_TRUE(tray->visible());
495 EXPECT_EQ(0.0f, tray->layer()->GetTargetOpacity()); 479 EXPECT_EQ(0.0f, tray->layer()->GetTargetOpacity());
496 480
497 tray->SetVisible(true); 481 tray->SetVisible(true);
498 animation_duration.reset(); 482 animation_duration.reset();
499 tray->layer()->GetAnimator()->StopAnimating(); 483 tray->layer()->GetAnimator()->StopAnimating();
500 EXPECT_TRUE(tray->visible()); 484 EXPECT_TRUE(tray->visible());
501 EXPECT_EQ(1.0f, tray->layer()->GetTargetOpacity()); 485 EXPECT_EQ(1.0f, tray->layer()->GetTargetOpacity());
502 } 486 }
503 487
504 #if defined(OS_CHROMEOS) 488 #if defined(OS_CHROMEOS)
505 // Tests that touch on an item in the system bubble triggers it to become 489 // Tests that touch on an item in the system bubble triggers it to become
506 // active. 490 // active.
507 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedback) { 491 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedback) {
508 SystemTray* tray = GetSystemTray(); 492 SystemTray* tray = GetPrimarySystemTray();
509 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 493 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
510 494
511 TrayPopupItemContainer* view = 495 TrayPopupItemContainer* view =
512 static_cast<TrayPopupItemContainer*>(tray->GetSystemBubble()-> 496 static_cast<TrayPopupItemContainer*>(tray->GetSystemBubble()->
513 bubble_view()->child_at(0)); 497 bubble_view()->child_at(0));
514 EXPECT_FALSE(view->active()); 498 EXPECT_FALSE(view->active());
515 499
516 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 500 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
517 generator.set_current_location(view->GetBoundsInScreen().CenterPoint()); 501 generator.set_current_location(view->GetBoundsInScreen().CenterPoint());
518 generator.PressTouch(); 502 generator.PressTouch();
519 EXPECT_TRUE(view->active()); 503 EXPECT_TRUE(view->active());
520 504
521 generator.ReleaseTouch(); 505 generator.ReleaseTouch();
522 EXPECT_FALSE(view->active()); 506 EXPECT_FALSE(view->active());
523 } 507 }
524 508
525 // Tests that touch events on an item in the system bubble cause it to stop 509 // Tests that touch events on an item in the system bubble cause it to stop
526 // being active. 510 // being active.
527 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedbackCancellation) { 511 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedbackCancellation) {
528 SystemTray* tray = GetSystemTray(); 512 SystemTray* tray = GetPrimarySystemTray();
529 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 513 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
530 514
531 TrayPopupItemContainer* view = 515 TrayPopupItemContainer* view =
532 static_cast<TrayPopupItemContainer*>(tray->GetSystemBubble()-> 516 static_cast<TrayPopupItemContainer*>(tray->GetSystemBubble()->
533 bubble_view()->child_at(0)); 517 bubble_view()->child_at(0));
534 EXPECT_FALSE(view->active()); 518 EXPECT_FALSE(view->active());
535 519
536 gfx::Rect view_bounds = view->GetBoundsInScreen(); 520 gfx::Rect view_bounds = view->GetBoundsInScreen();
537 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 521 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
538 generator.set_current_location(view_bounds.CenterPoint()); 522 generator.set_current_location(view_bounds.CenterPoint());
539 generator.PressTouch(); 523 generator.PressTouch();
540 EXPECT_TRUE(view->active()); 524 EXPECT_TRUE(view->active());
541 525
542 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); 526 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y());
543 generator.MoveTouch(move_point); 527 generator.MoveTouch(move_point);
544 EXPECT_FALSE(view->active()); 528 EXPECT_FALSE(view->active());
545 529
546 generator.set_current_location(move_point); 530 generator.set_current_location(move_point);
547 generator.ReleaseTouch(); 531 generator.ReleaseTouch();
548 EXPECT_FALSE(view->active()); 532 EXPECT_FALSE(view->active());
549 } 533 }
550 534
551 TEST_F(SystemTrayTest, SystemTrayHeightWithBubble) { 535 TEST_F(SystemTrayTest, SystemTrayHeightWithBubble) {
552 StatusAreaWidget* widget = Shell::GetPrimaryRootWindowController() 536 SystemTray* tray = GetPrimarySystemTray();
553 ->shelf_widget()
554 ->status_area_widget();
555 SystemTray* tray = widget->system_tray();
556 WebNotificationTray* notification_tray = 537 WebNotificationTray* notification_tray =
557 tray->status_area_widget()->web_notification_tray(); 538 tray->status_area_widget()->web_notification_tray();
558 539
559 // Ensure the initial system tray height is zero. 540 // Ensure the initial system tray height is zero.
560 EXPECT_EQ(0, notification_tray->system_tray_height_for_test()); 541 EXPECT_EQ(0, notification_tray->system_tray_height_for_test());
561 542
562 // Show the default view, ensure the system tray height is changed. 543 // Show the default view, ensure the system tray height is changed.
563 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 544 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
564 RunAllPendingInMessageLoop(); 545 RunAllPendingInMessageLoop();
565 EXPECT_LT(0, notification_tray->system_tray_height_for_test()); 546 EXPECT_LT(0, notification_tray->system_tray_height_for_test());
566 547
567 // Hide the default view, ensure the system tray height is back to zero. 548 // Hide the default view, ensure the system tray height is back to zero.
568 ASSERT_TRUE(tray->CloseSystemBubble()); 549 ASSERT_TRUE(tray->CloseSystemBubble());
569 RunAllPendingInMessageLoop(); 550 RunAllPendingInMessageLoop();
570 551
571 EXPECT_EQ(0, notification_tray->system_tray_height_for_test()); 552 EXPECT_EQ(0, notification_tray->system_tray_height_for_test());
572 } 553 }
573 #endif // OS_CHROMEOS 554 #endif // OS_CHROMEOS
574 555
575 } // namespace test 556 } // namespace test
576 } // namespace ash 557 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/system_tray.cc ('k') | ash/system/tray/tray_background_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698