[go: nahoru, domu]

blob: 2228521e3e9fa395da6ed0f82d113774642724e8 [file] [log] [blame]
Hirthanan Subenderanc1f1015d2023-12-13 17:06:311// Copyright 2023 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/ash/report_controller_initializer.h"
6
7#include "base/memory/ptr_util.h"
8#include "chrome/browser/ash/settings/device_settings_service.h"
9#include "testing/gtest/include/gtest/gtest.h"
10
11namespace ash {
12
13class ReportControllerInitializerValidateSegment
14 : public testing::TestWithParam<std::tuple<policy::DeviceMode,
15 policy::MarketSegment,
16 report::MarketSegment>> {
17 public:
18 void SetUp() override {
19 // Initialize CrOS device settings for ReportControllerInitializer.
20 DeviceSettingsService::Initialize();
21
22 // Create ReportControllerInitializer for unit testing.
23 report_controller_initializer_ =
24 std::make_unique<ReportControllerInitializer>();
25 }
26
27 void TearDown() override {
28 // Destruct ReportControllerInitializer before cleaning up dependencies.
29 report_controller_initializer_.reset();
30
31 // Clean up CrOS device settings after testing.
32 DeviceSettingsService::Shutdown();
33 }
34
35 ReportControllerInitializer* GetReportControllerInitializer() {
36 return report_controller_initializer_.get();
37 }
38
39 protected:
40 report::MarketSegment GetMarketSegmentForTesting(
41 const policy::DeviceMode& device_mode,
42 const policy::MarketSegment& device_market_segment) {
43 return report_controller_initializer_->GetMarketSegmentForTesting(
44 device_mode, device_market_segment);
45 }
46
47 private:
48 std::unique_ptr<ReportControllerInitializer> report_controller_initializer_;
49};
50
51TEST_P(ReportControllerInitializerValidateSegment, ValidateSegment) {
52 auto [device_mode, device_market_segment, expected_segment] = GetParam();
53 ASSERT_EQ(expected_segment,
54 GetMarketSegmentForTesting(device_mode, device_market_segment));
55}
56
57INSTANTIATE_TEST_SUITE_P(
58 ReportControllerInitializerValidateSegmentTests,
59 ReportControllerInitializerValidateSegment,
60 testing::Values(
61 // Unknown DeviceMode
62 std::make_tuple(policy::DeviceMode::DEVICE_MODE_PENDING,
63 policy::MarketSegment::UNKNOWN,
64 report::MARKET_SEGMENT_UNKNOWN),
65 // Consumer DeviceMode
66 std::make_tuple(policy::DeviceMode::DEVICE_MODE_CONSUMER,
67 policy::MarketSegment::UNKNOWN,
68 report::MARKET_SEGMENT_CONSUMER),
69 // Demo Enterprise DeviceMode
70 std::make_tuple(policy::DeviceMode::DEVICE_MODE_DEMO,
71 policy::MarketSegment::ENTERPRISE,
72 report::MARKET_SEGMENT_ENTERPRISE_DEMO),
73 // Enterprise DeviceMode Enterprise Segment
74 std::make_tuple(policy::DeviceMode::DEVICE_MODE_ENTERPRISE,
75 policy::MarketSegment::ENTERPRISE,
76 report::MARKET_SEGMENT_ENTERPRISE),
77 // Enterprise DeviceMode Education Segment
78 std::make_tuple(policy::DeviceMode::DEVICE_MODE_ENTERPRISE,
79 policy::MarketSegment::EDUCATION,
80 report::MARKET_SEGMENT_EDUCATION),
81 // Enterprise DeviceMode Unknown Segment
82 std::make_tuple(policy::DeviceMode::DEVICE_MODE_ENTERPRISE,
83 policy::MarketSegment::UNKNOWN,
84 report::MARKET_SEGMENT_ENTERPRISE_ENROLLED_BUT_UNKNOWN),
85 // Unknown DeviceMode And Segment
86 std::make_tuple(policy::DeviceMode::DEVICE_MODE_NOT_SET,
87 policy::MarketSegment::UNKNOWN,
88 report::MARKET_SEGMENT_UNKNOWN)));
89
90} // namespace ash