| // Copyright 2018 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "ash/system/unified/unified_system_tray.h" |
| |
| #include "ash/system/status_area_widget.h" |
| #include "ash/system/status_area_widget_test_helper.h" |
| #include "ash/system/unified/unified_slider_bubble_controller.h" |
| #include "ash/system/unified/unified_system_tray_bubble.h" |
| #include "ash/test/ash_test_base.h" |
| #include "ui/display/display.h" |
| #include "ui/display/screen.h" |
| |
| namespace ash { |
| |
| class UnifiedSystemTrayTest : public AshTestBase { |
| public: |
| UnifiedSystemTrayTest() = default; |
| ~UnifiedSystemTrayTest() override = default; |
| |
| protected: |
| bool IsSliderBubbleShown() { |
| return GetPrimaryUnifiedSystemTray() |
| ->slider_bubble_controller_->bubble_widget_; |
| } |
| |
| UnifiedSliderBubbleController::SliderType GetSliderBubbleType() { |
| return GetPrimaryUnifiedSystemTray() |
| ->slider_bubble_controller_->slider_type_; |
| } |
| |
| UnifiedSystemTrayBubble* GetUnifiedSystemTrayBubble() { |
| return GetPrimaryUnifiedSystemTray()->bubble_.get(); |
| } |
| |
| private: |
| DISALLOW_COPY_AND_ASSIGN(UnifiedSystemTrayTest); |
| }; |
| |
| TEST_F(UnifiedSystemTrayTest, ShowVolumeSliderBubble) { |
| // The volume popup is not visible initially. |
| EXPECT_FALSE(IsSliderBubbleShown()); |
| |
| // When set to autohide, the shelf shouldn't be shown. |
| StatusAreaWidget* status = StatusAreaWidgetTestHelper::GetStatusAreaWidget(); |
| EXPECT_FALSE(status->ShouldShowShelf()); |
| |
| // Simulate ARC asking to show the volume view. |
| GetPrimaryUnifiedSystemTray()->ShowVolumeSliderBubble(); |
| |
| // Volume view is now visible. |
| EXPECT_TRUE(IsSliderBubbleShown()); |
| EXPECT_EQ(UnifiedSliderBubbleController::SLIDER_TYPE_VOLUME, |
| GetSliderBubbleType()); |
| |
| // This does not force the shelf to automatically show. Regression tests for |
| // crbug.com/729188 |
| EXPECT_FALSE(status->ShouldShowShelf()); |
| } |
| |
| TEST_F(UnifiedSystemTrayTest, ShowBubble_MultipleDisplays_OpenedOnSameDisplay) { |
| // Initialize two displays with 800x800 resolution. |
| UpdateDisplay("400+400-800x600,1220+400-800x600"); |
| auto* screen = display::Screen::GetScreen(); |
| EXPECT_EQ(2, screen->GetNumDisplays()); |
| |
| // The tray bubble for each display should be opened on the same display. |
| // See crbug.com/937420. |
| for (int i = 0; i < screen->GetNumDisplays(); ++i) { |
| auto* system_tray = GetPrimaryUnifiedSystemTray(); |
| system_tray->ShowBubble(true /* show_by_click */); |
| const gfx::Rect primary_display_bounds = GetPrimaryDisplay().bounds(); |
| const gfx::Rect tray_bubble_bounds = |
| GetPrimaryUnifiedSystemTray()->GetBubbleBoundsInScreen(); |
| EXPECT_TRUE(primary_display_bounds.Contains(tray_bubble_bounds)) |
| << "primary display bounds=" << primary_display_bounds.ToString() |
| << ", tray bubble bounds=" << tray_bubble_bounds.ToString(); |
| |
| SwapPrimaryDisplay(); |
| } |
| } |
| |
| } // namespace ash |