File: mv2_deprecation_impact_checker_unittest.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 (566 lines) | stat: -rw-r--r-- 23,096 bytes parent folder | download | duplicates (5)
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
// 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 "base/memory/raw_ptr.h"
#include "base/strings/stringprintf.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/values_test_util.h"
#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/extensions/extension_management_internal.h"
#include "chrome/browser/extensions/extension_service_test_base.h"
#include "chrome/browser/extensions/manifest_v2_experiment_manager.h"
#include "chrome/browser/extensions/mv2_experiment_stage.h"
#include "chrome/browser/profiles/profile.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "extensions/browser/pref_names.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/mojom/manifest.mojom.h"

namespace extensions {

namespace {

// Hashed ID for 'aaaa...a'.
constexpr char kTestHashedIdA[] = "68F84A59A3CA2D0E5CB1646FBB164DA409B5D8F2";
// Hashed ID for 'bbbb...b'.
constexpr char kTestHashedIdB[] = "142E27CA6D179970507F4076E2AC96FEC5834F82";

// The setting of the MV2 policy to use.
enum class MV2PolicyLevel {
  // Unset. Default browser behavior.
  kUnset,
  // All MV2 extensions are allowed.
  kAllowed,
  // All MV2 extensions are disallowed.
  kDisallowed,
  // Only MV2 extensions installed by admin policy are allowed.
  kAllowedForAdminInstalledOnly,
};

// A test variant that allows parameterization of both the experiment stage and
// the policy level.
using TestVariant = std::tuple<MV2ExperimentStage, MV2PolicyLevel>;

// Describes the current test variants; used in describing parameterized tests.
std::string DescribeTestVariant(const TestVariant& test_variant) {
  const MV2ExperimentStage experiment_stage = std::get<0>(test_variant);
  const MV2PolicyLevel policy_level = std::get<1>(test_variant);

  std::string description;

  switch (policy_level) {
    case MV2PolicyLevel::kUnset:
      description += "PolicyUnset";
      break;
    case MV2PolicyLevel::kAllowed:
      description += "MV2AllowedByPolicy";
      break;
    case MV2PolicyLevel::kDisallowed:
      description += "MV2DisallowedByPolicy";
      break;
    case MV2PolicyLevel::kAllowedForAdminInstalledOnly:
      description += "MV2ForAdminInstalledOnly";
      break;
  }

  description += "And";

  switch (experiment_stage) {
    case MV2ExperimentStage::kNone:
      description += "ExperimentIsDisabled";
      break;
    case MV2ExperimentStage::kWarning:
      description += "WarningExperiment";
      break;
    case MV2ExperimentStage::kDisableWithReEnable:
      description += "DisableExperiment";
      break;
    case MV2ExperimentStage::kUnsupported:
      description += "UnsupportedExperiment";
      break;
  }

  return description;
}

}  // namespace

class MV2DeprecationImpactCheckerUnitTest
    : public ExtensionServiceTestBase,
      public testing::WithParamInterface<TestVariant> {
 public:
  MV2DeprecationImpactCheckerUnitTest();
  ~MV2DeprecationImpactCheckerUnitTest() override = default;

  void SetUp() override {
    ExtensionServiceTestBase::SetUp();

    // Note: This is (subtly) different from
    // `InitializeEmptyExtensionService()`, which doesn't initialize a
    // testing PrefService.
    InitializeExtensionService(ExtensionServiceInitParams{});

    // Sets the current level of the MV2 admin policy.
    sync_preferences::TestingPrefServiceSyncable* pref_service =
        testing_pref_service();
    std::optional<internal::GlobalSettings::ManifestV2Setting> pref_value;
    switch (mv2_policy_level_) {
      case MV2PolicyLevel::kUnset:
        break;  // Don't set the policy.
      case MV2PolicyLevel::kAllowed:
        pref_value = internal::GlobalSettings::ManifestV2Setting::kEnabled;
        break;
      case MV2PolicyLevel::kDisallowed:
        pref_value = internal::GlobalSettings::ManifestV2Setting::kDisabled;
        break;
      case MV2PolicyLevel::kAllowedForAdminInstalledOnly:
        pref_value = internal::GlobalSettings::ManifestV2Setting::
            kEnabledForForceInstalled;
        break;
    }

    if (pref_value) {
      pref_service->SetManagedPref(pref_names::kManifestV2Availability,
                                   base::Value(static_cast<int>(*pref_value)));
    }

    impact_checker_ = std::make_unique<MV2DeprecationImpactChecker>(
        experiment_stage_,
        ExtensionManagementFactory::GetForBrowserContext(profile()));
  }

  void TearDown() override {
    impact_checker_ = nullptr;
    ExtensionServiceTestBase::TearDown();
  }

  // Since this is testing the MV2 deprecation experiments, we don't want to
  // bypass their disabling for testing.
  bool ShouldAllowMV2Extensions() override { return false; }

  // Adds a new force-installed extension with the given `name`,
  // `manifest_location`, and `manifest_version`.
  scoped_refptr<const Extension> AddForceInstalledExtension(
      const std::string& name,
      mojom::ManifestLocation location,
      int manifest_version) {
    return AddPolicyInstalledExtension(name, location, manifest_version,
                                       "force_installed");
  }

  // Adds a new "recommended" extension with the given `name`,
  // `manifest_location`, and `manifest_version`. "Recommended" extensions
  // are installed and always kept installed, but may be disabled by the user.
  scoped_refptr<const Extension> AddRecommendedPolicyExtension(
      const std::string& name,
      mojom::ManifestLocation location,
      int manifest_version) {
    return AddPolicyInstalledExtension(name, location, manifest_version,
                                       "normal_installed");
  }

  // Adds a new extension that's explicitly allowed by admin policy, but is
  // not force- or default-installed.
  scoped_refptr<const Extension> AddAllowedPolicyExtension(
      const std::string& name,
      mojom::ManifestLocation location,
      int manifest_version) {
    return AddPolicyInstalledExtension(name, location, manifest_version,
                                       "allowed");
  }

  // Returns true if the MV2 deprecation experiment is active in any stage.
  bool ExperimentIsActive() const {
    return experiment_stage_ != MV2ExperimentStage::kNone;
  }

  MV2DeprecationImpactChecker* impact_checker() {
    return impact_checker_.get();
  }
  MV2PolicyLevel policy_level() const { return mv2_policy_level_; }

 private:
  // Helper function to add a policy extension entry.
  scoped_refptr<const Extension> AddPolicyInstalledExtension(
      const std::string& name,
      mojom::ManifestLocation location,
      int manifest_version,
      const std::string& installation_mode) {
    scoped_refptr<const Extension> extension =
        ExtensionBuilder(name)
            .SetLocation(location)
            .SetManifestVersion(manifest_version)
            .Build();

    sync_preferences::TestingPrefServiceSyncable* pref_service =
        testing_pref_service();
    const base::Value* existing_value =
        pref_service->GetManagedPref(pref_names::kExtensionManagement);
    base::Value::Dict new_value;
    if (existing_value) {
      new_value = existing_value->Clone().TakeDict();
    }

    new_value.Set(extension->id(),
                  base::Value::Dict()
                      .Set("installation_mode", installation_mode)
                      .Set("update_url", "http://example.com/"));

    pref_service->SetManagedPref(pref_names::kExtensionManagement,
                                 std::move(new_value));

    return extension;
  }

  const MV2ExperimentStage experiment_stage_;
  const MV2PolicyLevel mv2_policy_level_;
  std::unique_ptr<MV2DeprecationImpactChecker> impact_checker_;
};

MV2DeprecationImpactCheckerUnitTest::MV2DeprecationImpactCheckerUnitTest()
    : experiment_stage_(std::get<0>(GetParam())),
      mv2_policy_level_(std::get<1>(GetParam())) {}

class MV2DeprecationImpactCheckerUnitTestWithAllowlist
    : public MV2DeprecationImpactCheckerUnitTest {
 public:
  MV2DeprecationImpactCheckerUnitTestWithAllowlist() {
    std::string params =
        base::StringPrintf("%s,%s", kTestHashedIdA, kTestHashedIdB);
    feature_list_.InitAndEnableFeatureWithParameters(
        extensions_features::kExtensionManifestV2ExceptionList,
        {{extensions_features::kExtensionManifestV2ExceptionListParam.name,
          params}});
  }
  ~MV2DeprecationImpactCheckerUnitTestWithAllowlist() override = default;

 private:
  base::test::ScopedFeatureList feature_list_;
};

INSTANTIATE_TEST_SUITE_P(
    ,
    MV2DeprecationImpactCheckerUnitTest,
    testing::Combine(
        testing::Values(MV2ExperimentStage::kNone,
                        MV2ExperimentStage::kWarning,
                        MV2ExperimentStage::kDisableWithReEnable,
                        MV2ExperimentStage::kUnsupported),
        testing::Values(MV2PolicyLevel::kUnset,
                        MV2PolicyLevel::kAllowed,
                        MV2PolicyLevel::kDisallowed,
                        MV2PolicyLevel::kAllowedForAdminInstalledOnly)),
    [](const testing::TestParamInfo<TestVariant>& info) {
      return DescribeTestVariant(info.param);
    });

INSTANTIATE_TEST_SUITE_P(
    ,
    MV2DeprecationImpactCheckerUnitTestWithAllowlist,
    testing::Combine(
        testing::Values(MV2ExperimentStage::kNone,
                        MV2ExperimentStage::kWarning,
                        MV2ExperimentStage::kDisableWithReEnable,
                        MV2ExperimentStage::kUnsupported),
        testing::Values(MV2PolicyLevel::kUnset,
                        MV2PolicyLevel::kAllowed,
                        MV2PolicyLevel::kDisallowed,
                        MV2PolicyLevel::kAllowedForAdminInstalledOnly)),
    [](const testing::TestParamInfo<TestVariant>& info) {
      return DescribeTestVariant(info.param);
    });

// Tests that user-visible MV2 extensions are properly considered affected by
// the MV2 deprecation experiment.
TEST_P(MV2DeprecationImpactCheckerUnitTest,
       UserVisibleMV2ExtensionsAreAffected) {
  scoped_refptr<const Extension> user_installed =
      ExtensionBuilder("user installed")
          .SetLocation(mojom::ManifestLocation::kInternal)
          .SetManifestVersion(2)
          .Build();
  scoped_refptr<const Extension> external_registry =
      ExtensionBuilder("external registry")
          .SetLocation(mojom::ManifestLocation::kExternalRegistry)
          .SetManifestVersion(2)
          .Build();
  scoped_refptr<const Extension> external_pref =
      ExtensionBuilder("external pref")
          .SetLocation(mojom::ManifestLocation::kExternalPref)
          .SetManifestVersion(2)
          .Build();
  scoped_refptr<const Extension> external_pref_download =
      ExtensionBuilder("external pref download")
          .SetLocation(mojom::ManifestLocation::kExternalPrefDownload)
          .SetManifestVersion(2)
          .Build();

  // Unpacked (and commandline) extensions *are* affected by the MV2
  // deprecation.  They will be treated differently depending on the experiment
  // stage, but should be included in e.g. the warning.
  scoped_refptr<const Extension> unpacked =
      ExtensionBuilder("unpacked")
          .SetLocation(mojom::ManifestLocation::kUnpacked)
          .SetManifestVersion(2)
          .Build();
  scoped_refptr<const Extension> commandline =
      ExtensionBuilder("commandline")
          .SetLocation(mojom::ManifestLocation::kCommandLine)
          .SetManifestVersion(2)
          .Build();

  // These user-facing MV2 extensions would be affected if the experiment is
  // active and the policy is anything other than set to "Allowed" (which
  // allows all MV2 extensions).
  bool expected_affected =
      ExperimentIsActive() && policy_level() != MV2PolicyLevel::kAllowed;
  EXPECT_EQ(expected_affected,
            impact_checker()->IsExtensionAffected(*user_installed));
  EXPECT_EQ(expected_affected,
            impact_checker()->IsExtensionAffected(*external_registry));
  EXPECT_EQ(expected_affected,
            impact_checker()->IsExtensionAffected(*external_pref));
  EXPECT_EQ(expected_affected,
            impact_checker()->IsExtensionAffected(*external_pref_download));
  EXPECT_EQ(expected_affected,
            impact_checker()->IsExtensionAffected(*unpacked));
  EXPECT_EQ(expected_affected,
            impact_checker()->IsExtensionAffected(*commandline));
}

// Checks that certain special cases of extensions, such as default-installed
// and installed by OEM, are also affected by the MV2 deprecation experiments.
TEST_P(MV2DeprecationImpactCheckerUnitTest,
       DefaultInstalledMV2ExtensionsAreAffected) {
  scoped_refptr<const Extension> default_installed =
      ExtensionBuilder("default installed")
          .SetLocation(mojom::ManifestLocation::kInternal)
          .SetManifestVersion(2)
          .AddFlags(Extension::WAS_INSTALLED_BY_DEFAULT)
          .Build();
  scoped_refptr<const Extension> oem_installed =
      ExtensionBuilder("oem installed")
          .SetLocation(mojom::ManifestLocation::kInternal)
          .SetManifestVersion(2)
          .AddFlags(Extension::WAS_INSTALLED_BY_DEFAULT &
                    Extension::WAS_INSTALLED_BY_OEM)
          .Build();

  // These extensions should be affected if the experiment is enabled and the
  // policy isn't set to allow all MV2 extensions.
  bool expected_affected =
      ExperimentIsActive() && policy_level() != MV2PolicyLevel::kAllowed;
  EXPECT_EQ(expected_affected,
            impact_checker()->IsExtensionAffected(*default_installed));
  EXPECT_EQ(expected_affected,
            impact_checker()->IsExtensionAffected(*oem_installed));
}

// Tests that component extensions are not included in the MV2 deprecation
// experiment (they're implementation details of the browser).
TEST_P(MV2DeprecationImpactCheckerUnitTest, ComponentExtensionsAreNotAffected) {
  scoped_refptr<const Extension> component =
      ExtensionBuilder("component")
          .SetLocation(mojom::ManifestLocation::kComponent)
          .SetManifestVersion(2)
          .Build();
  scoped_refptr<const Extension> external_component =
      ExtensionBuilder("external component")
          .SetLocation(mojom::ManifestLocation::kExternalComponent)
          .SetManifestVersion(2)
          .Build();

  // Component extensions are never affected by the experiment.
  EXPECT_FALSE(impact_checker()->IsExtensionAffected(*component));
  EXPECT_FALSE(impact_checker()->IsExtensionAffected(*external_component));
}

// Tests that MV3 extensions, of any location, are not affected by the MV2
// deprecation experiment.
TEST_P(MV2DeprecationImpactCheckerUnitTest, NoMV3ExtensionsAreAffected) {
  struct {
    mojom::ManifestLocation manifest_location;
    const char* name;
  } test_cases[] = {
      {mojom::ManifestLocation::kInternal, "internal"},
      {mojom::ManifestLocation::kExternalPref, "external pref"},
      {mojom::ManifestLocation::kExternalRegistry, "external registry"},
      {mojom::ManifestLocation::kUnpacked, "unpacked"},
      {mojom::ManifestLocation::kComponent, "component"},
      {mojom::ManifestLocation::kExternalPrefDownload,
       "external pref download"},
      {mojom::ManifestLocation::kExternalPolicyDownload,
       "external policy download"},
      {mojom::ManifestLocation::kCommandLine, "command line"},
      {mojom::ManifestLocation::kExternalPolicy, "external policy"},
      {mojom::ManifestLocation::kExternalComponent, "external component"},
  };

  for (const auto& test_case : test_cases) {
    SCOPED_TRACE(test_case.name);
    scoped_refptr<const Extension> extension =
        ExtensionBuilder(test_case.name)
            .SetManifestVersion(3)
            .SetLocation(test_case.manifest_location)
            .Build();
    EXPECT_FALSE(impact_checker()->IsExtensionAffected(*extension));
  }
}

// Tests that MV2 policy-installed extensions are affected if and only if the
// policy does not exempt them.
TEST_P(MV2DeprecationImpactCheckerUnitTest,
       MV2PolicyInstalledExtensionsMayBeAffected) {
  scoped_refptr<const Extension> forced_policy = AddForceInstalledExtension(
      "forced policy", mojom::ManifestLocation::kExternalPolicy, 2);
  scoped_refptr<const Extension> forced_policy_download =
      AddForceInstalledExtension(
          "forced policy download",
          mojom::ManifestLocation::kExternalPolicyDownload, 2);
  scoped_refptr<const Extension> recommended_policy =
      AddRecommendedPolicyExtension(
          "recommended policy", mojom::ManifestLocation::kExternalPolicy, 2);
  scoped_refptr<const Extension> recommended_policy_download =
      AddRecommendedPolicyExtension(
          "recommended policy download",
          mojom::ManifestLocation::kExternalPolicyDownload, 2);

  bool policy_installed_mv2_extensions_allowed =
      policy_level() == MV2PolicyLevel::kAllowed ||
      policy_level() == MV2PolicyLevel::kAllowedForAdminInstalledOnly;

  // Policy installs are affected if they are not exempt by policy and if the
  // experiment is active.
  bool policy_installs_affected =
      ExperimentIsActive() && !policy_installed_mv2_extensions_allowed;

  EXPECT_EQ(policy_installs_affected,
            impact_checker()->IsExtensionAffected(*forced_policy));
  EXPECT_EQ(policy_installs_affected,
            impact_checker()->IsExtensionAffected(*forced_policy_download));
  EXPECT_EQ(policy_installs_affected,
            impact_checker()->IsExtensionAffected(*recommended_policy));
  EXPECT_EQ(policy_installs_affected, impact_checker()->IsExtensionAffected(
                                          *recommended_policy_download));
}

// Tests that MV2 extensions that are allowed by policy, but not policy-
// installed, are treated as other MV2 extensions.
TEST_P(MV2DeprecationImpactCheckerUnitTest,
       MV2PolicyAllowedExtensionsMayBeAffected) {
  scoped_refptr<const Extension> allowed_policy = AddAllowedPolicyExtension(
      "allowed policy", mojom::ManifestLocation::kExternalPolicy, 2);
  scoped_refptr<const Extension> allowed_policy_download =
      AddAllowedPolicyExtension(
          "allowed policy download",
          mojom::ManifestLocation::kExternalPolicyDownload, 2);

  // "allowed" policy installs (as opposed to recommend or force-installed
  // installs) are affected if the experiment is on and the policy does not
  // allow *all* MV2 extensions.
  bool all_mv2_extensions_allowed = policy_level() == MV2PolicyLevel::kAllowed;
  bool allowed_installs_affected =
      ExperimentIsActive() && !all_mv2_extensions_allowed;
  EXPECT_EQ(allowed_installs_affected,
            impact_checker()->IsExtensionAffected(*allowed_policy));
  EXPECT_EQ(allowed_installs_affected,
            impact_checker()->IsExtensionAffected(*allowed_policy_download));
}

// Tests that any MV3 extension installed by policy is never affected by
// MV2 experiments.
TEST_P(MV2DeprecationImpactCheckerUnitTest,
       MV3PolicyInstalledExtensionsNeverAffected) {
  scoped_refptr<const Extension> forced_policy = AddForceInstalledExtension(
      "forced policy", mojom::ManifestLocation::kExternalPolicy, 3);
  scoped_refptr<const Extension> forced_policy_download =
      AddForceInstalledExtension(
          "forced policy download",
          mojom::ManifestLocation::kExternalPolicyDownload, 3);
  scoped_refptr<const Extension> recommended_policy =
      AddRecommendedPolicyExtension(
          "recommended policy", mojom::ManifestLocation::kExternalPolicy, 3);
  scoped_refptr<const Extension> recommended_policy_download =
      AddRecommendedPolicyExtension(
          "recommended policy download",
          mojom::ManifestLocation::kExternalPolicyDownload, 3);
  scoped_refptr<const Extension> allowed_policy = AddAllowedPolicyExtension(
      "allowed policy", mojom::ManifestLocation::kExternalPolicy, 3);
  scoped_refptr<const Extension> allowed_policy_download =
      AddAllowedPolicyExtension(
          "allowed policy download",
          mojom::ManifestLocation::kExternalPolicyDownload, 3);

  EXPECT_FALSE(impact_checker()->IsExtensionAffected(*forced_policy));
  EXPECT_FALSE(impact_checker()->IsExtensionAffected(*forced_policy_download));
  EXPECT_FALSE(impact_checker()->IsExtensionAffected(*recommended_policy));
  EXPECT_FALSE(
      impact_checker()->IsExtensionAffected(*recommended_policy_download));
  EXPECT_FALSE(impact_checker()->IsExtensionAffected(*allowed_policy));
  EXPECT_FALSE(impact_checker()->IsExtensionAffected(*allowed_policy_download));
}

// Tests that non-extension "extension-like" things (such as platform apps and
// hosted apps) are not affected by the MV2 deprecation experiment.
TEST_P(MV2DeprecationImpactCheckerUnitTest, NonExtensionsAreNotAffected) {
  scoped_refptr<const Extension> platform_app =
      ExtensionBuilder("app", ExtensionBuilder::Type::PLATFORM_APP)
          .SetManifestVersion(2)
          .Build();
  ASSERT_TRUE(platform_app->is_platform_app());

  static constexpr char kHostedAppManifest[] =
      R"({
           "name": "hosted app",
           "manifest_version": 2,
           "version": "0.1",
           "app": {"urls": ["http://example.com/"]}
         })";
  scoped_refptr<const Extension> hosted_app =
      ExtensionBuilder()
          .SetManifest(base::test::ParseJsonDict(kHostedAppManifest))
          .Build();
  ASSERT_TRUE(hosted_app->is_hosted_app());

  EXPECT_FALSE(impact_checker()->IsExtensionAffected(*platform_app));
  EXPECT_FALSE(impact_checker()->IsExtensionAffected(*hosted_app));
}

// Tests the allowlist is taken into account.
TEST_P(MV2DeprecationImpactCheckerUnitTestWithAllowlist, AllowlistWorks) {
  scoped_refptr<const Extension> ext_a =
      ExtensionBuilder("ext-a")
          .SetLocation(mojom::ManifestLocation::kInternal)
          .SetManifestVersion(2)
          .SetID(std::string(32, 'a'))
          .Build();
  scoped_refptr<const Extension> ext_b =
      ExtensionBuilder("ext-b")
          .SetLocation(mojom::ManifestLocation::kInternal)
          .SetManifestVersion(2)
          .SetID(std::string(32, 'b'))
          .Build();
  scoped_refptr<const Extension> ext_c =
      ExtensionBuilder("ext-c")
          .SetLocation(mojom::ManifestLocation::kInternal)
          .SetManifestVersion(2)
          .SetID(std::string(32, 'c'))
          .Build();

  // User-facing MV2 extensions would be affected if the experiment is active
  // and the policy is anything other than set to "Allowed" (which allows all
  // MV2 extensions).
  bool expected_affected =
      ExperimentIsActive() && policy_level() != MV2PolicyLevel::kAllowed;

  // `ext_a` and `ext_b` are in the allowlist, so aren't affected.
  EXPECT_FALSE(impact_checker()->IsExtensionAffected(*ext_a));
  EXPECT_FALSE(impact_checker()->IsExtensionAffected(*ext_b));
  // `ext_c` is not in the allowlist, so is affected if the experiment is active
  // and the policy isn't set.
  EXPECT_EQ(expected_affected, impact_checker()->IsExtensionAffected(*ext_c));
}

}  // namespace extensions