File: esim_interactive_uitest.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 (363 lines) | stat: -rw-r--r-- 14,445 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
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
// 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 <optional>
#include <string>

#include "ash/ash_element_identifiers.h"
#include "base/check.h"
#include "base/test/scoped_run_loop_timeout.h"
#include "base/time/time.h"
#include "chrome/grit/generated_resources.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/network/shill_device_power_state_observer.h"
#include "chrome/test/base/ash/interactive/settings/interactive_uitest_elements.h"
#include "chromeos/ash/components/dbus/shill/shill_device_client.h"
#include "chromeos/ash/components/dbus/shill/shill_service_client.h"
#include "chromeos/ash/components/network/network_type_pattern.h"
#include "chromeos/strings/grit/chromeos_strings.h"
#include "third_party/cros_system_api/dbus/shill/dbus-constants.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/base/interaction/polling_state_observer.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/events/event.h"
#include "ui/events/types/event_type.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/interaction/polling_view_observer.h"
#include "ui/views/test/button_test_api.h"
#include "ui/views/view.h"

namespace ash {
namespace {

DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(kOSSettingsId);
const base::TimeDelta kInhibitPropertyChangeTimeout = base::Seconds(2);

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

    esim_info_ = std::make_unique<SimInfo>(/*id=*/0);
  }

  ui::test::internal::InteractiveTestPrivate::MultiStep
  SetDevicePropertyChangeDelay() {
    return Steps(Do([&]() {
      ShillDeviceClient::TestInterface* device_test =
          ShillDeviceClient::Get()->GetTestInterface();
      device_test->SetPropertyChangeDelay(kInhibitPropertyChangeTimeout);
    }));
  }

  const SimInfo& esim_info() const { return *esim_info_; }

 private:
  std::unique_ptr<SimInfo> esim_info_;
};

IN_PROC_BROWSER_TEST_F(EsimInteractiveUiTest,
                       OpenAddEsimDialogFromQuickSettings) {
  DEFINE_LOCAL_STATE_IDENTIFIER_VALUE(ShillDevicePowerStateObserver,
                                      kMobileDataPoweredState);

  ConfigureEsimProfile(euicc_info(), esim_info(), /*connected=*/true);

  using Observer = views::test::PollingViewObserver<bool, views::View>;
  DEFINE_LOCAL_STATE_IDENTIFIER_VALUE(Observer, kPollingViewState);

  bool has_clicked_add_esim_entry = false;

  RunTestSequence(
      Log("Waiting for cellular to be enabled"),

      ObserveState(
          kMobileDataPoweredState,
          std::make_unique<ShillDevicePowerStateObserver>(
              ShillManagerClient::Get(), NetworkTypePattern::Mobile())),
      WaitForState(kMobileDataPoweredState, true),

      Log("Opening Quick Settings and navigating to the network page"),

      OpenQuickSettings(), NavigateQuickSettingsToNetworkPage(),

      Log("Waiting for the 'add eSIM' button to be visible, then clicking it"),

      InstrumentNextTab(kOSSettingsId, AnyBrowser()),

      // The views in the network page of Quick Settings (that are not
      // top-level e.g. the toggles or headers) are prone to frequent
      // re-ordering and/or can rapidly appear/disappear before being stable due
      // to network state changes. Instead of attempting to click the view via
      // moving and clicking the mouse we instead click via code to avoid the
      // possibility of the element disappearing during the step.
      PollView(
          kPollingViewState, kNetworkAddEsimElementId,
          [&has_clicked_add_esim_entry](const views::View* view) -> bool {
            if (!has_clicked_add_esim_entry) {
              views::test::ButtonTestApi(
                  views::Button::AsButton(const_cast<views::View*>(view)))
                  .NotifyClick(ui::MouseEvent(ui::EventType::kMousePressed,
                                              gfx::PointF(), gfx::PointF(),
                                              base::TimeTicks(), 0, 0));
            }
            has_clicked_add_esim_entry = true;
            return true;
          },
          base::Milliseconds(50)),

      // The `WaitForState` step also requires that the element in question
      // exists for the duration of the step. As mentioned above, the element
      // may rapidly appear/disappear which would cause `WaitForState` to fail.
      // Instead, we wait for the Quick Settings to close as a result of the
      // button being clicked.

      WaitForHide(ash::kQuickSettingsViewElementId),

      Log("Waiting for OS Settings to open"),

      InAnyContext(WaitForShow(kOSSettingsId)));

  ui::ElementContext context = FindSystemWebApp(SystemWebAppType::SETTINGS);

  // Run the remaining steps with a longer timeout since it can take more than
  // 10 seconds for OS Settings to open.
  const base::test::ScopedRunLoopTimeout longer_timeout(FROM_HERE,
                                                        base::Seconds(15));

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

      Log("Waiting for OS Settings to navigate to cellular subpage"),

      WaitForElementTextContains(
          kOSSettingsId, settings::InternetSettingsSubpageTitle(),
          /*text=*/l10n_util::GetStringUTF8(IDS_NETWORK_TYPE_MOBILE_DATA)),

      Log("Waiting for 'add eSIM' dialog to open"),

      WaitForElementTextContains(
          kOSSettingsId, settings::cellular::EsimDialogTitle(),
          /*text=*/
          l10n_util::GetStringUTF8(
              IDS_CELLULAR_SETUP_ESIM_PAGE_PROFILE_DISCOVERY_CONSENT_TITLE)),

      Do([&]() { CloseSystemWebApp(SystemWebAppType::SETTINGS); }),

      Log("Test complete"));
}

IN_PROC_BROWSER_TEST_F(EsimInteractiveUiTest, AutoconnectBehavior) {
  DEFINE_LOCAL_STATE_IDENTIFIER_VALUE(ShillDevicePowerStateObserver,
                                      kMobileDataPoweredState);
  DEFINE_LOCAL_STATE_IDENTIFIER_VALUE(WaitForServiceConnectedObserver,
                                      kCellularServiceConnected);
  DEFINE_LOCAL_STATE_IDENTIFIER_VALUE(ui::test::PollingStateObserver<bool>,
                                      kCellularServiceAutoconnect);

  ConfigureEsimProfile(euicc_info(), esim_info(), /*connected=*/true);

  ui::ElementContext context =
      LaunchSystemWebApp(SystemWebAppType::SETTINGS, kOSSettingsId);

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

      Log("Waiting for cellular to be enabled"),

      ObserveState(
          kMobileDataPoweredState,
          std::make_unique<ShillDevicePowerStateObserver>(
              ShillManagerClient::Get(), NetworkTypePattern::Mobile())),
      WaitForState(kMobileDataPoweredState, true),

      Log("Waiting for cellular network to be connected"),

      ObserveState(kCellularServiceConnected,
                   std::make_unique<WaitForServiceConnectedObserver>(
                       esim_info().iccid())),
      WaitForState(kCellularServiceConnected, true),

      Log("Waiting for cellular network to be have auto-connect enabled"),

      PollState(kCellularServiceAutoconnect,
                [this]() -> bool {
                  const auto* shill_service_client_test =
                      ShillServiceClient::Get()->GetTestInterface();
                  CHECK(shill_service_client_test);
                  const auto* cellular_properties =
                      shill_service_client_test->GetServiceProperties(
                          esim_info().service_path());
                  CHECK(cellular_properties);
                  const std::optional<bool> autoconnect =
                      cellular_properties->FindBool(
                          shill::kAutoConnectProperty);
                  CHECK(autoconnect.has_value());
                  return *autoconnect;
                }),
      WaitForState(kCellularServiceAutoconnect, true),

      Log("Navigating to the details page for the cellular network"),

      NavigateToInternetDetailsPage(kOSSettingsId,
                                    NetworkTypePattern::Cellular(),
                                    esim_info().nickname()),
      WaitForElementTextContains(kOSSettingsId,
                                 settings::InternetSettingsSubpageTitle(),
                                 /*text=*/esim_info().nickname()),

      Log("Disabling auto-connect for the cellular network"),

      WaitForElementEnabled(
          kOSSettingsId,
          settings::cellular::CellularDetailsSubpageAutoConnectToggle()),
      WaitForElementChecked(
          kOSSettingsId,
          settings::cellular::CellularDetailsSubpageAutoConnectToggle()),
      ClickElement(
          kOSSettingsId,
          settings::cellular::CellularDetailsSubpageAutoConnectToggle()),
      WaitForElementUnchecked(
          kOSSettingsId,
          settings::cellular::CellularDetailsSubpageAutoConnectToggle()),
      WaitForState(kCellularServiceAutoconnect, false),
      WaitForElementWithManagedPropertyBoolean(
          kOSSettingsId, settings::InternetDetailsSubpage(),
          /*property=*/"typeProperties.cellular.autoConnect",
          /*expected_value=*/false),

      Log("Enabling auto-connect for the cellular network"),

      ClickElement(
          kOSSettingsId,
          settings::cellular::CellularDetailsSubpageAutoConnectToggle()),
      WaitForElementChecked(
          kOSSettingsId,
          settings::cellular::CellularDetailsSubpageAutoConnectToggle()),
      WaitForState(kCellularServiceAutoconnect, true),

      Log("Closing the Settings app"),

      Do([&]() { CloseSystemWebApp(SystemWebAppType::SETTINGS); }),

      Log("Test complete"));
}

IN_PROC_BROWSER_TEST_F(EsimInteractiveUiTest,
                       ConnectDisconnectFromDetailsPage) {
  DEFINE_LOCAL_STATE_IDENTIFIER_VALUE(WaitForServiceConnectedObserver,
                                      kCellularServiceConnected);

  ConfigureEsimProfile(euicc_info(), esim_info(), /*connected=*/true);

  ui::ElementContext context =
      LaunchSystemWebApp(SystemWebAppType::SETTINGS, kOSSettingsId);

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

      ObserveState(kCellularServiceConnected,
                   std::make_unique<WaitForServiceConnectedObserver>(
                       esim_info().iccid())),
      WaitForState(kCellularServiceConnected, true),

      Log("Navigating to the details page for the eSIM network"),

      NavigateToInternetDetailsPage(kOSSettingsId,
                                    NetworkTypePattern::Cellular(),
                                    esim_info().nickname()),

      Log("Disconnect eSIM network"),

      WaitForElementExists(kOSSettingsId,
                           settings::SettingsSubpageConnectDisconnectButton()),
      ClickElement(kOSSettingsId,
                   settings::SettingsSubpageConnectDisconnectButton()),
      WaitForState(kCellularServiceConnected, false),

      Log("Connect to eSIM network"),

      WaitForElementExists(kOSSettingsId,
                           settings::SettingsSubpageConnectDisconnectButton()),
      ClickElement(kOSSettingsId,
                   settings::SettingsSubpageConnectDisconnectButton()),
      WaitForState(kCellularServiceConnected, true),

      WaitForElementTextContains(
          kOSSettingsId, settings::SettingsSubpageNetworkState(),
          /*text=*/l10n_util::GetStringUTF8(IDS_ONC_CONNECTED).c_str()),

      Log("Test complete"));
}

IN_PROC_BROWSER_TEST_F(EsimInteractiveUiTest, ConnectFromMobileDataSubpage) {
  DEFINE_LOCAL_STATE_IDENTIFIER_VALUE(WaitForServiceConnectedObserver,
                                      kCellularServiceConnected);

  ConfigureEsimProfile(euicc_info(), esim_info(), /*connected=*/false);

  ui::ElementContext context =
      LaunchSystemWebApp(SystemWebAppType::SETTINGS, kOSSettingsId);

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

      ObserveState(kCellularServiceConnected,
                   std::make_unique<WaitForServiceConnectedObserver>(
                       esim_info().iccid())),
      WaitForState(kCellularServiceConnected, false),

      Log("Navigating to Mobile data subpage"),

      NavigateSettingsToNetworkSubpage(kOSSettingsId,
                                       ash::NetworkTypePattern::Mobile()),

      Log("Connect to eSIM network"),

      // Add a property change delay to allow enough time for test to
      // observe cellular inhibition changes in the UI.
      SetDevicePropertyChangeDelay(),

      ClickAnyElementTextContains(kOSSettingsId,
                                  settings::cellular::CellularNetworksList(),
                                  WebContentsInteractionTestUtil::DeepQuery({
                                      "network-list",
                                      "network-list-item",
                                      "div#divText",
                                  }),
                                  esim_info().nickname()),

      Log("Check cellular is inhibited"),

      WaitForElementDoesNotHaveAttribute(
          kOSSettingsId, settings::cellular::CellularInhibitedItem(), "hidden"),

      Log("Check cellular is no longer inhibited"),

      WaitForElementHasAttribute(
          kOSSettingsId, settings::cellular::CellularInhibitedItem(), "hidden"),

      Log("Check network is connected"),

      WaitForState(kCellularServiceConnected, true),
      WaitForAnyElementTextContains(
          kOSSettingsId, settings::cellular::CellularNetworksList(),
          WebContentsInteractionTestUtil::DeepQuery(
              {"network-list", "network-list-item", "div#sublabel"}),
          l10n_util::GetStringUTF8(IDS_ONC_CONNECTED).c_str()),

      Log("Test complete"));
}

}  // namespace
}  // namespace ash