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

ash / public / cpp / system / toast_data_unittest.cc [blame]

// Copyright 2022 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/public/cpp/system/toast_data.h"

#include <string>
#include <utility>

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

namespace ash {

TEST(ToastDataTest, InitializedWithProvidedValues) {
  ToastData data = ToastData(
      /*id=*/"some_id", ToastCatalogName::kDebugCommand, /*text=*/u"some_text",
      base::Seconds(1),
      /*visible_on_lock_screen=*/true);
  data.button_type = ToastData::ButtonType::kTextButton;
  data.button_text = u"Dismiss now";

  EXPECT_EQ(data.id, "some_id");
  EXPECT_EQ(data.catalog_name, ash::ToastCatalogName::kDebugCommand);
  EXPECT_EQ(data.text, u"some_text");
  EXPECT_EQ(data.duration, base::Seconds(1));
  EXPECT_EQ(data.visible_on_lock_screen, true);
  EXPECT_EQ(data.button_text, u"Dismiss now");
}

TEST(ToastDataTest, InitializedWithDefaultValues) {
  ToastData data = ToastData(
      /*id=*/"some_id", ToastCatalogName::kDebugCommand, /*text=*/u"some_text");

  EXPECT_EQ(data.duration, ToastData::kDefaultToastDuration);
  EXPECT_EQ(data.visible_on_lock_screen, false);
  EXPECT_EQ(data.button_text, std::u16string());
}

TEST(ToastDataTest, InitializedWithInfiniteDuration) {
  ToastData data = ToastData(
      /*id=*/"some_id", ToastCatalogName::kDebugCommand, /*text=*/u"some_text",
      ToastData::kInfiniteDuration);

  EXPECT_EQ(data.duration, ToastData::kInfiniteDuration);
}

TEST(ToastDataTest, EnforcesMinimumDuration) {
  ToastData data = ToastData(
      /*id=*/"some_id", ToastCatalogName::kDebugCommand, /*text=*/u"some_text",
      base::Milliseconds(1));

  EXPECT_EQ(data.duration, ToastData::kMinimumDuration);
}

}  // namespace ash