1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/rotation/rotation_lock_feature_pod_controller.h"
#include "ash/constants/quick_settings_catalogs.h"
#include "ash/shell.h"
#include "ash/system/unified/feature_tile.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/command_line.h"
#include "base/test/metrics/histogram_tester.h"
#include "ui/display/display_switches.h"
namespace ash {
class RotationLockFeaturePodControllerTest : public AshTestBase {
public:
RotationLockFeaturePodControllerTest() = default;
// AshTestBase:
void SetUp() override {
// The Display used for testing is not an internal display. This flag
// allows for DisplayManager to treat it as one.
base::CommandLine::ForCurrentProcess()->AppendSwitch(
::switches::kUseFirstDisplayAsInternal);
AshTestBase::SetUp();
}
void TearDown() override {
controller_.reset();
feature_tile_.reset();
AshTestBase::TearDown();
}
protected:
void SetUpController() {
controller_ = std::make_unique<RotationLockFeaturePodController>();
feature_tile_ = controller_->CreateTile();
}
std::unique_ptr<RotationLockFeaturePodController> controller_;
std::unique_ptr<FeatureTile> feature_tile_;
};
// Tests that when the tile is initially created it is not visible.
TEST_F(RotationLockFeaturePodControllerTest, CreateTile) {
SetUpController();
EXPECT_FALSE(feature_tile_->GetVisible());
}
// Tests that the button is created visible when tablet mode is enabled.
TEST_F(RotationLockFeaturePodControllerTest, CreateTileInTabletMode) {
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
SetUpController();
EXPECT_TRUE(feature_tile_->GetVisible());
}
// Tests that enabling tablet mode changes the tile visibility.
TEST_F(RotationLockFeaturePodControllerTest,
TileVisibilityChangesDuringTabletMode) {
SetUpController();
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
EXPECT_TRUE(feature_tile_->GetVisible());
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
// Set up the controller again, this simulates the bubble being closed when
// tablet mode changes.
SetUpController();
EXPECT_FALSE(feature_tile_->GetVisible());
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
SetUpController();
EXPECT_TRUE(feature_tile_->GetVisible());
}
TEST_F(RotationLockFeaturePodControllerTest, OnIconPressed) {
SetUpController();
TabletModeController* tablet_mode_controller =
Shell::Get()->tablet_mode_controller();
ScreenOrientationController* screen_orientation_controller =
Shell::Get()->screen_orientation_controller();
ASSERT_FALSE(screen_orientation_controller->rotation_locked());
tablet_mode_controller->SetEnabledForTest(true);
ASSERT_TRUE(feature_tile_->GetVisible());
ASSERT_TRUE(feature_tile_->IsToggled());
// Clicking the tile turns off auto-rotate and locks rotation.
controller_->OnIconPressed();
EXPECT_TRUE(screen_orientation_controller->rotation_locked());
EXPECT_TRUE(feature_tile_->GetVisible());
EXPECT_FALSE(feature_tile_->IsToggled());
// Clicking again turns on auto-rotate and unlocks rotation.
controller_->OnIconPressed();
EXPECT_FALSE(screen_orientation_controller->rotation_locked());
EXPECT_TRUE(feature_tile_->GetVisible());
EXPECT_TRUE(feature_tile_->IsToggled());
tablet_mode_controller->SetEnabledForTest(false);
}
TEST_F(RotationLockFeaturePodControllerTest, IconUMATracking) {
SetUpController();
// No metrics logged before clicking on any views.
auto histogram_tester = std::make_unique<base::HistogramTester>();
histogram_tester->ExpectTotalCount("Ash.QuickSettings.FeaturePod.ToggledOn",
/*expected_count=*/0);
histogram_tester->ExpectTotalCount("Ash.QuickSettings.FeaturePod.ToggledOff",
/*expected_count=*/0);
histogram_tester->ExpectTotalCount("Ash.QuickSettings.FeaturePod.DiveIn",
/*expected_count=*/0);
// Turn on rotation lock when pressing on the icon.
controller_->OnIconPressed();
histogram_tester->ExpectTotalCount("Ash.QuickSettings.FeaturePod.ToggledOn",
/*expected_count=*/1);
histogram_tester->ExpectTotalCount("Ash.QuickSettings.FeaturePod.ToggledOff",
/*expected_count=*/0);
histogram_tester->ExpectTotalCount("Ash.QuickSettings.FeaturePod.DiveIn",
/*expected_count=*/0);
histogram_tester->ExpectBucketCount("Ash.QuickSettings.FeaturePod.ToggledOn",
QsFeatureCatalogName::kRotationLock,
/*expected_count=*/1);
// Turn off rotation lock when pressing on the icon.
controller_->OnIconPressed();
histogram_tester->ExpectTotalCount("Ash.QuickSettings.FeaturePod.ToggledOn",
/*expected_count=*/1);
histogram_tester->ExpectTotalCount("Ash.QuickSettings.FeaturePod.ToggledOff",
/*expected_count=*/1);
histogram_tester->ExpectTotalCount("Ash.QuickSettings.FeaturePod.DiveIn",
/*expected_count=*/0);
histogram_tester->ExpectBucketCount("Ash.QuickSettings.FeaturePod.ToggledOff",
QsFeatureCatalogName::kRotationLock,
/*expected_count=*/1);
}
} // namespace ash
|