File: focus_mode_policy_browsertest.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 (113 lines) | stat: -rw-r--r-- 4,177 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
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
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <string_view>

#include "ash/constants/ash_features.h"
#include "ash/public/cpp/ash_view_ids.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/system/focus_mode/focus_mode_controller.h"
#include "ash/system/focus_mode/focus_mode_detailed_view.h"
#include "ash/system/focus_mode/sounds/focus_mode_sounds_view.h"
#include "ash/system/unified/quick_settings_view.h"
#include "ash/system/unified/unified_system_tray.h"
#include "ash/system/unified/unified_system_tray_bubble.h"
#include "base/run_loop.h"
#include "chrome/browser/policy/policy_test_utils.h"
#include "components/policy/policy_constants.h"
#include "content/public/test/browser_test.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/button_controller.h"

namespace ash {
namespace {

class FocusModePolicyTest : public policy::PolicyTest {
 public:
  FocusModePolicyTest() = default;
  ~FocusModePolicyTest() override = default;

 protected:
  void SetUpOnMainThread() override {
    policy::PolicyTest::SetUpOnMainThread();
    FocusModeController::Get()
        ->focus_mode_sounds_controller()
        ->SetIsMinorUserForTesting(false);
  }

  void SetPolicyValue(std::string_view value) {
    policy::PolicyMap policies;
    SetPolicy(&policies, policy::key::kFocusModeSoundsEnabled,
              base::Value(value));
    provider_.UpdateChromePolicy(policies);
  }

  FocusModeSoundsView* GetSoundsView(QuickSettingsView* quick_settings) {
    views::View* detailed_view = quick_settings->detailed_view_container();
    return reinterpret_cast<FocusModeSoundsView*>(
        detailed_view->GetViewByID(FocusModeDetailedView::ViewId::kSoundView));
  }

  void ClickOnFocusTile(views::View* panel) {
    views::Button* tile = static_cast<views::Button*>(
        panel->GetViewByID(VIEW_ID_FEATURE_TILE_FOCUS_MODE));
    tile->button_controller()->NotifyClick();
    base::RunLoop().RunUntilIdle();
  }

  QuickSettingsView* OpenQuickSettings() {
    UnifiedSystemTray* system_tray = GetPrimaryUnifiedSystemTray();
    system_tray->ShowBubble();
    return system_tray->bubble()->quick_settings_view();
  }

 private:
  Shelf* GetPrimaryShelf() {
    return Shell::GetPrimaryRootWindowController()->shelf();
  }

  UnifiedSystemTray* GetPrimaryUnifiedSystemTray() {
    return GetPrimaryShelf()->GetStatusAreaWidget()->unified_system_tray();
  }
};

IN_PROC_BROWSER_TEST_F(FocusModePolicyTest, FocusModeSounds_Enabled) {
  SetPolicyValue("enabled");
  auto* quick_settings = OpenQuickSettings();
  ClickOnFocusTile(quick_settings);
  FocusModeSoundsView* sounds_view = GetSoundsView(quick_settings);
  EXPECT_THAT(sounds_view->GetVisible(), testing::Eq(true));
  EXPECT_THAT(sounds_view->soundscape_views(),
              testing::Pair(testing::NotNull(), testing::NotNull()));
  EXPECT_THAT(sounds_view->youtube_music_views(),
              testing::Pair(testing::NotNull(), testing::NotNull()));
}

IN_PROC_BROWSER_TEST_F(FocusModePolicyTest, FocusModeSounds_FocusSoundsOnly) {
  SetPolicyValue("focus-sounds");
  auto* quick_settings = OpenQuickSettings();
  ClickOnFocusTile(quick_settings);
  FocusModeSoundsView* sounds_view = GetSoundsView(quick_settings);
  EXPECT_THAT(sounds_view->GetVisible(), testing::Eq(true));
  // For this case, we will show a label for the soundscape playlists instead of
  // a `TabSliderButton`.
  EXPECT_THAT(sounds_view->soundscape_views(),
              testing::Pair(testing::IsNull(), testing::NotNull()));
  EXPECT_THAT(sounds_view->youtube_music_views(),
              testing::Pair(testing::IsNull(), testing::IsNull()));
}

IN_PROC_BROWSER_TEST_F(FocusModePolicyTest, FocusModeSounds_Disabled) {
  SetPolicyValue("disabled");
  auto* quick_settings = OpenQuickSettings();
  ClickOnFocusTile(quick_settings);
  EXPECT_THAT(GetSoundsView(quick_settings)->GetVisible(), testing::Eq(false));
}

}  // namespace
}  // namespace ash