File: quick_settings_footer_pixeltest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (83 lines) | stat: -rw-r--r-- 2,731 bytes parent folder | download | duplicates (5)
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
// Copyright 2023 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/constants/ash_features.h"
#include "ash/system/unified/quick_settings_footer.h"
#include "ash/system/unified/unified_system_tray.h"
#include "ash/system/unified/unified_system_tray_bubble.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/pixel/ash_pixel_differ.h"
#include "ash/test/pixel/ash_pixel_test_init_params.h"
#include "base/test/scoped_feature_list.h"
#include "components/user_manager/user_type.h"

namespace ash {

// Pixel tests for the quick settings footer.
class QuickSettingsFooterPixelTest : public AshTestBase {
 public:
  QuickSettingsFooterPixelTest() {
    feature_list_.InitAndDisableFeature(features::kAdaptiveCharging);
  }

  // AshTestBase:
  std::optional<pixel_test::InitParams> CreatePixelTestInitParams()
      const override {
    return pixel_test::InitParams();
  }

  void SetUp() override {
    chromeos::PowerManagerClient::InitializeFake();
    AshTestBase::SetUp();
  }

  void TearDown() override {
    AshTestBase::TearDown();
    chromeos::PowerManagerClient::Shutdown();
  }

  void InitPowerStatusAndOpenBubble() {
    power_manager::PowerSupplyProperties prop;
    prop.set_external_power(power_manager::PowerSupplyProperties::AC);
    prop.set_battery_state(power_manager::PowerSupplyProperties::CHARGING);
    prop.set_battery_time_to_full_sec(6000);
    prop.set_battery_percent(30.0);
    PowerStatus::Get()->SetProtoForTesting(prop);

    UnifiedSystemTray* system_tray = GetPrimaryUnifiedSystemTray();
    system_tray->ShowBubble();
    footer_ =
        system_tray->bubble()->quick_settings_view()->footer_for_testing();
  }

  void CloseBubble() { GetPrimaryUnifiedSystemTray()->CloseBubble(); }

 protected:
  QuickSettingsFooter* GetFooter() { return footer_; }

 private:
  base::test::ScopedFeatureList feature_list_;

  // Owned by view hierarchy.
  raw_ptr<QuickSettingsFooter, DanglingUntriaged> footer_ = nullptr;
};

TEST_F(QuickSettingsFooterPixelTest, FooterShouldBeRenderedCorrectly) {
  InitPowerStatusAndOpenBubble();
  EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
      "with_no_extra_button",
      /*revision_number=*/8, GetFooter()));
  CloseBubble();

  // Regression test for b/293484037: The settings button is missing when
  // there's no enough space for the battery label.
  SimulateUserLogin({"test@gmail.com", user_manager::UserType::kPublicAccount});
  InitPowerStatusAndOpenBubble();
  EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
      "with_exit_button",
      /*revision_number=*/8, GetFooter()));
  CloseBubble();
}

}  // namespace ash