File: hotspot_allowed_flag_handler_unittest.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (81 lines) | stat: -rw-r--r-- 2,817 bytes parent folder | download | duplicates (8)
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
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromeos/ash/components/network/hotspot_allowed_flag_handler.h"

#include "ash/constants/ash_features.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/values.h"
#include "chromeos/ash/components/dbus/shill/shill_clients.h"
#include "chromeos/ash/components/dbus/shill/shill_manager_client.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/cros_system_api/dbus/shill/dbus-constants.h"

namespace ash {

class HotspotAllowedFlagHandlerTest : public ::testing::Test {
 public:
  void SetUp() override {
    shill_clients::InitializeFakes();

    hotspot_allowed_flag_handler_ =
        std::make_unique<HotspotAllowedFlagHandler>();
  }

  void TearDown() override {
    hotspot_allowed_flag_handler_.reset();

    shill_clients::Shutdown();
  }

  void OnGetManagerCallback(const std::string& property_name,
                            bool expected_value,
                            std::optional<base::Value::Dict> result) {
    if (!result) {
      ADD_FAILURE() << "Error getting Shill manager properties";
      return;
    }
    std::optional<bool> actual_value = result->FindBool(property_name);
    if (!actual_value) {
      ADD_FAILURE()
          << "Error getting TetheringAllowed in Shill manager properties";
      return;
    }
    EXPECT_EQ(expected_value, *actual_value);
  }

 protected:
  base::test::TaskEnvironment task_environment_{
      base::test::TaskEnvironment::TimeSource::MOCK_TIME};
  base::test::ScopedFeatureList feature_list_;
  std::unique_ptr<HotspotAllowedFlagHandler> hotspot_allowed_flag_handler_;
};

TEST_F(HotspotAllowedFlagHandlerTest, ExperimentalCarriersEnabled) {
  feature_list_.InitAndEnableFeature(
      features::kTetheringExperimentalFunctionality);
  hotspot_allowed_flag_handler_->Init();
  base::RunLoop().RunUntilIdle();
  ShillManagerClient::Get()->GetProperties(base::BindOnce(
      &HotspotAllowedFlagHandlerTest::OnGetManagerCallback,
      base::Unretained(this), shill::kExperimentalTetheringFunctionality,
      /*expected_value=*/true));
  base::RunLoop().RunUntilIdle();
}

TEST_F(HotspotAllowedFlagHandlerTest, ExperimentalCarriersDisabled) {
  feature_list_.InitAndDisableFeature(
      features::kTetheringExperimentalFunctionality);
  hotspot_allowed_flag_handler_->Init();
  base::RunLoop().RunUntilIdle();
  ShillManagerClient::Get()->GetProperties(base::BindOnce(
      &HotspotAllowedFlagHandlerTest::OnGetManagerCallback,
      base::Unretained(this), shill::kExperimentalTetheringFunctionality,
      /*expected_value=*/false));
  base::RunLoop().RunUntilIdle();
}

}  // namespace ash