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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
// 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/cellular/cellular_util.h"
#include "chrome/test/base/ash/interactive/cellular/esim_interactive_uitest_base.h"
#include "chrome/test/base/ash/interactive/settings/interactive_uitest_elements.h"
#include "chromeos/ash/components/network/managed_network_configuration_handler.h"
#include "chromeos/components/onc/onc_utils.h"
#include "chromeos/strings/grit/chromeos_strings.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/l10n/l10n_util.h"
namespace ash {
namespace {
class EsimPolicyInteractiveUiTest : public EsimInteractiveUiTestBase {
public:
std::optional<bool> NetworkIsConnected(const std::string& service_path) {
const NetworkState* network =
NetworkHandler::Get()->network_state_handler()->GetNetworkState(
service_path);
if (!network) {
return std::nullopt;
}
return network->IsConnectedState();
}
protected:
// InteractiveAshTest:
void SetUpOnMainThread() override {
EsimInteractiveUiTestBase::SetUpOnMainThread();
esim_info_ = std::make_unique<SimInfo>(/*id=*/0);
ConfigureEsimProfile(euicc_info(), *esim_info_, /*connected=*/true);
}
ui::test::internal::InteractiveTestPrivate::MultiStep
RestrictCellularFromPolicy(bool allow_only_managed_cellular,
bool set_existing_esim_as_managed) {
return Steps(Do([allow_only_managed_cellular, set_existing_esim_as_managed,
this]() {
base::Value::Dict global_config;
global_config.Set(
::onc::global_network_config::kAllowOnlyPolicyCellularNetworks,
allow_only_managed_cellular);
auto onc_configs = base::Value::List();
if (set_existing_esim_as_managed) {
onc_configs.Append(GenerateCellularPolicy(*esim_info_));
}
NetworkHandler::Get()->managed_network_configuration_handler()->SetPolicy(
::onc::ONC_SOURCE_DEVICE_POLICY, /*userhash=*/std::string(),
std::move(onc_configs), global_config);
}));
}
ui::test::internal::InteractiveTestPrivate::MultiStep
ClickEsimProfileInMobilePage(const ui::ElementIdentifier& element_id,
const std::string& esim_profile_name) {
return Steps(NavigateSettingsToNetworkSubpage(
element_id, ash::NetworkTypePattern::Mobile()),
ClickAnyElementTextContains(
element_id, settings::cellular::CellularNetworksList(),
WebContentsInteractionTestUtil::DeepQuery({
"network-list",
"network-list-item",
"div#divText",
}),
esim_profile_name));
}
const SimInfo& esim_info() const { return *esim_info_; }
private:
std::unique_ptr<SimInfo> esim_info_;
};
IN_PROC_BROWSER_TEST_F(EsimPolicyInteractiveUiTest,
EsimPolicyRestrictUnmanagedNetworkConnection) {
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(kOSSettingsId);
DEFINE_LOCAL_STATE_IDENTIFIER_VALUE(
ui::test::PollingStateObserver<std::optional<bool>>,
kNetworkConnectedState);
WebContentsInteractionTestUtil::DeepQuery cellular_network_list_item_label(
{"network-list", "network-list-item", "div#divText"});
ui::ElementContext context =
LaunchSystemWebApp(SystemWebAppType::SETTINGS, kOSSettingsId);
// Run the following steps with the OS Settings context set as the default.
RunTestSequenceInContext(
context,
NavigateSettingsToNetworkSubpage(kOSSettingsId,
ash::NetworkTypePattern::Mobile()),
PollState(kNetworkConnectedState,
base::BindRepeating(
&EsimPolicyInteractiveUiTest::NetworkIsConnected,
base::Unretained(this), esim_info().service_path())),
WaitForState(kNetworkConnectedState, true),
Log("Check for add eSIM icon is enabled"),
WaitForElementEnabled(kOSSettingsId, settings::cellular::AddEsimButton()),
Log("Apply policy to restrict unmanaged cellular network connection"),
RestrictCellularFromPolicy(/*allow_only_managed_cellular=*/true,
/*set_existing_esim_as_managed=*/false),
Log("Check for add eSIM icon disabled"),
WaitForElementDisabled(kOSSettingsId,
settings::cellular::AddEsimButton()),
Log("Check for unmanaged cellular network should be disconnected by "
"policy"),
WaitForState(kNetworkConnectedState, false),
Log("Click on the network item should go to its detail page"),
ClickAnyElementTextContains(
kOSSettingsId, settings::cellular::CellularNetworksList(),
cellular_network_list_item_label, esim_info().nickname()),
WaitForElementTextContains(kOSSettingsId,
settings::InternetSettingsSubpageTitle(),
/*text=*/esim_info().nickname()),
Log("Check the connect button is disabled"),
WaitForElementDisabled(
kOSSettingsId, settings::SettingsSubpageConnectDisconnectButton()),
Log("Check for more action button should be enabled on unmanaged "
"network"),
WaitForElementEnabled(kOSSettingsId,
settings::NetworkMoreDetailsMenuButton()),
Log("Apply policy to set the existing cellular network as managed one"),
RestrictCellularFromPolicy(/*allow_only_managed_cellular=*/true,
/*set_existing_esim_as_managed=*/true),
Log("Click on managed network should trigger connection"),
ClickEsimProfileInMobilePage(kOSSettingsId, esim_info().nickname()),
WaitForAnyElementTextContains(
kOSSettingsId, settings::cellular::CellularNetworksList(),
WebContentsInteractionTestUtil::DeepQuery(
{"network-list", "network-list-item", "div#sublabel"}),
l10n_util::GetStringUTF8(IDS_ONC_CONNECTED).c_str()),
WaitForState(kNetworkConnectedState, true),
Log("Check for policy icon"),
WaitForElementExists(
kOSSettingsId,
settings::cellular::CellularNetworkListItemPolicyIcon()),
Log("Go to the network detailed page"),
ClickAnyElementTextContains(
kOSSettingsId, settings::cellular::CellularNetworksList(),
cellular_network_list_item_label, esim_info().nickname()),
Log("Check for policy icon"),
WaitForElementExists(kOSSettingsId,
settings::SettingsSubpagePolicyIcon()),
Log("Check for more action button should be disabled on managed network"),
WaitForElementDisabled(kOSSettingsId,
settings::NetworkMoreDetailsMenuButton()),
Log("Test complete"));
}
} // namespace
} // namespace ash
|