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

ash / system / focus_mode / focus_mode_util_unittest.cc [blame]

// 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 "ash/system/focus_mode/focus_mode_util.h"

#include "testing/gtest/include/gtest/gtest.h"

namespace ash::focus_mode_util {

// Verify that missing `id` or invalid playlist type results in an empty
// string.
TEST(FocusModeUtilTests, VerifyInvalidSourceTitle) {
  SelectedPlaylist selected_playlist;
  EXPECT_TRUE(GetSourceTitleForMediaControls(selected_playlist).empty());
  selected_playlist.id = "id0";
  EXPECT_TRUE(GetSourceTitleForMediaControls(selected_playlist).empty());
}

// Verify the YTM source string.
TEST(FocusModeUtilTests, VerifyYTMSourceTitle) {
  SelectedPlaylist selected_playlist;
  selected_playlist.id = "id0";
  selected_playlist.type = SoundType::kYouTubeMusic;
  EXPECT_EQ(GetSourceTitleForMediaControls(selected_playlist),
            "music.youtube.com");
}

// Verify the Soundscape source string.
TEST(FocusModeUtilTests, VerifySoundscapeSourceTitle) {
  SelectedPlaylist selected_playlist;
  selected_playlist.id = "id0";
  selected_playlist.type = SoundType::kSoundscape;
  EXPECT_EQ(GetSourceTitleForMediaControls(selected_playlist), "Focus sounds");
}

// Verify we get the correct `GetNextProgressStep` based on the current
// progress.
TEST(FocusModeUtilTests, VerifyGetNextProgressStep) {
  // Verify that when it starts, it just expecting the first step.
  EXPECT_EQ(GetNextProgressStep(0.0), 1);

  // Verify values slightly below, exactly at, and slightly above a threshold.
  EXPECT_EQ(GetNextProgressStep(0.499999), 60);
  EXPECT_EQ(GetNextProgressStep(0.5), 61);
  EXPECT_EQ(GetNextProgressStep(0.5000001), 61);

  // Test a progress value very close to max, which would expect the last step.
  EXPECT_EQ(GetNextProgressStep(0.999), 120);

  // Test that we clamp the step value to the last step.
  EXPECT_EQ(GetNextProgressStep(1.0), 120);
}

}  // namespace ash::focus_mode_util