File: force_installed_test_base.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; 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 (98 lines) | stat: -rw-r--r-- 3,522 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
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_FORCED_EXTENSIONS_FORCE_INSTALLED_TEST_BASE_H_
#define CHROME_BROWSER_EXTENSIONS_FORCED_EXTENSIONS_FORCE_INSTALLED_TEST_BASE_H_

#include "base/memory/raw_ptr.h"
#include "chrome/browser/extensions/forced_extensions/force_installed_tracker.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "content/public/test/browser_task_environment.h"
#include "extensions/common/extension.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace sync_preferences {
class TestingPrefServiceSyncable;
}

namespace extensions {

class ExtensionRegistry;
class InstallStageTracker;

// This class is extended by tests to provide a setup for tracking installation
// of force extensions. It also provides helper functions for creating and
// setting ExtensionInstallForcelist policy value.
class ForceInstalledTestBase : public testing::Test {
 public:
  enum class ExtensionOrigin {
    kWebStore,
    kOffStore,
  };

  ForceInstalledTestBase();
  ~ForceInstalledTestBase() override;

  ForceInstalledTestBase(const ForceInstalledTestBase&) = delete;
  ForceInstalledTestBase& operator=(const ForceInstalledTestBase&) = delete;

 protected:
  void SetUp() override;

  // Creates and sets value for ExtensionInstallForcelist policy and
  // kInstallForceList preference. `source` tells whether the extensions
  // specified in the policy should have an update URL from CWS or not.
  void SetupForceList(ExtensionOrigin origin);

  // Creates and sets empty value for ExtensionInstallForcelist policy and
  // kInstallForceList preference.
  void SetupEmptyForceList();

  // Creates a new extension with `extension_id` and `extension_name` and fakes
  // its status by calling one of ForceInstalledTracker's
  // ExtensionRegistryObserver override.
  scoped_refptr<const Extension> CreateNewExtension(
      const std::string& extension_name,
      const std::string& extension_id,
      const ForceInstalledTracker::ExtensionStatus& status);

  Profile* profile() const { return profile_; }

  sync_preferences::TestingPrefServiceSyncable* prefs() const { return prefs_; }

  ExtensionRegistry* registry() const { return registry_; }

  InstallStageTracker* install_stage_tracker() const {
    return install_stage_tracker_;
  }

  ForceInstalledTracker* force_installed_tracker() const {
    return force_installed_tracker_.get();
  }

  static const char kExtensionId1[];
  static const char kExtensionId2[];
  static const char kExtensionName1[];
  static const char kExtensionName2[];
  static const char kExtensionUpdateUrl[];
  static const char kOffStoreUpdateUrl[];

  content::BrowserTaskEnvironment task_environment_{
      base::test::TaskEnvironment::TimeSource::MOCK_TIME};

 private:
  testing::NiceMock<policy::MockConfigurationPolicyProvider> policy_provider_;
  std::unique_ptr<TestingProfileManager> profile_manager_;
  raw_ptr<TestingProfile> profile_;
  raw_ptr<sync_preferences::TestingPrefServiceSyncable> prefs_;
  raw_ptr<ExtensionRegistry> registry_;
  raw_ptr<InstallStageTracker> install_stage_tracker_;
  std::unique_ptr<ForceInstalledTracker> force_installed_tracker_;
};

}  // namespace extensions

#endif  // CHROME_BROWSER_EXTENSIONS_FORCED_EXTENSIONS_FORCE_INSTALLED_TEST_BASE_H_