File: hotspot_policy_interactive_uitest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (161 lines) | stat: -rw-r--r-- 5,684 bytes parent folder | download | duplicates (6)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// 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 <string>

#include "chrome/test/base/ash/interactive/hotspot/hotspot_state_observer.h"
#include "chrome/test/base/ash/interactive/interactive_ash_test.h"
#include "chrome/test/base/ash/interactive/network/shill_service_util.h"
#include "chrome/test/base/ash/interactive/settings/interactive_uitest_elements.h"
#include "chromeos/ash/components/dbus/shill/shill_manager_client.h"
#include "chromeos/ash/components/dbus/shill/shill_service_client.h"
#include "chromeos/ash/components/network/managed_network_configuration_handler.h"
#include "chromeos/ash/components/network/network_handler.h"
#include "third_party/cros_system_api/dbus/shill/dbus-constants.h"
#include "ui/base/interaction/element_identifier.h"

namespace ash {
namespace {

DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(kOSSettingsId);

DEFINE_LOCAL_STATE_IDENTIFIER_VALUE(HotspotStateObserver, kHotspotStateService);

class HotspotPolicyInteractiveUITest : public InteractiveAshTest {
 protected:
  // InteractiveAshTest:
  void SetUpOnMainThread() override {
    InteractiveAshTest::SetUpOnMainThread();

    // Set up context for element tracking for InteractiveBrowserTest.
    SetupContextWidget();

    // Ensure the OS Settings app is installed.
    InstallSystemApps();

    ShillManagerClient::Get()
        ->GetTestInterface()
        ->SetSimulateCheckTetheringReadinessResult(
            FakeShillSimulatedResult::kSuccess,
            shill::kTetheringReadinessReady);

    ShillServiceClient::Get()->GetTestInterface()->AddService(
        shill_service_info_.service_path(), shill_service_info_.service_guid(),
        shill_service_info_.service_name(), shill::kTypeCellular,
        shill::kStateOnline, /*visible=*/true);
  }

  void RestrictHotspotFromPolicy() {
    base::Value::Dict global_config;
    global_config.Set(::onc::global_network_config::kAllowCellularHotspot,
                      false);
    NetworkHandler::Get()->managed_network_configuration_handler()->SetPolicy(
        ::onc::ONC_SOURCE_DEVICE_POLICY, std::string(), base::Value::List(),
        global_config);
  }

 private:
  const ShillServiceInfo shill_service_info_ =
      ShillServiceInfo(/*id=*/0, shill::kTypeCellular);
};

IN_PROC_BROWSER_TEST_F(HotspotPolicyInteractiveUITest,
                       ApplyPolicyWithHotspotOff) {
  ui::ElementContext context =
      LaunchSystemWebApp(SystemWebAppType::SETTINGS, kOSSettingsId);

  // Run the following steps with the OS Settings context set as the default.
  RunTestSequenceInContext(
      context,

      Log("Navigating to the internet page"),

      NavigateSettingsToInternetPage(kOSSettingsId),

      Log("Waiting for hotspot summary item to exist"),

      WaitForElementExists(kOSSettingsId,
                           settings::hotspot::HotspotSummaryItem()),

      Log("Enforce the policy to restrict users from enabling hotspot"),

      Do([&]() { RestrictHotspotFromPolicy(); }),

      Log("Wait for hotspot toggle to be disabled"),

      WaitForElementDisabled(kOSSettingsId, settings::hotspot::HotspotToggle()),

      Log("Wait for the policy icon to be shown"),

      WaitForElementExists(kOSSettingsId,
                           settings::hotspot::HotspotPolicyIcon()),

      Log("Test complete"));
}

IN_PROC_BROWSER_TEST_F(HotspotPolicyInteractiveUITest,
                       ApplyPolicyWithHotspotOn) {
  ui::ElementContext context =
      LaunchSystemWebApp(SystemWebAppType::SETTINGS, kOSSettingsId);

  ShillManagerClient::Get()
      ->GetTestInterface()
      ->SetSimulateTetheringEnableResult(FakeShillSimulatedResult::kSuccess,
                                         shill::kTetheringEnableResultSuccess);

  // Run the following steps with the OS Settings context set as the default.
  RunTestSequenceInContext(
      context,

      Log("Navigating to the internet page"),

      NavigateSettingsToInternetPage(kOSSettingsId),

      Log("Waiting for hotspot summary item to exist"),

      WaitForElementExists(kOSSettingsId,
                           settings::hotspot::HotspotSummaryItem()),

      WaitForElementEnabled(kOSSettingsId, settings::hotspot::HotspotToggle()),

      Log("Make sure hotspot is initially disabled"),

      ObserveState(kHotspotStateService,
                   std::make_unique<HotspotStateObserver>()),
      WaitForState(kHotspotStateService,
                   hotspot_config::mojom::HotspotState::kDisabled),
      WaitForToggleState(kOSSettingsId, settings::hotspot::HotspotToggle(),
                         false),

      Log("Waiting for hotspot toggle to be enabled then click it"),

      ClickElement(kOSSettingsId, settings::hotspot::HotspotToggle()),

      Log("Wait for the hotspot state to be enabled"),

      WaitForState(kHotspotStateService,
                   hotspot_config::mojom::HotspotState::kEnabled),
      WaitForToggleState(kOSSettingsId, settings::hotspot::HotspotToggle(),
                         true),

      Log("Enforce the policy to restrict users from enabling hotspot"),

      Do([&]() { RestrictHotspotFromPolicy(); }),

      Log("Wait for hotspot toggle to be turned off"),

      WaitForElementDisabled(kOSSettingsId, settings::hotspot::HotspotToggle()),
      WaitForToggleState(kOSSettingsId, settings::hotspot::HotspotToggle(),
                         false),

      Log("Wait for the policy icon to be shown"),

      WaitForElementExists(kOSSettingsId,
                           settings::hotspot::HotspotPolicyIcon()),

      Log("Test complete"));
}

}  // namespace
}  // namespace ash