File: protocol_handling_sub_manager_unittest.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; 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,811; 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 (530 lines) | stat: -rw-r--r-- 20,733 bytes parent folder | download | duplicates (4)
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
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <memory>
#include <utility>
#include <vector>

#include "base/files/file_util.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/test/test_future.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/os_integration/os_integration_manager.h"
#include "chrome/browser/web_applications/os_integration/web_app_file_handler_manager.h"
#include "chrome/browser/web_applications/os_integration/web_app_protocol_handler_manager.h"
#include "chrome/browser/web_applications/proto/web_app_os_integration_state.pb.h"
#include "chrome/browser/web_applications/test/fake_web_app_provider.h"
#include "chrome/browser/web_applications/test/os_integration_test_override_impl.h"
#include "chrome/browser/web_applications/test/web_app_install_test_utils.h"
#include "chrome/browser/web_applications/test/web_app_test.h"
#include "chrome/browser/web_applications/test/web_app_test_utils.h"
#include "chrome/browser/web_applications/web_app_command_scheduler.h"
#include "chrome/browser/web_applications/web_app_install_finalizer.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/browser/web_applications/web_app_install_params.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/common/chrome_features.h"
#include "components/services/app_service/public/cpp/protocol_handler_info.h"
#include "components/webapps/browser/install_result_code.h"
#include "components/webapps/browser/uninstall_result_code.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

#if BUILDFLAG(IS_MAC)
#include "chrome/browser/web_applications/os_integration/mac/app_shim_registry.h"
#endif

namespace web_app {

using ::testing::ElementsAre;
using ::testing::Eq;
using ::testing::IsEmpty;
enum class ApiApprovalState;

namespace {

class ProtocolHandlingSubManagerTestBase : public WebAppTest {
 public:
  const GURL kWebAppUrl = GURL("https://example.com/path/index.html");

  ProtocolHandlingSubManagerTestBase() = default;
  ~ProtocolHandlingSubManagerTestBase() override = default;

  void SetUp() override {
    WebAppTest::SetUp();
    {
      base::ScopedAllowBlockingForTesting allow_blocking;
      test_override_ = OsIntegrationTestOverrideImpl::OverrideForTesting();
    }
    provider_ = FakeWebAppProvider::Get(profile());

    auto file_handler_manager =
        std::make_unique<WebAppFileHandlerManager>(profile());
    auto protocol_handler_manager =
        std::make_unique<WebAppProtocolHandlerManager>(profile());
    auto os_integration_manager = std::make_unique<OsIntegrationManager>(
        profile(), std::move(file_handler_manager),
        std::move(protocol_handler_manager));

    provider_->SetOsIntegrationManager(std::move(os_integration_manager));
    test::AwaitStartWebAppProviderAndSubsystems(profile());
  }

  void TearDown() override {
    test::UninstallAllWebApps(profile());
    // Blocking required due to file operations in the shortcut override
    // destructor.
    {
      base::ScopedAllowBlockingForTesting allow_blocking;
      test_override_.reset();
    }
    WebAppTest::TearDown();
  }

  webapps::AppId InstallWebAppWithProtocolHandlers(
      const std::vector<apps::ProtocolHandlerInfo>& protocol_handlers) {
    std::unique_ptr<WebAppInstallInfo> info =
        WebAppInstallInfo::CreateWithStartUrlForTesting(kWebAppUrl);
    info->title = u"Test App";
    info->user_display_mode = web_app::mojom::UserDisplayMode::kStandalone;
    info->protocol_handlers = protocol_handlers;
    base::test::TestFuture<const webapps::AppId&, webapps::InstallResultCode>
        result;
    // InstallFromInfoWithParams is used instead of InstallFromInfo, because
    // InstallFromInfo doesn't register OS integration.
    provider().scheduler().InstallFromInfoWithParams(
        std::move(info), /*overwrite_existing_manifest_fields=*/true,
        webapps::WebappInstallSource::OMNIBOX_INSTALL_ICON,
        result.GetCallback(), WebAppInstallParams());
    bool success = result.Wait();
    EXPECT_TRUE(success);
    if (!success)
      return webapps::AppId();
    EXPECT_EQ(result.Get<webapps::InstallResultCode>(),
              webapps::InstallResultCode::kSuccessNewInstall);
    return result.Get<webapps::AppId>();
  }

 protected:
  WebAppProvider& provider() { return *provider_; }

 private:
  raw_ptr<FakeWebAppProvider, DanglingUntriaged> provider_ = nullptr;
  std::unique_ptr<OsIntegrationTestOverrideImpl::BlockingRegistration>
      test_override_;
};

using ProtocolHandlingConfigureTest = ProtocolHandlingSubManagerTestBase;

TEST_F(ProtocolHandlingConfigureTest, ConfigureOnlyProtocolHandler) {
  apps::ProtocolHandlerInfo protocol_handler;
  const std::string handler_url =
      std::string(kWebAppUrl.spec()) + "/testing=%s";
  protocol_handler.url = GURL(handler_url);
  protocol_handler.protocol = "web+test";

  const webapps::AppId app_id =
      InstallWebAppWithProtocolHandlers({protocol_handler});

  auto state =
      provider().registrar_unsafe().GetAppCurrentOsIntegrationState(app_id);
  ASSERT_TRUE(state.has_value());
  const proto::os_state::WebAppOsIntegration& os_integration_state =
      state.value();
  ASSERT_THAT(os_integration_state.protocols_handled().protocols_size(),
              testing::Eq(1));

  const proto::os_state::ProtocolsHandled::Protocol& protocol_handler_state =
      os_integration_state.protocols_handled().protocols(0);

  ASSERT_THAT(protocol_handler_state.protocol(),
              testing::Eq(protocol_handler.protocol));
  ASSERT_THAT(protocol_handler_state.url(), testing::Eq(handler_url));
}

TEST_F(ProtocolHandlingConfigureTest, UninstalledAppDoesNotConfigure) {
  apps::ProtocolHandlerInfo protocol_handler;
  const std::string handler_url =
      std::string(kWebAppUrl.spec()) + "/testing=%s";
  protocol_handler.url = GURL(handler_url);
  protocol_handler.protocol = "web+test";

  const webapps::AppId app_id =
      InstallWebAppWithProtocolHandlers({protocol_handler});
  test::UninstallAllWebApps(profile());

  auto state =
      provider().registrar_unsafe().GetAppCurrentOsIntegrationState(app_id);
  ASSERT_FALSE(state.has_value());
}

TEST_F(ProtocolHandlingConfigureTest, ConfigureProtocolHandlerDisallowed) {
  apps::ProtocolHandlerInfo protocol_handler1;
  const std::string handler_url1 =
      std::string(kWebAppUrl.spec()) + "/testing=%s";
  protocol_handler1.url = GURL(handler_url1);
  protocol_handler1.protocol = "web+test";

  apps::ProtocolHandlerInfo protocol_handler2;
  const std::string handler_url2 =
      std::string(kWebAppUrl.spec()) + "/testing_protocol=%s";
  protocol_handler2.url = GURL(handler_url2);
  protocol_handler2.protocol = "web+test+protocol";

  const webapps::AppId app_id =
      InstallWebAppWithProtocolHandlers({protocol_handler1, protocol_handler2});
  {
    base::test::TestFuture<void> disallowed_future;
    provider().scheduler().UpdateProtocolHandlerUserApproval(
        app_id, "web+test", ApiApprovalState::kDisallowed,
        disallowed_future.GetCallback());
    EXPECT_TRUE(disallowed_future.Wait());
  }

  auto state =
      provider().registrar_unsafe().GetAppCurrentOsIntegrationState(app_id);
  ASSERT_TRUE(state.has_value());
  const proto::os_state::WebAppOsIntegration& os_integration_state =
      state.value();
  ASSERT_THAT(os_integration_state.protocols_handled().protocols_size(),
              testing::Eq(1));

  const proto::os_state::ProtocolsHandled::Protocol& protocol_handler_state =
      os_integration_state.protocols_handled().protocols(0);

  ASSERT_THAT(protocol_handler_state.protocol(),
              testing::Eq(protocol_handler2.protocol));
  ASSERT_THAT(protocol_handler_state.url(), testing::Eq(handler_url2));
}

// Synchronize and Execute tests from here onwards. Tests here should
// verify both DB updates as well as OS registrations/unregistrations.
class ProtocolHandlingExecuteTest : public ProtocolHandlingSubManagerTestBase {
 public:
  ProtocolHandlingExecuteTest() = default;
  ~ProtocolHandlingExecuteTest() override = default;

#if BUILDFLAG(IS_MAC)
  std::vector<std::string> GetAppShimRegisteredProtocolHandlers(
      const webapps::AppId& app_id) {
    std::vector<std::string> protocol_schemes;
    for (const auto& [file_path, handler] :
         AppShimRegistry::Get()->GetHandlersForApp(app_id)) {
      protocol_schemes.insert(protocol_schemes.end(),
                              handler.protocol_handlers.begin(),
                              handler.protocol_handlers.end());
    }
    return protocol_schemes;
  }
#endif  // BUILDFLAG(IS_MAC)

  bool AreProtocolsRegisteredWithOs() { return !BUILDFLAG(IS_CHROMEOS); }
};

TEST_F(ProtocolHandlingExecuteTest, Register) {
  apps::ProtocolHandlerInfo protocol_handler;
  const std::string handler_url =
      std::string(kWebAppUrl.spec()) + "/testing=%s";
  protocol_handler.url = GURL(handler_url);
  protocol_handler.protocol = "web+test";
  const webapps::AppId app_id =
      InstallWebAppWithProtocolHandlers({protocol_handler});

  auto state =
      provider().registrar_unsafe().GetAppCurrentOsIntegrationState(app_id);
  ASSERT_TRUE(state.has_value());
  const proto::os_state::WebAppOsIntegration& os_integration_state =
      state.value();
  ASSERT_THAT(os_integration_state.protocols_handled().protocols_size(),
              testing::Eq(1));

  const proto::os_state::ProtocolsHandled::Protocol& protocol_handler_state =
      os_integration_state.protocols_handled().protocols(0);

  ASSERT_THAT(protocol_handler_state.protocol(),
              testing::Eq(protocol_handler.protocol));
  ASSERT_THAT(protocol_handler_state.url(), testing::Eq(handler_url));

#if BUILDFLAG(IS_MAC)
    EXPECT_THAT(GetAppShimRegisteredProtocolHandlers(app_id),
                testing::ElementsAre(protocol_handler.protocol));
#endif

    if (AreProtocolsRegisteredWithOs()) {
      // Installation registers the protocol handlers.
      EXPECT_THAT(
          OsIntegrationTestOverrideImpl::Get()->protocol_scheme_registrations(),
          testing::ElementsAre(std::make_tuple(
              app_id, std::vector({protocol_handler.protocol}))));
    }
}

TEST_F(ProtocolHandlingExecuteTest, Unregister) {
  apps::ProtocolHandlerInfo protocol_handler;
  const std::string handler_url =
      std::string(kWebAppUrl.spec()) + "/testing=%s";
  protocol_handler.url = GURL(handler_url);
  protocol_handler.protocol = "web+test";
  const webapps::AppId app_id =
      InstallWebAppWithProtocolHandlers({protocol_handler});
  test::UninstallAllWebApps(profile());

  auto state =
      provider().registrar_unsafe().GetAppCurrentOsIntegrationState(app_id);
  ASSERT_FALSE(state.has_value());

#if BUILDFLAG(IS_MAC)
  ASSERT_THAT(GetAppShimRegisteredProtocolHandlers(app_id), testing::IsEmpty());
#endif

  if (AreProtocolsRegisteredWithOs()) {
    ASSERT_THAT(
        OsIntegrationTestOverrideImpl::Get()->protocol_scheme_registrations(),
        testing::ElementsAre(
            std::make_tuple(app_id, std::vector({protocol_handler.protocol})),
            std::make_tuple(app_id, std::vector<std::string>())));
  }
}

// This test has extra assertions since Windows registers protocol handlers
// differently than Mac/Linux where protocol handlers are bundled as part
// of the shortcuts OS integration process.
TEST_F(ProtocolHandlingExecuteTest, UpdateHandlers) {
  apps::ProtocolHandlerInfo protocol_handler_approved;
  const std::string handler_url1 =
      std::string(kWebAppUrl.spec()) + "/testing=%s";
  protocol_handler_approved.url = GURL(handler_url1);
  protocol_handler_approved.protocol = "web+test";

  apps::ProtocolHandlerInfo protocol_handler_disapproved;
  const std::string handler_url2 =
      std::string(kWebAppUrl.spec()) + "/testing_protocol=%s";
  protocol_handler_disapproved.url = GURL(handler_url2);
  protocol_handler_disapproved.protocol = "web+test+protocol";

  const webapps::AppId app_id = InstallWebAppWithProtocolHandlers(
      {protocol_handler_approved, protocol_handler_disapproved});
  {
    base::test::TestFuture<void> disallowed_future;
    provider().scheduler().UpdateProtocolHandlerUserApproval(
        app_id, protocol_handler_disapproved.protocol,
        ApiApprovalState::kDisallowed, disallowed_future.GetCallback());
    EXPECT_TRUE(disallowed_future.Wait());
  }

  auto state =
      provider().registrar_unsafe().GetAppCurrentOsIntegrationState(app_id);
  ASSERT_TRUE(state.has_value());
  const proto::os_state::WebAppOsIntegration& os_integration_state =
      state.value();

  ASSERT_THAT(os_integration_state.protocols_handled().protocols_size(),
              testing::Eq(1));

  const proto::os_state::ProtocolsHandled::Protocol& protocol_handler_state =
      os_integration_state.protocols_handled().protocols(0);

  ASSERT_THAT(protocol_handler_state.protocol(),
              testing::Eq(protocol_handler_approved.protocol));
  ASSERT_THAT(protocol_handler_state.url(), testing::Eq(handler_url1));

#if BUILDFLAG(IS_MAC)
    ASSERT_THAT(GetAppShimRegisteredProtocolHandlers(app_id),
                testing::ElementsAre(protocol_handler_approved.protocol));
#endif
    if (AreProtocolsRegisteredWithOs()) {
#if BUILDFLAG(IS_WIN)
      ASSERT_THAT(
          OsIntegrationTestOverrideImpl::Get()->protocol_scheme_registrations(),
          testing::ElementsAre(
              std::make_tuple(
                  app_id, std::vector({protocol_handler_approved.protocol,
                                       protocol_handler_disapproved.protocol})),
              std::make_tuple(app_id, std::vector<std::string>()),
              std::make_tuple(
                  app_id, std::vector({protocol_handler_approved.protocol}))));
#else
      ASSERT_THAT(
          OsIntegrationTestOverrideImpl::Get()->protocol_scheme_registrations(),
          testing::ElementsAre(
              std::make_tuple(
                  app_id, std::vector({protocol_handler_approved.protocol,
                                       protocol_handler_disapproved.protocol})),
              std::make_tuple(
                  app_id, std::vector({protocol_handler_approved.protocol}))));
#endif  // BUILDFLAG(IS_WIN)
    }
}

TEST_F(ProtocolHandlingExecuteTest, DataEqualNoOp) {
  apps::ProtocolHandlerInfo protocol_handler;
  const std::string handler_url =
      std::string(kWebAppUrl.spec()) + "/testing=%s";
  protocol_handler.url = GURL(handler_url);
  protocol_handler.protocol = "web+test";

  const webapps::AppId app_id =
      InstallWebAppWithProtocolHandlers({protocol_handler});
  {
    base::test::TestFuture<void> future;
    provider().scheduler().UpdateProtocolHandlerUserApproval(
        app_id, protocol_handler.protocol, ApiApprovalState::kAllowed,
        future.GetCallback());
    EXPECT_TRUE(future.Wait());
  }

  auto state =
      provider().registrar_unsafe().GetAppCurrentOsIntegrationState(app_id);
  ASSERT_TRUE(state.has_value());
  const proto::os_state::WebAppOsIntegration& os_integration_state =
      state.value();

  ASSERT_THAT(os_integration_state.protocols_handled().protocols_size(),
              testing::Eq(1));

  const proto::os_state::ProtocolsHandled::Protocol& protocol_handler_state =
      os_integration_state.protocols_handled().protocols(0);

  ASSERT_THAT(protocol_handler_state.protocol(),
              testing::Eq(protocol_handler.protocol));
  ASSERT_THAT(protocol_handler_state.url(), testing::Eq(handler_url));

#if BUILDFLAG(IS_MAC)
    ASSERT_THAT(GetAppShimRegisteredProtocolHandlers(app_id),
                testing::ElementsAre(protocol_handler.protocol));
#endif
    if (AreProtocolsRegisteredWithOs()) {
      ASSERT_THAT(
          OsIntegrationTestOverrideImpl::Get()->protocol_scheme_registrations(),
          testing::ElementsAre(std::make_tuple(
              app_id, std::vector({protocol_handler.protocol}))));
    }
}

TEST_F(ProtocolHandlingExecuteTest, MultipleSynchronizeEmptyData) {
  const webapps::AppId app_id1 = InstallWebAppWithProtocolHandlers(
      std::vector<apps::ProtocolHandlerInfo>());
  const webapps::AppId app_id2 = InstallWebAppWithProtocolHandlers(
      std::vector<apps::ProtocolHandlerInfo>());
  ASSERT_THAT(app_id1, testing::Eq(app_id2));

  auto state =
      provider().registrar_unsafe().GetAppCurrentOsIntegrationState(app_id1);
  ASSERT_TRUE(state.has_value());
  const proto::os_state::WebAppOsIntegration& os_integration_state =
      state.value();

  ASSERT_THAT(os_integration_state.protocols_handled().protocols_size(),
              testing::Eq(0));
#if BUILDFLAG(IS_MAC)
    ASSERT_THAT(GetAppShimRegisteredProtocolHandlers(app_id1),
                testing::IsEmpty());
#endif
    if (AreProtocolsRegisteredWithOs()) {
      ASSERT_THAT(
          OsIntegrationTestOverrideImpl::Get()->protocol_scheme_registrations(),
          testing::IsEmpty());
    }
}

TEST_F(ProtocolHandlingExecuteTest, ForceUnregisterAppInRegistry) {
  apps::ProtocolHandlerInfo protocol_handler;
  const std::string handler_url =
      std::string(kWebAppUrl.spec()) + "/testing=%s";
  protocol_handler.url = GURL(handler_url);
  protocol_handler.protocol = "web+test";
  const webapps::AppId app_id =
      InstallWebAppWithProtocolHandlers({protocol_handler});

  auto state =
      provider().registrar_unsafe().GetAppCurrentOsIntegrationState(app_id);
  ASSERT_TRUE(state.has_value());

#if BUILDFLAG(IS_MAC)
  EXPECT_THAT(GetAppShimRegisteredProtocolHandlers(app_id),
              testing::ElementsAre(protocol_handler.protocol));
#endif
  if (AreProtocolsRegisteredWithOs()) {
    EXPECT_THAT(
        OsIntegrationTestOverrideImpl::Get()->protocol_scheme_registrations(),
        testing::ElementsAre(
            std::make_tuple(app_id, std::vector({protocol_handler.protocol}))));
  }

  SynchronizeOsOptions options;
  options.force_unregister_os_integration = true;
  test::SynchronizeOsIntegration(profile(), app_id, options);

#if BUILDFLAG(IS_MAC)
  ASSERT_THAT(GetAppShimRegisteredProtocolHandlers(app_id), testing::IsEmpty());
#endif
  if (AreProtocolsRegisteredWithOs()) {
    EXPECT_THAT(
        OsIntegrationTestOverrideImpl::Get()->protocol_scheme_registrations(),
        testing::ElementsAre(
            std::make_tuple(app_id, std::vector({protocol_handler.protocol})),
            std::make_tuple(app_id, std::vector<std::string>())));
  }
}

TEST_F(ProtocolHandlingExecuteTest, ForceUnregisterAppNotInRegistry) {
  apps::ProtocolHandlerInfo protocol_handler;
  const std::string handler_url =
      std::string(kWebAppUrl.spec()) + "/testing=%s";
  protocol_handler.url = GURL(handler_url);
  protocol_handler.protocol = "web+test";
  const webapps::AppId app_id =
      InstallWebAppWithProtocolHandlers({protocol_handler});

  auto state =
      provider().registrar_unsafe().GetAppCurrentOsIntegrationState(app_id);
  ASSERT_TRUE(state.has_value());

#if BUILDFLAG(IS_MAC)
  EXPECT_THAT(GetAppShimRegisteredProtocolHandlers(app_id),
              testing::ElementsAre(protocol_handler.protocol));
#endif
  if (AreProtocolsRegisteredWithOs()) {
    EXPECT_THAT(
        OsIntegrationTestOverrideImpl::Get()->protocol_scheme_registrations(),
        testing::ElementsAre(
            std::make_tuple(app_id, std::vector({protocol_handler.protocol}))));
  }

  test::UninstallAllWebApps(profile());
#if BUILDFLAG(IS_MAC)
  EXPECT_THAT(GetAppShimRegisteredProtocolHandlers(app_id), testing::IsEmpty());
#endif
  if (AreProtocolsRegisteredWithOs()) {
    EXPECT_THAT(
        OsIntegrationTestOverrideImpl::Get()->protocol_scheme_registrations(),
        testing::ElementsAre(
            std::make_tuple(app_id, std::vector({protocol_handler.protocol})),
            std::make_tuple(app_id, std::vector<std::string>())));
  }
  EXPECT_FALSE(provider().registrar_unsafe().IsInRegistrar(app_id));

  // This should have no affect.
  SynchronizeOsOptions options;
  options.force_unregister_os_integration = true;
  test::SynchronizeOsIntegration(profile(), app_id, options);
#if BUILDFLAG(IS_MAC)
  ASSERT_THAT(GetAppShimRegisteredProtocolHandlers(app_id), testing::IsEmpty());
#endif
  if (AreProtocolsRegisteredWithOs()) {
    EXPECT_THAT(
        OsIntegrationTestOverrideImpl::Get()->protocol_scheme_registrations(),
        testing::ElementsAre(
            std::make_tuple(app_id, std::vector({protocol_handler.protocol})),
            std::make_tuple(app_id, std::vector<std::string>()),
            std::make_tuple(app_id, std::vector<std::string>())));
  }
}

}  // namespace

}  // namespace web_app