| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/system/tray/system_tray.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "ash/common/accessibility_delegate.h" | |
| 10 #include "ash/common/shelf/wm_shelf.h" | |
| 11 #include "ash/common/system/tray/system_tray_bubble.h" | |
| 12 #include "ash/common/system/tray/system_tray_item.h" | |
| 13 #include "ash/common/system/tray/tray_constants.h" | |
| 14 #include "ash/common/system/tray/tray_popup_item_container.h" | |
| 15 #include "ash/common/system/web_notification/web_notification_tray.h" | |
| 16 #include "ash/common/wm_shell.h" | |
| 17 #include "ash/shell.h" | |
| 18 #include "ash/system/status_area_widget.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" | |
| 22 #include "base/run_loop.h" | |
| 23 #include "base/strings/utf_string_conversions.h" | |
| 24 #include "ui/aura/window.h" | |
| 25 #include "ui/base/ui_base_types.h" | |
| 26 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | |
| 27 #include "ui/events/test/event_generator.h" | |
| 28 #include "ui/gfx/geometry/point.h" | |
| 29 #include "ui/gfx/geometry/rect.h" | |
| 30 #include "ui/views/controls/label.h" | |
| 31 #include "ui/views/layout/fill_layout.h" | |
| 32 #include "ui/views/view.h" | |
| 33 #include "ui/views/widget/widget.h" | |
| 34 #include "ui/views/widget/widget_delegate.h" | |
| 35 | |
| 36 #if defined(OS_WIN) | |
| 37 #include "base/win/windows_version.h" | |
| 38 #endif | |
| 39 | |
| 40 namespace ash { | |
| 41 namespace test { | |
| 42 | |
| 43 namespace { | |
| 44 | |
| 45 // Trivial item implementation that tracks its views for testing. | |
| 46 class TestItem : public SystemTrayItem { | |
| 47 public: | |
| 48 TestItem() | |
| 49 : SystemTrayItem(AshTestBase::GetPrimarySystemTray()), | |
| 50 tray_view_(nullptr), | |
| 51 default_view_(nullptr), | |
| 52 detailed_view_(nullptr), | |
| 53 notification_view_(nullptr) {} | |
| 54 | |
| 55 views::View* CreateTrayView(LoginStatus status) override { | |
| 56 tray_view_ = new views::View; | |
| 57 // Add a label so it has non-zero width. | |
| 58 tray_view_->SetLayoutManager(new views::FillLayout); | |
| 59 tray_view_->AddChildView(new views::Label(base::UTF8ToUTF16("Tray"))); | |
| 60 return tray_view_; | |
| 61 } | |
| 62 | |
| 63 views::View* CreateDefaultView(LoginStatus status) override { | |
| 64 default_view_ = new views::View; | |
| 65 default_view_->SetLayoutManager(new views::FillLayout); | |
| 66 default_view_->AddChildView(new views::Label(base::UTF8ToUTF16("Default"))); | |
| 67 return default_view_; | |
| 68 } | |
| 69 | |
| 70 views::View* CreateDetailedView(LoginStatus status) override { | |
| 71 detailed_view_ = new views::View; | |
| 72 detailed_view_->SetLayoutManager(new views::FillLayout); | |
| 73 detailed_view_->AddChildView( | |
| 74 new views::Label(base::UTF8ToUTF16("Detailed"))); | |
| 75 return detailed_view_; | |
| 76 } | |
| 77 | |
| 78 views::View* CreateNotificationView(LoginStatus status) override { | |
| 79 notification_view_ = new views::View; | |
| 80 return notification_view_; | |
| 81 } | |
| 82 | |
| 83 void DestroyTrayView() override { tray_view_ = NULL; } | |
| 84 | |
| 85 void DestroyDefaultView() override { default_view_ = NULL; } | |
| 86 | |
| 87 void DestroyDetailedView() override { detailed_view_ = NULL; } | |
| 88 | |
| 89 void DestroyNotificationView() override { notification_view_ = NULL; } | |
| 90 | |
| 91 void UpdateAfterLoginStatusChange(LoginStatus status) override {} | |
| 92 | |
| 93 views::View* tray_view() const { return tray_view_; } | |
| 94 views::View* default_view() const { return default_view_; } | |
| 95 views::View* detailed_view() const { return detailed_view_; } | |
| 96 views::View* notification_view() const { return notification_view_; } | |
| 97 | |
| 98 private: | |
| 99 views::View* tray_view_; | |
| 100 views::View* default_view_; | |
| 101 views::View* detailed_view_; | |
| 102 views::View* notification_view_; | |
| 103 }; | |
| 104 | |
| 105 // Trivial item implementation that returns NULL from tray/default/detailed | |
| 106 // view creation methods. | |
| 107 class TestNoViewItem : public SystemTrayItem { | |
| 108 public: | |
| 109 TestNoViewItem() : SystemTrayItem(AshTestBase::GetPrimarySystemTray()) {} | |
| 110 | |
| 111 views::View* CreateTrayView(LoginStatus status) override { return nullptr; } | |
| 112 | |
| 113 views::View* CreateDefaultView(LoginStatus status) override { | |
| 114 return nullptr; | |
| 115 } | |
| 116 | |
| 117 views::View* CreateDetailedView(LoginStatus status) override { | |
| 118 return nullptr; | |
| 119 } | |
| 120 | |
| 121 views::View* CreateNotificationView(LoginStatus status) override { | |
| 122 return nullptr; | |
| 123 } | |
| 124 | |
| 125 void DestroyTrayView() override {} | |
| 126 void DestroyDefaultView() override {} | |
| 127 void DestroyDetailedView() override {} | |
| 128 void DestroyNotificationView() override {} | |
| 129 void UpdateAfterLoginStatusChange(LoginStatus status) override {} | |
| 130 }; | |
| 131 | |
| 132 class ModalWidgetDelegate : public views::WidgetDelegateView { | |
| 133 public: | |
| 134 ModalWidgetDelegate() {} | |
| 135 ~ModalWidgetDelegate() override {} | |
| 136 | |
| 137 views::View* GetContentsView() override { return this; } | |
| 138 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_SYSTEM; } | |
| 139 | |
| 140 private: | |
| 141 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate); | |
| 142 }; | |
| 143 | |
| 144 } // namespace | |
| 145 | |
| 146 typedef AshTestBase SystemTrayTest; | |
| 147 | |
| 148 TEST_F(SystemTrayTest, SystemTrayDefaultView) { | |
| 149 SystemTray* tray = GetPrimarySystemTray(); | |
| 150 ASSERT_TRUE(tray->GetWidget()); | |
| 151 | |
| 152 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 153 | |
| 154 // Ensure that closing the bubble destroys it. | |
| 155 ASSERT_TRUE(tray->CloseSystemBubble()); | |
| 156 RunAllPendingInMessageLoop(); | |
| 157 ASSERT_FALSE(tray->CloseSystemBubble()); | |
| 158 } | |
| 159 | |
| 160 // Opening and closing the bubble should change the coloring of the tray. | |
| 161 TEST_F(SystemTrayTest, SystemTrayColoring) { | |
| 162 SystemTray* tray = GetPrimarySystemTray(); | |
| 163 ASSERT_TRUE(tray->GetWidget()); | |
| 164 // At the beginning the tray coloring is not active. | |
| 165 ASSERT_FALSE(tray->draw_background_as_active()); | |
| 166 | |
| 167 // Showing the system bubble should show the background as active. | |
| 168 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 169 ASSERT_TRUE(tray->draw_background_as_active()); | |
| 170 | |
| 171 // Closing the system menu should change the coloring back to normal. | |
| 172 ASSERT_TRUE(tray->CloseSystemBubble()); | |
| 173 RunAllPendingInMessageLoop(); | |
| 174 ASSERT_FALSE(tray->draw_background_as_active()); | |
| 175 } | |
| 176 | |
| 177 // Closing the system bubble through an alignment change should change the | |
| 178 // system tray coloring back to normal. | |
| 179 TEST_F(SystemTrayTest, SystemTrayColoringAfterAlignmentChange) { | |
| 180 SystemTray* tray = GetPrimarySystemTray(); | |
| 181 ASSERT_TRUE(tray->GetWidget()); | |
| 182 WmShelf* shelf = GetPrimaryShelf(); | |
| 183 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | |
| 184 // At the beginning the tray coloring is not active. | |
| 185 ASSERT_FALSE(tray->draw_background_as_active()); | |
| 186 | |
| 187 // Showing the system bubble should show the background as active. | |
| 188 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 189 ASSERT_TRUE(tray->draw_background_as_active()); | |
| 190 | |
| 191 // Changing the alignment should close the system bubble and change the | |
| 192 // background color. | |
| 193 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); | |
| 194 ASSERT_FALSE(tray->draw_background_as_active()); | |
| 195 RunAllPendingInMessageLoop(); | |
| 196 // The bubble should already be closed by now. | |
| 197 ASSERT_FALSE(tray->CloseSystemBubble()); | |
| 198 } | |
| 199 | |
| 200 TEST_F(SystemTrayTest, SystemTrayTestItems) { | |
| 201 SystemTray* tray = GetPrimarySystemTray(); | |
| 202 ASSERT_TRUE(tray->GetWidget()); | |
| 203 | |
| 204 TestItem* test_item = new TestItem; | |
| 205 TestItem* detailed_item = new TestItem; | |
| 206 tray->AddTrayItem(test_item); | |
| 207 tray->AddTrayItem(detailed_item); | |
| 208 | |
| 209 // Check items have been added | |
| 210 const std::vector<SystemTrayItem*>& items = tray->GetTrayItems(); | |
| 211 ASSERT_TRUE(std::find(items.begin(), items.end(), test_item) != items.end()); | |
| 212 ASSERT_TRUE(std::find(items.begin(), items.end(), detailed_item) != | |
| 213 items.end()); | |
| 214 | |
| 215 // Ensure the tray views are created. | |
| 216 ASSERT_TRUE(test_item->tray_view() != NULL); | |
| 217 ASSERT_TRUE(detailed_item->tray_view() != NULL); | |
| 218 | |
| 219 // Ensure a default views are created. | |
| 220 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 221 ASSERT_TRUE(test_item->default_view() != NULL); | |
| 222 ASSERT_TRUE(detailed_item->default_view() != NULL); | |
| 223 | |
| 224 // Show the detailed view, ensure it's created and the default view destroyed. | |
| 225 tray->ShowDetailedView(detailed_item, 0, false, BUBBLE_CREATE_NEW); | |
| 226 RunAllPendingInMessageLoop(); | |
| 227 ASSERT_TRUE(test_item->default_view() == NULL); | |
| 228 ASSERT_TRUE(detailed_item->detailed_view() != NULL); | |
| 229 | |
| 230 // Show the default view, ensure it's created and the detailed view destroyed. | |
| 231 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 232 RunAllPendingInMessageLoop(); | |
| 233 ASSERT_TRUE(test_item->default_view() != NULL); | |
| 234 ASSERT_TRUE(detailed_item->detailed_view() == NULL); | |
| 235 } | |
| 236 | |
| 237 TEST_F(SystemTrayTest, SystemTrayNoViewItems) { | |
| 238 SystemTray* tray = GetPrimarySystemTray(); | |
| 239 ASSERT_TRUE(tray->GetWidget()); | |
| 240 | |
| 241 // Verify that no crashes occur on items lacking some views. | |
| 242 TestNoViewItem* no_view_item = new TestNoViewItem; | |
| 243 tray->AddTrayItem(no_view_item); | |
| 244 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 245 tray->ShowDetailedView(no_view_item, 0, false, BUBBLE_USE_EXISTING); | |
| 246 RunAllPendingInMessageLoop(); | |
| 247 } | |
| 248 | |
| 249 TEST_F(SystemTrayTest, TrayWidgetAutoResizes) { | |
| 250 SystemTray* tray = GetPrimarySystemTray(); | |
| 251 ASSERT_TRUE(tray->GetWidget()); | |
| 252 | |
| 253 // Add an initial tray item so that the tray gets laid out correctly. | |
| 254 TestItem* initial_item = new TestItem; | |
| 255 tray->AddTrayItem(initial_item); | |
| 256 | |
| 257 gfx::Size initial_size = tray->GetWidget()->GetWindowBoundsInScreen().size(); | |
| 258 | |
| 259 TestItem* new_item = new TestItem; | |
| 260 tray->AddTrayItem(new_item); | |
| 261 | |
| 262 gfx::Size new_size = tray->GetWidget()->GetWindowBoundsInScreen().size(); | |
| 263 | |
| 264 // Adding the new item should change the size of the tray. | |
| 265 EXPECT_NE(initial_size.ToString(), new_size.ToString()); | |
| 266 | |
| 267 // Hiding the tray view of the new item should also change the size of the | |
| 268 // tray. | |
| 269 new_item->tray_view()->SetVisible(false); | |
| 270 EXPECT_EQ(initial_size.ToString(), | |
| 271 tray->GetWidget()->GetWindowBoundsInScreen().size().ToString()); | |
| 272 | |
| 273 new_item->tray_view()->SetVisible(true); | |
| 274 EXPECT_EQ(new_size.ToString(), | |
| 275 tray->GetWidget()->GetWindowBoundsInScreen().size().ToString()); | |
| 276 } | |
| 277 | |
| 278 TEST_F(SystemTrayTest, SystemTrayNotifications) { | |
| 279 SystemTray* tray = GetPrimarySystemTray(); | |
| 280 ASSERT_TRUE(tray->GetWidget()); | |
| 281 | |
| 282 TestItem* test_item = new TestItem; | |
| 283 TestItem* detailed_item = new TestItem; | |
| 284 tray->AddTrayItem(test_item); | |
| 285 tray->AddTrayItem(detailed_item); | |
| 286 | |
| 287 // Ensure the tray views are created. | |
| 288 ASSERT_TRUE(test_item->tray_view() != NULL); | |
| 289 ASSERT_TRUE(detailed_item->tray_view() != NULL); | |
| 290 | |
| 291 // Ensure a notification view is created. | |
| 292 tray->ShowNotificationView(test_item); | |
| 293 ASSERT_TRUE(test_item->notification_view() != NULL); | |
| 294 | |
| 295 // Show the default view, notification view should remain. | |
| 296 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 297 RunAllPendingInMessageLoop(); | |
| 298 ASSERT_TRUE(test_item->notification_view() != NULL); | |
| 299 | |
| 300 // Show the detailed view, ensure the notification view remains. | |
| 301 tray->ShowDetailedView(detailed_item, 0, false, BUBBLE_CREATE_NEW); | |
| 302 RunAllPendingInMessageLoop(); | |
| 303 ASSERT_TRUE(detailed_item->detailed_view() != NULL); | |
| 304 ASSERT_TRUE(test_item->notification_view() != NULL); | |
| 305 | |
| 306 // Hide the detailed view, ensure the notification view still exists. | |
| 307 ASSERT_TRUE(tray->CloseSystemBubble()); | |
| 308 RunAllPendingInMessageLoop(); | |
| 309 ASSERT_TRUE(detailed_item->detailed_view() == NULL); | |
| 310 ASSERT_TRUE(test_item->notification_view() != NULL); | |
| 311 } | |
| 312 | |
| 313 TEST_F(SystemTrayTest, BubbleCreationTypesTest) { | |
| 314 SystemTray* tray = GetPrimarySystemTray(); | |
| 315 ASSERT_TRUE(tray->GetWidget()); | |
| 316 | |
| 317 TestItem* test_item = new TestItem; | |
| 318 tray->AddTrayItem(test_item); | |
| 319 | |
| 320 // Ensure the tray views are created. | |
| 321 ASSERT_TRUE(test_item->tray_view() != NULL); | |
| 322 | |
| 323 // Show the default view, ensure the notification view is destroyed. | |
| 324 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 325 RunAllPendingInMessageLoop(); | |
| 326 | |
| 327 views::Widget* widget = test_item->default_view()->GetWidget(); | |
| 328 gfx::Rect bubble_bounds = widget->GetWindowBoundsInScreen(); | |
| 329 | |
| 330 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); | |
| 331 RunAllPendingInMessageLoop(); | |
| 332 | |
| 333 EXPECT_FALSE(test_item->default_view()); | |
| 334 | |
| 335 EXPECT_EQ(bubble_bounds.ToString(), test_item->detailed_view() | |
| 336 ->GetWidget() | |
| 337 ->GetWindowBoundsInScreen() | |
| 338 .ToString()); | |
| 339 EXPECT_EQ(widget, test_item->detailed_view()->GetWidget()); | |
| 340 | |
| 341 tray->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 342 RunAllPendingInMessageLoop(); | |
| 343 | |
| 344 EXPECT_EQ(bubble_bounds.ToString(), test_item->default_view() | |
| 345 ->GetWidget() | |
| 346 ->GetWindowBoundsInScreen() | |
| 347 .ToString()); | |
| 348 EXPECT_EQ(widget, test_item->default_view()->GetWidget()); | |
| 349 } | |
| 350 | |
| 351 // Tests that the tray view is laid out properly and is fully contained within | |
| 352 // the shelf widget. | |
| 353 TEST_F(SystemTrayTest, TrayBoundsInWidget) { | |
| 354 WmShelf* shelf = GetPrimaryShelf(); | |
| 355 StatusAreaWidget* widget = StatusAreaWidgetTestHelper::GetStatusAreaWidget(); | |
| 356 SystemTray* tray = GetPrimarySystemTray(); | |
| 357 | |
| 358 // Test in bottom alignment. | |
| 359 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | |
| 360 gfx::Rect window_bounds = widget->GetWindowBoundsInScreen(); | |
| 361 gfx::Rect tray_bounds = tray->GetBoundsInScreen(); | |
| 362 EXPECT_TRUE(window_bounds.Contains(tray_bounds)); | |
| 363 | |
| 364 // Test in locked alignment. | |
| 365 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM_LOCKED); | |
| 366 window_bounds = widget->GetWindowBoundsInScreen(); | |
| 367 tray_bounds = tray->GetBoundsInScreen(); | |
| 368 EXPECT_TRUE(window_bounds.Contains(tray_bounds)); | |
| 369 | |
| 370 // Test in the left alignment. | |
| 371 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); | |
| 372 window_bounds = widget->GetWindowBoundsInScreen(); | |
| 373 tray_bounds = tray->GetBoundsInScreen(); | |
| 374 EXPECT_TRUE(window_bounds.Contains(tray_bounds)); | |
| 375 | |
| 376 // Test in the right alignment. | |
| 377 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); | |
| 378 window_bounds = widget->GetWindowBoundsInScreen(); | |
| 379 tray_bounds = tray->GetBoundsInScreen(); | |
| 380 EXPECT_TRUE(window_bounds.Contains(tray_bounds)); | |
| 381 } | |
| 382 | |
| 383 TEST_F(SystemTrayTest, PersistentBubble) { | |
| 384 SystemTray* tray = GetPrimarySystemTray(); | |
| 385 ASSERT_TRUE(tray->GetWidget()); | |
| 386 | |
| 387 TestItem* test_item = new TestItem; | |
| 388 tray->AddTrayItem(test_item); | |
| 389 | |
| 390 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | |
| 391 | |
| 392 // Tests for usual default view. | |
| 393 // Activating window. | |
| 394 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 395 ASSERT_TRUE(tray->HasSystemBubble()); | |
| 396 wm::ActivateWindow(window.get()); | |
| 397 base::RunLoop().RunUntilIdle(); | |
| 398 ASSERT_FALSE(tray->HasSystemBubble()); | |
| 399 | |
| 400 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 401 ASSERT_TRUE(tray->HasSystemBubble()); | |
| 402 { | |
| 403 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | |
| 404 gfx::Point(5, 5)); | |
| 405 generator.ClickLeftButton(); | |
| 406 ASSERT_FALSE(tray->HasSystemBubble()); | |
| 407 } | |
| 408 | |
| 409 // Same tests for persistent default view. | |
| 410 tray->ShowPersistentDefaultView(); | |
| 411 ASSERT_TRUE(tray->HasSystemBubble()); | |
| 412 wm::ActivateWindow(window.get()); | |
| 413 base::RunLoop().RunUntilIdle(); | |
| 414 ASSERT_TRUE(tray->HasSystemBubble()); | |
| 415 | |
| 416 { | |
| 417 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | |
| 418 gfx::Point(5, 5)); | |
| 419 generator.ClickLeftButton(); | |
| 420 ASSERT_TRUE(tray->HasSystemBubble()); | |
| 421 } | |
| 422 } | |
| 423 | |
| 424 #if defined(OS_CHROMEOS) | |
| 425 // Accessibility/Settings tray items are available only on cros. | |
| 426 #define MAYBE_WithSystemModal WithSystemModal | |
| 427 #else | |
| 428 #define MAYBE_WithSystemModal DISABLED_WithSystemModal | |
| 429 #endif | |
| 430 TEST_F(SystemTrayTest, MAYBE_WithSystemModal) { | |
| 431 // Check if the accessibility item is created even with system modal dialog. | |
| 432 WmShell::Get()->GetAccessibilityDelegate()->SetVirtualKeyboardEnabled(true); | |
| 433 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( | |
| 434 new ModalWidgetDelegate(), Shell::GetPrimaryRootWindow(), | |
| 435 gfx::Rect(0, 0, 100, 100)); | |
| 436 widget->Show(); | |
| 437 | |
| 438 SystemTray* tray = GetPrimarySystemTray(); | |
| 439 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 440 | |
| 441 ASSERT_TRUE(tray->HasSystemBubble()); | |
| 442 const views::View* accessibility = | |
| 443 tray->GetSystemBubble()->bubble_view()->GetViewByID( | |
| 444 test::kAccessibilityTrayItemViewId); | |
| 445 ASSERT_TRUE(accessibility); | |
| 446 EXPECT_TRUE(accessibility->visible()); | |
| 447 EXPECT_FALSE(tray->GetSystemBubble()->bubble_view()->GetViewByID( | |
| 448 test::kSettingsTrayItemViewId)); | |
| 449 | |
| 450 widget->Close(); | |
| 451 | |
| 452 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 453 // System modal is gone. The bubble should now contains settings | |
| 454 // as well. | |
| 455 accessibility = tray->GetSystemBubble()->bubble_view()->GetViewByID( | |
| 456 test::kAccessibilityTrayItemViewId); | |
| 457 ASSERT_TRUE(accessibility); | |
| 458 EXPECT_TRUE(accessibility->visible()); | |
| 459 | |
| 460 const views::View* settings = | |
| 461 tray->GetSystemBubble()->bubble_view()->GetViewByID( | |
| 462 test::kSettingsTrayItemViewId); | |
| 463 ASSERT_TRUE(settings); | |
| 464 EXPECT_TRUE(settings->visible()); | |
| 465 } | |
| 466 | |
| 467 // Tests that if SetVisible(true) is called while animating to hidden that the | |
| 468 // tray becomes visible, and stops animating to hidden. | |
| 469 TEST_F(SystemTrayTest, SetVisibleDuringHideAnimation) { | |
| 470 SystemTray* tray = GetPrimarySystemTray(); | |
| 471 ASSERT_TRUE(tray->visible()); | |
| 472 | |
| 473 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> animation_duration; | |
| 474 animation_duration.reset(new ui::ScopedAnimationDurationScaleMode( | |
| 475 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); | |
| 476 tray->SetVisible(false); | |
| 477 EXPECT_TRUE(tray->visible()); | |
| 478 EXPECT_EQ(0.0f, tray->layer()->GetTargetOpacity()); | |
| 479 | |
| 480 tray->SetVisible(true); | |
| 481 animation_duration.reset(); | |
| 482 tray->layer()->GetAnimator()->StopAnimating(); | |
| 483 EXPECT_TRUE(tray->visible()); | |
| 484 EXPECT_EQ(1.0f, tray->layer()->GetTargetOpacity()); | |
| 485 } | |
| 486 | |
| 487 #if defined(OS_CHROMEOS) | |
| 488 // Tests that touch on an item in the system bubble triggers it to become | |
| 489 // active. | |
| 490 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedback) { | |
| 491 SystemTray* tray = GetPrimarySystemTray(); | |
| 492 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 493 | |
| 494 TrayPopupItemContainer* view = static_cast<TrayPopupItemContainer*>( | |
| 495 tray->GetSystemBubble()->bubble_view()->child_at(0)); | |
| 496 EXPECT_FALSE(view->active()); | |
| 497 | |
| 498 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | |
| 499 generator.set_current_location(view->GetBoundsInScreen().CenterPoint()); | |
| 500 generator.PressTouch(); | |
| 501 EXPECT_TRUE(view->active()); | |
| 502 | |
| 503 generator.ReleaseTouch(); | |
| 504 EXPECT_FALSE(view->active()); | |
| 505 } | |
| 506 | |
| 507 // Tests that touch events on an item in the system bubble cause it to stop | |
| 508 // being active. | |
| 509 TEST_F(SystemTrayTest, TrayPopupItemContainerTouchFeedbackCancellation) { | |
| 510 SystemTray* tray = GetPrimarySystemTray(); | |
| 511 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 512 | |
| 513 TrayPopupItemContainer* view = static_cast<TrayPopupItemContainer*>( | |
| 514 tray->GetSystemBubble()->bubble_view()->child_at(0)); | |
| 515 EXPECT_FALSE(view->active()); | |
| 516 | |
| 517 gfx::Rect view_bounds = view->GetBoundsInScreen(); | |
| 518 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | |
| 519 generator.set_current_location(view_bounds.CenterPoint()); | |
| 520 generator.PressTouch(); | |
| 521 EXPECT_TRUE(view->active()); | |
| 522 | |
| 523 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y()); | |
| 524 generator.MoveTouch(move_point); | |
| 525 EXPECT_FALSE(view->active()); | |
| 526 | |
| 527 generator.set_current_location(move_point); | |
| 528 generator.ReleaseTouch(); | |
| 529 EXPECT_FALSE(view->active()); | |
| 530 } | |
| 531 | |
| 532 TEST_F(SystemTrayTest, SystemTrayHeightWithBubble) { | |
| 533 SystemTray* tray = GetPrimarySystemTray(); | |
| 534 WebNotificationTray* notification_tray = | |
| 535 StatusAreaWidgetTestHelper::GetStatusAreaWidget() | |
| 536 ->web_notification_tray(); | |
| 537 | |
| 538 // Ensure the initial tray bubble height is zero. | |
| 539 EXPECT_EQ(0, notification_tray->tray_bubble_height_for_test()); | |
| 540 | |
| 541 // Show the default view, ensure the tray bubble height is changed. | |
| 542 tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 543 RunAllPendingInMessageLoop(); | |
| 544 EXPECT_LT(0, notification_tray->tray_bubble_height_for_test()); | |
| 545 | |
| 546 // Hide the default view, ensure the tray bubble height is back to zero. | |
| 547 ASSERT_TRUE(tray->CloseSystemBubble()); | |
| 548 RunAllPendingInMessageLoop(); | |
| 549 | |
| 550 EXPECT_EQ(0, notification_tray->tray_bubble_height_for_test()); | |
| 551 } | |
| 552 #endif // OS_CHROMEOS | |
| 553 | |
| 554 } // namespace test | |
| 555 } // namespace ash | |
| OLD | NEW |