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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931
|
// 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 "ash/constants/ash_features.h"
#include "base/strings/stringprintf.h"
#include "base/strings/to_string.h"
#include "base/test/scoped_feature_list.h"
#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/cellular/wait_for_service_connected_observer.h"
#include "chrome/test/base/ash/interactive/settings/interactive_uitest_elements.h"
#include "chromeos/ash/components/dbus/hermes/fake_hermes_euicc_client.h"
#include "chromeos/ash/components/dbus/shill/fake_shill_service_client.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 "dbus/object_path.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/l10n/l10n_util.h"
namespace ash {
namespace {
const char kDefaultCustomApnName[] = "custom_default_only_apn";
const char kAttachCustomApnName[] = "custom_attach_only_apn";
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(kOSSettingsId);
class ApnUiInteractiveUiTest : public EsimInteractiveUiTestBase {
protected:
ApnUiInteractiveUiTest() {
scoped_feature_list_.InitAndEnableFeature(
ash::features::kAllowApnModificationPolicy);
}
// InteractiveAshTest:
void SetUpOnMainThread() override {
EsimInteractiveUiTestBase::SetUpOnMainThread();
esim_info_ = std::make_unique<SimInfo>(/*id=*/0);
ConfigureEsimProfile(euicc_info(), *esim_info_, /*connected=*/true);
default_modb_apn_name_ = *ShillServiceClient::Get()
->GetTestInterface()
->GetFakeDefaultModbApnDict()
.FindString(shill::kApnNameProperty);
}
const SimInfo& esim_info() const { return *esim_info_; }
const std::string& default_modb_apn_name() const {
return default_modb_apn_name_;
}
void VerifyNoCustomApnsInShill() {
const base::Value::Dict* cellular_properties =
ShillServiceClient::Get()->GetTestInterface()->GetServiceProperties(
esim_info().service_path());
ASSERT_TRUE(cellular_properties);
const base::Value::List* shill_custom_apns =
cellular_properties->FindList(shill::kCellularCustomApnListProperty);
if (shill_custom_apns) {
EXPECT_EQ(0u, shill_custom_apns->size());
}
}
void VerifyCustomApnInShill(bool expect_exists,
const std::string& expected_apn_name,
const std::string& expected_apn_type) {
const base::Value::Dict* cellular_properties =
ShillServiceClient::Get()->GetTestInterface()->GetServiceProperties(
esim_info().service_path());
ASSERT_TRUE(cellular_properties);
const base::Value::List* shill_custom_apns =
cellular_properties->FindList(shill::kCellularCustomApnListProperty);
ASSERT_TRUE(shill_custom_apns);
bool found_matching_apn_name = false;
for (const auto& custom_apn : *shill_custom_apns) {
CHECK(custom_apn.is_dict());
const std::string* apn_name =
custom_apn.GetDict().FindString(shill::kApnProperty);
if (!apn_name || *apn_name != expected_apn_name) {
continue;
}
found_matching_apn_name = true;
const std::string* apn_type =
custom_apn.GetDict().FindString(shill::kApnTypesProperty);
ASSERT_TRUE(apn_type);
EXPECT_EQ(expected_apn_type, *apn_type);
}
EXPECT_EQ(expect_exists, found_matching_apn_name);
}
void VerifyLastGoodApn(const std::string& expected_apn_name) {
const base::Value::Dict* cellular_properties =
ShillServiceClient::Get()->GetTestInterface()->GetServiceProperties(
esim_info().service_path());
ASSERT_TRUE(cellular_properties);
const base::Value::Dict* last_good_apn =
cellular_properties->FindDict(shill::kCellularLastGoodApnProperty);
ASSERT_TRUE(last_good_apn);
const std::string* apn_name =
last_good_apn->FindString(shill::kApnProperty);
ASSERT_TRUE(apn_name);
EXPECT_EQ(expected_apn_name, *apn_name);
}
ui::test::internal::InteractiveTestPrivate::MultiStep CreateCustomApn(
const std::string& apn_name,
bool is_default,
bool is_attach) {
return Steps(
Log("Open add custom APN dialog"),
OpenAddCustomApnDetailsDialog(kOSSettingsId),
Log("Type in custom APN name in APN dialog"),
WaitForElementExists(kOSSettingsId,
settings::cellular::ApnDialogApnInput()),
WaitForElementEnabled(kOSSettingsId,
settings::cellular::ApnDialogApnInput()),
ClickElement(kOSSettingsId, settings::cellular::ApnDialogApnInput()),
SendTextAsKeyEvents(kOSSettingsId, apn_name),
Log("Expand advanced settings"),
WaitForElementEnabled(
kOSSettingsId,
settings::cellular::ApnDialogAdvancedSettingsButton()),
ClickElement(kOSSettingsId,
settings::cellular::ApnDialogAdvancedSettingsButton()),
WaitForElementOpened(
kOSSettingsId,
settings::cellular::ApnDialogAdvancedSettingsGroup()),
Log("Check APN type defaults to 'Default'"),
WaitForElementChecked(kOSSettingsId,
settings::cellular::ApnDialogDefaultCheckbox()),
WaitForElementUnchecked(kOSSettingsId,
settings::cellular::ApnDialogAttachCheckbox()),
Log(base::StringPrintf("Select APN type: Default: %s, Attach: %s",
base::ToString(is_default),
base::ToString(is_attach))),
SelectApnTypeInDialog(is_default, is_attach),
Log("Save the custom APN"),
WaitForElementEnabled(kOSSettingsId,
settings::cellular::ApnDialogAddActionButton()),
ClickElement(kOSSettingsId,
settings::cellular::ApnDialogAddActionButton()),
WaitForElementDoesNotExist(kOSSettingsId,
settings::cellular::ApnDialog()));
}
ui::test::internal::InteractiveTestPrivate::MultiStep DisableNthApnInList(
int n) {
return ClickButtonInDotsMenuOfNthApnInList(
n, settings::cellular::ApnListNthItemDisableButton(n));
}
ui::test::internal::InteractiveTestPrivate::MultiStep RemoveNthApnInList(
int n) {
return ClickButtonInDotsMenuOfNthApnInList(
n, settings::cellular::ApnListNthItemRemoveButton(n));
}
ui::test::internal::InteractiveTestPrivate::MultiStep EnableNthApnInList(
int n) {
return ClickButtonInDotsMenuOfNthApnInList(
n, settings::cellular::ApnListNthItemEnableButton(n));
}
ui::test::internal::InteractiveTestPrivate::MultiStep WaitForApnConnected(
const std::string& apn_name) {
return Steps(
WaitForElementTextContains(kOSSettingsId,
settings::cellular::ApnListFirstItemName(),
/*text=*/apn_name),
WaitForElementTextContains(
kOSSettingsId, settings::cellular::ApnListFirstItemSublabel(),
/*text=*/l10n_util::GetStringUTF8(IDS_ONC_CONNECTED).c_str()),
Do([this, apn_name]() { VerifyLastGoodApn(apn_name); }));
}
ui::test::internal::InteractiveTestPrivate::MultiStep
WaitForAutoDetectedApnConnected() {
return Steps(
WaitForApnConnected(default_modb_apn_name()),
WaitForElementTextContains(
kOSSettingsId, settings::cellular::ApnListItemAutoDetectedDiv(),
/*text=*/
l10n_util::GetStringUTF8(IDS_SETTINGS_APN_AUTO_DETECTED).c_str()));
}
ui::test::internal::InteractiveTestPrivate::MultiStep
DisableAndEnableMobileData() {
return Steps(
Log("Re-enabling mobile data"),
NavigateSettingsToInternetPage(kOSSettingsId),
WaitForToggleState(kOSSettingsId,
settings::cellular::MobileDataToggle(), true),
Log("Disabling mobile data"),
ClickElement(kOSSettingsId, settings::cellular::MobileDataToggle()),
WaitForToggleState(kOSSettingsId,
settings::cellular::MobileDataToggle(), false),
Log("Enabling mobile data"),
ClickElement(kOSSettingsId, settings::cellular::MobileDataToggle()),
WaitForToggleState(kOSSettingsId,
settings::cellular::MobileDataToggle(), true));
}
ui::test::internal::InteractiveTestPrivate::MultiStep
VerifyApnPolicyEnforced() {
return Steps(Log("Wait for policy icon in cellular detail subpage"),
WaitForElementExists(
kOSSettingsId,
settings::cellular::CellularDetailsSubpageApnPolicyIcon()),
Log("Navigate to the APN revamp details page"),
NavigateToApnRevampDetailsPage(kOSSettingsId),
Log("Wait for APN action button is disabled"),
WaitForElementExists(
kOSSettingsId, settings::cellular::ApnSubpagePolicyIcon()),
Log("Wait for automatically detected APN to be connected"),
WaitForAutoDetectedApnConnected());
}
// This function returns a series of steps that are used in two tests: one of
// the tests involves a managed eSIM network and the other test involves an
// unmanaged eSIM network.
ui::test::internal::InteractiveTestPrivate::MultiStep
ApplyApnPolicyAndCheckEnforcement(bool with_managed_network) {
ui::test::internal::InteractiveTestPrivate::MultiStep steps = Steps(
Log("Verify no custom APNs before start testing"),
Do([&]() { VerifyNoCustomApnsInShill(); }),
Log("Navigating to the cellular detail subpage"),
NavigateToInternetDetailsPage(
kOSSettingsId, NetworkTypePattern::Cellular(), esim_info().name()));
if (with_managed_network) {
AddStep(
steps,
Steps(Log("Checking that the policy icon is shown for the network"),
WaitForElementExists(kOSSettingsId,
settings::SettingsSubpagePolicyIcon())));
}
AddStep(
steps,
Steps(Log("Checking that the APN policy icon is not shown"),
WaitForElementDoesNotExist(
kOSSettingsId,
settings::cellular::CellularDetailsSubpageApnPolicyIcon()),
Log("Navigating to the APN details page"),
NavigateToApnRevampDetailsPage(kOSSettingsId),
Log("Verify it connects to the auto detected APN"),
WaitForAutoDetectedApnConnected(),
Log("Creating a custom default APN and waiting for it to be "
"connected"),
CreateCustomApn(kDefaultCustomApnName, /*is_default=*/true,
/*is_attach=*/false),
WaitForApnConnected(kDefaultCustomApnName),
Log("Verify Shill is aware of the APN"),
Do([&]() {
VerifyCustomApnInShill(/*expect_exists=*/true,
kDefaultCustomApnName,
shill::kApnTypeDefault);
}),
Log("Navigating back to the cellular detail subpage"),
NavigateToInternetDetailsPage(kOSSettingsId,
NetworkTypePattern::Cellular(),
esim_info().name()),
Log("Prohibiting APN modification with policy"),
Do([this, with_managed_network]() {
auto network_configs = base::Value::List();
if (with_managed_network) {
network_configs.Append(GenerateCellularPolicy(
esim_info(), /*allow_apn_modification=*/false));
}
base::Value::Dict global_config;
global_config.Set(
::onc::global_network_config::kAllowAPNModification, false);
NetworkHandler::Get()
->managed_network_configuration_handler()
->SetPolicy(::onc::ONC_SOURCE_DEVICE_POLICY,
/*userhash=*/std::string(),
std::move(network_configs), global_config);
}),
Log("Checking that the policy is enforced"),
VerifyApnPolicyEnforced(),
Log("Turning cellular off and back on"),
DisableAndEnableMobileData(),
Log("Navigating to the cellular detail subpage"),
NavigateToInternetDetailsPage(kOSSettingsId,
NetworkTypePattern::Cellular(),
esim_info().name()),
Log("Checking that the policy is enforced"),
VerifyApnPolicyEnforced()));
return steps;
}
private:
ui::test::internal::InteractiveTestPrivate::MultiStep
ClickButtonInDotsMenuOfNthApnInList(
int n,
const WebContentsInteractionTestUtil::DeepQuery& action_button) {
return Steps(
WaitForElementEnabled(kOSSettingsId,
settings::cellular::ApnListNthItemMenuButton(n)),
ClickElement(kOSSettingsId,
settings::cellular::ApnListNthItemMenuButton(n)),
WaitForElementOpened(kOSSettingsId,
settings::cellular::ApnListNthItemDotsMenu(n)),
WaitForElementEnabled(kOSSettingsId, action_button),
ClickElement(kOSSettingsId, action_button),
WaitForElementUnopened(kOSSettingsId,
settings::cellular::ApnListNthItemDotsMenu(n)));
}
ui::test::internal::InteractiveTestPrivate::MultiStep SelectApnTypeInDialog(
bool select_default_type,
bool select_attach_type) {
if (select_default_type && !select_attach_type) {
return Steps();
}
if (select_default_type && select_attach_type) {
return Steps(
SelectCheckbox(settings::cellular::ApnDialogAttachCheckbox()));
}
if (!select_default_type && select_attach_type) {
return Steps(
UnselectCheckbox(settings::cellular::ApnDialogDefaultCheckbox()),
SelectCheckbox(settings::cellular::ApnDialogAttachCheckbox()));
}
// APN type is required.
NOTREACHED();
}
ui::test::internal::InteractiveTestPrivate::MultiStep SelectCheckbox(
const WebContentsInteractionTestUtil::DeepQuery& checkbox) {
return Steps(WaitForElementUnchecked(kOSSettingsId, checkbox),
ClickElement(kOSSettingsId, checkbox),
WaitForElementChecked(kOSSettingsId, checkbox));
}
ui::test::internal::InteractiveTestPrivate::MultiStep UnselectCheckbox(
const WebContentsInteractionTestUtil::DeepQuery& checkbox) {
return Steps(WaitForElementChecked(kOSSettingsId, checkbox),
ClickElement(kOSSettingsId, checkbox),
WaitForElementUnchecked(kOSSettingsId, checkbox));
}
std::unique_ptr<SimInfo> esim_info_;
std::string default_modb_apn_name_;
base::test::ScopedFeatureList scoped_feature_list_;
};
IN_PROC_BROWSER_TEST_F(ApnUiInteractiveUiTest,
NonConnectedCellularHasNoApn) {
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"),
NavigateToInternetDetailsPage(
kOSSettingsId, NetworkTypePattern::Cellular(), esim_info().name()),
Log("Navigate to the APN revamp details page"),
NavigateToApnRevampDetailsPage(kOSSettingsId),
Log("Verify it connects to the auto detected APN"),
WaitForAutoDetectedApnConnected(),
Log("Disconnect cellular network"),
Do([&]() { esim_info().Disconnect(); }),
Log("Verify Zero state message shows and no APN shows in the list when "
"not connected"),
WaitForElementExists(kOSSettingsId,
settings::cellular::ApnSubpageZeroStateContent()),
WaitForElementHasAttribute(
kOSSettingsId, settings::cellular::ApnListFirstItem(), "hidden"),
Log("Test complete"));
}
IN_PROC_BROWSER_TEST_F(ApnUiInteractiveUiTest, MultipleNetworksDefaultApn) {
DEFINE_LOCAL_STATE_IDENTIFIER_VALUE(WaitForServiceConnectedObserver,
kConnectedToCellularService);
SimInfo esim_info1(/*id=*/1);
ConfigureEsimProfile(euicc_info(), esim_info1, /*connected=*/false);
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"),
NavigateToInternetDetailsPage(
kOSSettingsId, NetworkTypePattern::Cellular(), esim_info().name()),
Log("Navigate to the APN revamp details page"),
NavigateToApnRevampDetailsPage(kOSSettingsId),
Log("Verify it connects to the auto detected APN"),
WaitForAutoDetectedApnConnected(),
Log("Navigate to the second cellular network"),
NavigateToInternetDetailsPage(
kOSSettingsId, NetworkTypePattern::Cellular(), esim_info1.name()),
Log("Connect to the second network"),
ObserveState(kConnectedToCellularService,
std::make_unique<WaitForServiceConnectedObserver>(
esim_info1.iccid())),
Do([&]() { esim_info1.Connect(); }),
WaitForState(kConnectedToCellularService, true),
Log("Wait for the UI shows connected"),
WaitForElementTextContains(
kOSSettingsId, settings::SettingsSubpageNetworkState(),
/*text=*/l10n_util::GetStringUTF8(IDS_ONC_CONNECTED).c_str()),
Log("Navigate to the second APN revamp details page"),
NavigateToApnRevampDetailsPage(kOSSettingsId),
Log("Verify it connects to the auto detected APN"),
WaitForAutoDetectedApnConnected(),
Log("Test complete"));
}
IN_PROC_BROWSER_TEST_F(ApnUiInteractiveUiTest, CreateDefaultCustomApn) {
ui::ElementContext context =
LaunchSystemWebApp(SystemWebAppType::SETTINGS, kOSSettingsId);
// Run the following steps with the OS Settings context set as the default.
RunTestSequenceInContext(
context,
Log("Verify no custom APNs before start testing"),
Do([&]() { VerifyNoCustomApnsInShill(); }),
Log("Navigating to the internet page"),
NavigateToInternetDetailsPage(
kOSSettingsId, NetworkTypePattern::Cellular(), esim_info().name()),
Log("Navigate to the APN revamp details page"),
NavigateToApnRevampDetailsPage(kOSSettingsId),
Log("Create default custom APN from the dialog"),
CreateCustomApn(kDefaultCustomApnName, /*is_default=*/true,
/*is_attach=*/false),
Log("Wait for the newly created custom APN appear at the top of the "
"list"),
WaitForElementExists(kOSSettingsId,
settings::cellular::ApnListFirstItem()),
WaitForElementTextContains(kOSSettingsId,
settings::cellular::ApnListFirstItemName(),
/*text=*/kDefaultCustomApnName),
Log("Verify the custom APN saved in Shill"),
Do([&]() {
VerifyCustomApnInShill(/*expect_exists=*/true, kDefaultCustomApnName,
shill::kApnTypeDefault);
}),
Log("Test complete"));
}
IN_PROC_BROWSER_TEST_F(ApnUiInteractiveUiTest,
CreateDefaultAndAttachCustomApn) {
ui::ElementContext context =
LaunchSystemWebApp(SystemWebAppType::SETTINGS, kOSSettingsId);
// Run the following steps with the OS Settings context set as the default.
RunTestSequenceInContext(
context,
Log("Verify no custom APNs before start testing"),
Do([&]() { VerifyNoCustomApnsInShill(); }),
Log("Navigating to the internet page"),
NavigateToInternetDetailsPage(
kOSSettingsId, NetworkTypePattern::Cellular(), esim_info().name()),
Log("Navigate to the APN revamp details page"),
NavigateToApnRevampDetailsPage(kOSSettingsId),
Log("Open add custom APN dialog"),
OpenAddCustomApnDetailsDialog(kOSSettingsId),
Log("Type in custom APN name in APN dialog"),
WaitForElementExists(kOSSettingsId,
settings::cellular::ApnDialogApnInput()),
WaitForElementEnabled(kOSSettingsId,
settings::cellular::ApnDialogApnInput()),
ClickElement(kOSSettingsId, settings::cellular::ApnDialogApnInput()),
SendTextAsKeyEvents(kOSSettingsId, kDefaultCustomApnName),
Log("Expand advanced settings"),
WaitForElementEnabled(
kOSSettingsId, settings::cellular::ApnDialogAdvancedSettingsButton()),
ClickElement(kOSSettingsId,
settings::cellular::ApnDialogAdvancedSettingsButton()),
WaitForElementOpened(
kOSSettingsId, settings::cellular::ApnDialogAdvancedSettingsGroup()),
Log("Check APN type defaults to 'Default'"),
WaitForElementChecked(kOSSettingsId,
settings::cellular::ApnDialogDefaultCheckbox()),
Log("Uncheck 'Default' type"),
ClickElement(kOSSettingsId,
settings::cellular::ApnDialogDefaultCheckbox()),
WaitForElementUnchecked(kOSSettingsId,
settings::cellular::ApnDialogDefaultCheckbox()),
Log("Check 'Attach' type"),
WaitForElementUnchecked(kOSSettingsId,
settings::cellular::ApnDialogAttachCheckbox()),
ClickElement(kOSSettingsId,
settings::cellular::ApnDialogAttachCheckbox()),
WaitForElementChecked(kOSSettingsId,
settings::cellular::ApnDialogAttachCheckbox()),
Log("Check for the warning message"),
WaitForElementExists(
kOSSettingsId, settings::cellular::ApnDialogDefaultApnRequiredInfo()),
Log("Check for the 'Add' button disabled"),
WaitForElementDisabled(kOSSettingsId,
settings::cellular::ApnDialogAddActionButton()),
Log("Re-check the 'Default' type"),
ClickElement(kOSSettingsId,
settings::cellular::ApnDialogDefaultCheckbox()),
WaitForElementChecked(kOSSettingsId,
settings::cellular::ApnDialogDefaultCheckbox()),
Log("Save the custom APN"),
WaitForElementEnabled(kOSSettingsId,
settings::cellular::ApnDialogAddActionButton()),
ClickElement(kOSSettingsId,
settings::cellular::ApnDialogAddActionButton()),
Log("Wait for the newly created custom APN appear at the top of the "
"list"),
WaitForElementExists(kOSSettingsId,
settings::cellular::ApnListFirstItem()),
WaitForElementTextContains(kOSSettingsId,
settings::cellular::ApnListFirstItemName(),
/*text=*/kDefaultCustomApnName),
Log("Wait for the custom APN connected"),
WaitForElementTextContains(
kOSSettingsId, settings::cellular::ApnListFirstItemSublabel(),
/*text=*/l10n_util::GetStringUTF8(IDS_ONC_CONNECTED).c_str()),
Log("Wait for the custom APN connected"),
WaitForElementTextContains(
kOSSettingsId, settings::cellular::ApnListFirstItemSublabel(),
/*text=*/l10n_util::GetStringUTF8(IDS_ONC_CONNECTED).c_str()),
Log("Verify the custom APN saved in Shill"),
Do([&]() {
VerifyCustomApnInShill(
/*expect_exists*/ true, kDefaultCustomApnName,
base::StringPrintf("%s,%s", shill::kApnTypeDefault,
shill::kApnTypeIA));
}),
Log("Test complete"));
}
IN_PROC_BROWSER_TEST_F(ApnUiInteractiveUiTest, DiscoverApns) {
ui::ElementContext context =
LaunchSystemWebApp(SystemWebAppType::SETTINGS, kOSSettingsId);
// Run the following steps with the OS Settings context set as the default.
RunTestSequenceInContext(
context,
Log("Verify no custom APNs before start testing"),
Do([&]() { VerifyNoCustomApnsInShill(); }),
Log("Navigating to the internet page"),
NavigateToInternetDetailsPage(
kOSSettingsId, NetworkTypePattern::Cellular(), esim_info().name()),
Log("Navigate to the APN revamp details page"),
NavigateToApnRevampDetailsPage(kOSSettingsId),
Log("Create default custom APN from the dialog"),
CreateCustomApn(kDefaultCustomApnName, /*is_default=*/true,
/*is_attach=*/false),
Log("Wait for the newly created custom APN appear at the top of the "
"list"),
WaitForElementTextContains(kOSSettingsId,
settings::cellular::ApnListFirstItemName(),
/*text=*/kDefaultCustomApnName),
Log("Wait for the custom APN connected"),
WaitForApnConnected(kDefaultCustomApnName),
Log("Open 'Show known APNs' dialog"),
OpenApnSelectionDialog(kOSSettingsId),
Log("Checking the name of the first APN item"),
WaitForElementTextContains(
kOSSettingsId, settings::cellular::ApnSelectionFirstItemName(),
/*text=*/default_modb_apn_name()),
Log("Select default APNs"),
WaitForElementDisabled(kOSSettingsId,
settings::cellular::ApnSelectionConfirmButton()),
ClickElement(kOSSettingsId, settings::cellular::ApnSelectionFirstItem()),
WaitForElementEnabled(kOSSettingsId,
settings::cellular::ApnSelectionConfirmButton()),
ClickElement(kOSSettingsId,
settings::cellular::ApnSelectionConfirmButton()),
Log("Checking for the APN selection dialog close"),
WaitForElementDoesNotExist(kOSSettingsId,
settings::cellular::ApnSelectionDialog()),
Log("Wait for the default APN connected"),
WaitForApnConnected(default_modb_apn_name()),
Log("Check the custom APN re-ordered to second APN"),
WaitForElementTextContains(kOSSettingsId,
settings::cellular::ApnListNthItemName(2),
/*text=*/kDefaultCustomApnName),
Log("Check custom APN disabled"),
WaitForElementHasAttribute(
kOSSettingsId, settings::cellular::ApnListNthItem(2), "is-disabled_"),
Log("Test complete"));
}
IN_PROC_BROWSER_TEST_F(ApnUiInteractiveUiTest, EnableDisableRemoveApns) {
ui::ElementContext context =
LaunchSystemWebApp(SystemWebAppType::SETTINGS, kOSSettingsId);
// Run the following steps with the OS Settings context set as the default.
RunTestSequenceInContext(
context,
Log("Verify no custom APNs before start testing"),
Do([&]() { VerifyNoCustomApnsInShill(); }),
Log("Navigating to the internet page"),
NavigateToInternetDetailsPage(
kOSSettingsId, NetworkTypePattern::Cellular(), esim_info().name()),
Log("Navigate to the APN revamp details page"),
NavigateToApnRevampDetailsPage(kOSSettingsId),
Log("Create a default custom APN from the dialog"),
CreateCustomApn(kDefaultCustomApnName, /*is_default=*/true,
/*is_attach=*/false),
Log("Wait for the newly created custom APN appear at the top of the "
"list"),
WaitForElementTextContains(kOSSettingsId,
settings::cellular::ApnListFirstItemName(),
/*text=*/kDefaultCustomApnName),
Log("Wait for the default custom APN connected"),
WaitForApnConnected(kDefaultCustomApnName),
Log("Create a attach custom APN from the dialog"),
CreateCustomApn(kAttachCustomApnName, /*is_default=*/false,
/*is_attach=*/true),
Log("Checking for the default custom APN still connected"),
WaitForApnConnected(kDefaultCustomApnName),
Log("Attempt to disable Default APN"),
DisableNthApnInList(1),
Log("Checking for a warning toast and default APN not disabled in Shill"),
WaitForElementTextContains(
kOSSettingsId, settings::InternetPageErrorToastMessage(),
l10n_util::GetStringUTF8(
IDS_SETTINGS_APN_WARNING_PROMPT_FOR_DISABLE_REMOVE)
.c_str()),
Do([&]() {
VerifyCustomApnInShill(/*expect_exists=*/true, kDefaultCustomApnName,
shill::kApnTypeDefault);
}),
Log("Attempt to remove Default APN"),
RemoveNthApnInList(1),
Log("Checking for a warning toast and default APN not removed in Shill"),
WaitForElementTextContains(
kOSSettingsId, settings::InternetPageErrorToastMessage(),
l10n_util::GetStringUTF8(
IDS_SETTINGS_APN_WARNING_PROMPT_FOR_DISABLE_REMOVE)
.c_str()),
Do([&]() {
VerifyCustomApnInShill(/*expect_exists=*/true, kDefaultCustomApnName,
shill::kApnTypeDefault);
}),
Log("Disable Attach APN"),
DisableNthApnInList(2),
WaitForElementHasAttribute(
kOSSettingsId, settings::cellular::ApnListNthItem(2), "is-disabled_"),
Do([&]() {
VerifyCustomApnInShill(/*expect_exists=*/false, kAttachCustomApnName,
shill::kApnTypeIA);
}),
Log("Disable Default APN"),
DisableNthApnInList(1),
Log("Checking for auto-detected APN popped up in the APN list"),
WaitForAutoDetectedApnConnected(),
Log("Checking for Default custom APN removed and Modb APN connected in "
"Shill"),
Do([&]() { VerifyLastGoodApn(default_modb_apn_name()); }),
Log("Checking for both Default and Attach APNs disabled"),
WaitForElementHasAttribute(
kOSSettingsId, settings::cellular::ApnListNthItem(2), "is-disabled_"),
WaitForElementHasAttribute(
kOSSettingsId, settings::cellular::ApnListNthItem(3), "is-disabled_"),
Do([&]() { VerifyNoCustomApnsInShill(); }),
Log("Attempt to enable Attach APN"),
EnableNthApnInList(2),
Log("Checking for a warning toast"),
WaitForElementTextContains(
kOSSettingsId, settings::InternetPageErrorToastMessage(),
l10n_util::GetStringUTF8(IDS_SETTINGS_APN_WARNING_PROMPT_FOR_ENABLE)
.c_str()),
Do([&]() {
VerifyCustomApnInShill(/*expect_exists=*/false, kAttachCustomApnName,
shill::kApnTypeIA);
}),
Log("Enable Default APN"),
EnableNthApnInList(3), WaitForApnConnected(kDefaultCustomApnName),
Do([&]() {
VerifyCustomApnInShill(/*expect_exists=*/true, kDefaultCustomApnName,
shill::kApnTypeDefault);
}),
Log("Remove Attach APN"),
RemoveNthApnInList(2),
Log("Remove Default APN"),
RemoveNthApnInList(1),
Log("Checking for auto-detected APN popped up in the APN list when "
"there is no custom APN"),
WaitForElementTextContains(kOSSettingsId,
settings::cellular::ApnListFirstItemName(),
/*text=*/default_modb_apn_name()),
WaitForElementTextContains(
kOSSettingsId, settings::cellular::ApnListFirstItemSublabel(),
/*text=*/l10n_util::GetStringUTF8(IDS_ONC_CONNECTED).c_str()),
Do([&]() { VerifyLastGoodApn(default_modb_apn_name()); }),
Log("Checking for both custom APNs removed in Shill"),
Do([&]() { VerifyNoCustomApnsInShill(); }),
Log("Test complete"));
}
IN_PROC_BROWSER_TEST_F(ApnUiInteractiveUiTest, ApnPolicyWithUnmanagedNetwork) {
ui::ElementContext context =
LaunchSystemWebApp(SystemWebAppType::SETTINGS, kOSSettingsId);
// Run the following steps with the OS Settings context set as the default.
RunTestSequenceInContext(context,
ApplyApnPolicyAndCheckEnforcement(
/*with_managed_network=*/false),
Log("Test complete"));
}
IN_PROC_BROWSER_TEST_F(ApnUiInteractiveUiTest, ApnPolicyWithManagedNetwork) {
ui::ElementContext context =
LaunchSystemWebApp(SystemWebAppType::SETTINGS, kOSSettingsId);
base::Value::Dict global_config;
global_config.Set(::onc::global_network_config::kAllowAPNModification, true);
// Run the following steps with the OS Settings context set as the default.
RunTestSequenceInContext(context,
ApplyApnPolicyAndCheckEnforcement(
/*with_managed_network=*/true),
Log("Test complete"));
}
} // namespace
} // namespace ash
|