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

ash / public / cpp / holding_space / holding_space_section_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/holding_space/holding_space_section.h"

#include <set>

#include "ash/public/cpp/holding_space/holding_space_item.h"
#include "ash/public/cpp/holding_space/holding_space_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace ash {
namespace {

// Helpers ---------------------------------------------------------------------

std::set<HoldingSpaceSectionId> GetHoldingSpaceSectionIds() {
  std::set<HoldingSpaceSectionId> section_ids;
  for (size_t i = static_cast<size_t>(HoldingSpaceSectionId::kMinValue);
       i <= static_cast<size_t>(HoldingSpaceSectionId::kMaxValue); ++i) {
    section_ids.emplace(static_cast<HoldingSpaceSectionId>(i));
  }
  return section_ids;
}

void ExpectSection(const HoldingSpaceSection* section,
                   HoldingSpaceSectionId expected_id) {
  switch (expected_id) {
    case HoldingSpaceSectionId::kDownloads:
      EXPECT_EQ(section->id, HoldingSpaceSectionId::kDownloads);
      EXPECT_THAT(section->supported_types,
                  testing::UnorderedElementsAre(
                      HoldingSpaceItem::Type::kArcDownload,
                      HoldingSpaceItem::Type::kDiagnosticsLog,
                      HoldingSpaceItem::Type::kDownload,
                      HoldingSpaceItem::Type::kNearbyShare,
                      HoldingSpaceItem::Type::kPhoneHubCameraRoll,
                      HoldingSpaceItem::Type::kPhotoshopWeb,
                      HoldingSpaceItem::Type::kPrintedPdf,
                      HoldingSpaceItem::Type::kScan));
      EXPECT_EQ(section->max_visible_item_count, 4u);
      break;
    case HoldingSpaceSectionId::kPinnedFiles:
      EXPECT_EQ(section->id, HoldingSpaceSectionId::kPinnedFiles);
      EXPECT_THAT(
          section->supported_types,
          testing::UnorderedElementsAre(HoldingSpaceItem::Type::kPinnedFile));
      EXPECT_EQ(section->max_visible_item_count, std::nullopt);
      break;
    case HoldingSpaceSectionId::kScreenCaptures:
      EXPECT_EQ(section->id, HoldingSpaceSectionId::kScreenCaptures);
      EXPECT_THAT(section->supported_types,
                  testing::UnorderedElementsAre(
                      HoldingSpaceItem::Type::kScreenRecording,
                      HoldingSpaceItem::Type::kScreenRecordingGif,
                      HoldingSpaceItem::Type::kScreenshot));
      EXPECT_EQ(section->max_visible_item_count, 3u);
      break;
    case HoldingSpaceSectionId::kSuggestions:
      EXPECT_EQ(section->id, HoldingSpaceSectionId::kSuggestions);
      EXPECT_THAT(section->supported_types,
                  testing::UnorderedElementsAre(
                      HoldingSpaceItem::Type::kLocalSuggestion,
                      HoldingSpaceItem::Type::kDriveSuggestion));
      EXPECT_EQ(section->max_visible_item_count, 4u);
      break;
  }
}

}  // namespace

// Tests -----------------------------------------------------------------------

using HoldingSpaceSectionTest = testing::Test;

// Verifies that every `HoldingSpaceSectionId` maps to an expected section.
TEST_F(HoldingSpaceSectionTest, GetHoldingSpaceSectionById) {
  for (const auto& id : GetHoldingSpaceSectionIds()) {
    SCOPED_TRACE(testing::Message() << "ID: " << static_cast<size_t>(id));
    ExpectSection(GetHoldingSpaceSection(id), id);
  }
}

// Verifies that every `HoldingSpaceItem::Type` maps to an expected section.
TEST_F(HoldingSpaceSectionTest, GetHoldingSpaceSectionByType) {
  for (const auto type : holding_space_util::GetAllItemTypes()) {
    SCOPED_TRACE(testing::Message() << "Type: " << static_cast<size_t>(type));
    std::optional<HoldingSpaceSectionId> id;
    switch (type) {
      case HoldingSpaceItem::Type::kArcDownload:
      case HoldingSpaceItem::Type::kDiagnosticsLog:
      case HoldingSpaceItem::Type::kDownload:
      case HoldingSpaceItem::Type::kNearbyShare:
      case HoldingSpaceItem::Type::kPhoneHubCameraRoll:
      case HoldingSpaceItem::Type::kPhotoshopWeb:
      case HoldingSpaceItem::Type::kPrintedPdf:
      case HoldingSpaceItem::Type::kScan:
        id = HoldingSpaceSectionId::kDownloads;
        break;
      case HoldingSpaceItem::Type::kDriveSuggestion:
      case HoldingSpaceItem::Type::kLocalSuggestion:
        id = HoldingSpaceSectionId::kSuggestions;
        break;
      case HoldingSpaceItem::Type::kPinnedFile:
        id = HoldingSpaceSectionId::kPinnedFiles;
        break;
      case HoldingSpaceItem::Type::kScreenRecording:
      case HoldingSpaceItem::Type::kScreenRecordingGif:
      case HoldingSpaceItem::Type::kScreenshot:
        id = HoldingSpaceSectionId::kScreenCaptures;
        break;
    }
    ExpectSection(GetHoldingSpaceSection(type), id.value());
  }
}

}  // namespace ash