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