Skip to content

Commit

Permalink
Makes AppDependencyProvider non-instantiatable (#3373)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/414235014887631/1208353288582614/f

## Description

This is a follow up to [NetworkProtectionTunnelController
leaking](https://app.asana.com/0/inbox/1203108348814444/1208331423616717/1208348963925370)

We want to make AppDependencyProvider non instantiatable, since it's
really not meant to be.
  • Loading branch information
diegoreymendez authored Sep 20, 2024
1 parent 158d928 commit 9478841
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
12 changes: 9 additions & 3 deletions DuckDuckGo/AppDependencyProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protocol DependencyProvider {

/// Provides dependencies for objects that are not directly instantiated
/// through `init` call (e.g. ViewControllers created from Storyboards).
class AppDependencyProvider: DependencyProvider {
final class AppDependencyProvider: DependencyProvider {

static var shared: DependencyProvider = AppDependencyProvider()

Expand Down Expand Up @@ -89,12 +89,12 @@ class AppDependencyProvider: DependencyProvider {
let networkProtectionTunnelController: NetworkProtectionTunnelController

let subscriptionAppGroup = Bundle.main.appGroup(bundle: .subs)

let connectionObserver: ConnectionStatusObserver = ConnectionStatusObserverThroughSession()
let serverInfoObserver: ConnectionServerInfoObserver = ConnectionServerInfoObserverThroughSession()
let vpnSettings = VPNSettings(defaults: .networkProtectionGroupDefaults)

init() {
private init() {
featureFlagger = DefaultFeatureFlagger(internalUserDecider: internalUserDecider,
privacyConfigManager: ContentBlocking.shared.privacyConfigurationManager)

Expand Down Expand Up @@ -144,4 +144,10 @@ class AppDependencyProvider: DependencyProvider {
vpnFeatureVisibility = DefaultNetworkProtectionVisibility(userDefaults: .networkProtectionGroupDefaults,
accountManager: accountManager)
}

/// Only meant to be used for testing.
///
static func makeTestingInstance() -> Self {
Self.init()
}
}
2 changes: 1 addition & 1 deletion DuckDuckGoTests/AutoClearSettingsScreenTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AutoClearSettingsScreenTests: XCTestCase {
override func tearDown() {
super.tearDown()

AppDependencyProvider.shared = AppDependencyProvider()
AppDependencyProvider.shared = AppDependencyProvider.makeTestingInstance()
}

func testWhenOpeningSettingsThenClearDataToggleIsSetBasedOnAppSettings() {
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGoTests/LargeOmniBarStateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LargeOmniBarStateTests: XCTestCase {
override func tearDown() {
super.tearDown()

AppDependencyProvider.shared = AppDependencyProvider()
AppDependencyProvider.shared = AppDependencyProvider.makeTestingInstance()
}

func testWhenInHomeEmptyEditingStateWithoutVoiceSearchThenCorrectButtonsAreShown() {
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGoTests/MockDependencyProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class MockDependencyProvider: DependencyProvider {
var vpnSettings: NetworkProtection.VPNSettings

init() {
let defaultProvider = AppDependencyProvider()
let defaultProvider = AppDependencyProvider.makeTestingInstance()
appSettings = defaultProvider.appSettings
variantManager = defaultProvider.variantManager
featureFlagger = defaultProvider.featureFlagger
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGoTests/SmallOmniBarStateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SmallOmniBarStateTests: XCTestCase {
override func tearDown() {
super.tearDown()

AppDependencyProvider.shared = AppDependencyProvider()
AppDependencyProvider.shared = AppDependencyProvider.makeTestingInstance()
}

func testWhenInHomeEmptyEditingStateWithoutVoiceSearchThenCorrectButtonsAreShown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ final class SubscriptionPagesUseSubscriptionFeatureTests: XCTestCase {
pixelsFired.removeAll()
HTTPStubs.removeAllStubs()

AppDependencyProvider.shared = AppDependencyProvider()
AppDependencyProvider.shared = AppDependencyProvider.makeTestingInstance()

subscriptionService = nil
authService = nil
Expand Down

0 comments on commit 9478841

Please sign in to comment.