Skip to content

Commit 43b6e27

Browse files
authored
Fix Sessions Test App with Fake Subscriber (#10684)
1 parent a6d50a1 commit 43b6e27

File tree

3 files changed

+102
-6
lines changed

3 files changed

+102
-6
lines changed

FirebaseSessions/Tests/TestApp/AppQualityDevApp.xcodeproj/project.pbxproj

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@
88

99
/* Begin PBXBuildFile section */
1010
11B8D8A180615BBC0D6AA351 /* Pods_AppQualityDevApp_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3811A234E55662F7F459917A /* Pods_AppQualityDevApp_iOS.framework */; };
11-
1242A440A78627992C815FEE /* BuildFile in Frameworks */ = {isa = PBXBuildFile; };
11+
1242A440A78627992C815FEE /* (null) in Frameworks */ = {isa = PBXBuildFile; };
1212
42270ED35776E973127DB60D /* Pods_AppQualityDevApp_Performance_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BEDB83A06DD433EF06A4FFDC /* Pods_AppQualityDevApp_Performance_iOS.framework */; };
1313
687EF774F928ABB40381A18D /* Pods_AppQualityDevApp_Crashlytics_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9346F75872574EC9869B351A /* Pods_AppQualityDevApp_Crashlytics_iOS.framework */; };
1414
B43C5DD563235C70F18FA91C /* Pods_AppQualityDevApp_CrashlyticsPerformance_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1737E4D779EC21E163AEADE0 /* Pods_AppQualityDevApp_CrashlyticsPerformance_iOS.framework */; };
1515
CF94D83D29070DF600308FF7 /* UITestsiOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF94D83C29070DF600308FF7 /* UITestsiOS.swift */; };
16+
DF240E1F2971E996009F38CD /* MockSubscriberSDK.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF240E1E2971E996009F38CD /* MockSubscriberSDK.swift */; };
17+
DF240E202971E996009F38CD /* MockSubscriberSDK.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF240E1E2971E996009F38CD /* MockSubscriberSDK.swift */; };
18+
DF240E212971E996009F38CD /* MockSubscriberSDK.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF240E1E2971E996009F38CD /* MockSubscriberSDK.swift */; };
19+
DF240E222971E996009F38CD /* MockSubscriberSDK.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF240E1E2971E996009F38CD /* MockSubscriberSDK.swift */; };
20+
DF240E232971E996009F38CD /* MockSubscriberSDK.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF240E1E2971E996009F38CD /* MockSubscriberSDK.swift */; };
1621
DF33DA8C28E4941400F7B88B /* AppQualityDevAppApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF33DA6428E4941100F7B88B /* AppQualityDevAppApp.swift */; };
1722
DF33DA8D28E4941400F7B88B /* AppQualityDevAppApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF33DA6428E4941100F7B88B /* AppQualityDevAppApp.swift */; };
1823
DF33DA8E28E4941400F7B88B /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF33DA6528E4941100F7B88B /* ContentView.swift */; };
@@ -35,7 +40,7 @@
3540
DF9ABFFE295CD14F00EFFEB7 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = DF68F14228E4A34B00753C7E /* GoogleService-Info.plist */; };
3641
E16DE450B5A5D7EC71FCDF4D /* Pods_AppQualityDevApp_macOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EDA875D20BA56FABDFC9A521 /* Pods_AppQualityDevApp_macOS.framework */; };
3742
E47C7F742B2E926AAFEFF448 /* Pods_AppQualityDevApp_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3811A234E55662F7F459917A /* Pods_AppQualityDevApp_iOS.framework */; };
38-
F0820554CDC281260638D6D7 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; };
43+
F0820554CDC281260638D6D7 /* (null) in Frameworks */ = {isa = PBXBuildFile; };
3944
/* End PBXBuildFile section */
4045

4146
/* Begin PBXContainerItemProxy section */
@@ -112,6 +117,7 @@
112117
CFF3426B813F69EFC3CC95C2 /* Pods-AppQualityDevApp_Performance_iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AppQualityDevApp_Performance_iOS.debug.xcconfig"; path = "Target Support Files/Pods-AppQualityDevApp_Performance_iOS/Pods-AppQualityDevApp_Performance_iOS.debug.xcconfig"; sourceTree = "<group>"; };
113118
D18C61BD25DEE281DA8E8007 /* Pods-AppQualityDevAppWatchOS WatchKit Extension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AppQualityDevAppWatchOS WatchKit Extension.release.xcconfig"; path = "Target Support Files/Pods-AppQualityDevAppWatchOS WatchKit Extension/Pods-AppQualityDevAppWatchOS WatchKit Extension.release.xcconfig"; sourceTree = "<group>"; };
114119
DAA707D0793CF2FF718DDDD6 /* Pods-AppQualityDevApp (iOS).debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AppQualityDevApp (iOS).debug.xcconfig"; path = "Target Support Files/Pods-AppQualityDevApp (iOS)/Pods-AppQualityDevApp (iOS).debug.xcconfig"; sourceTree = "<group>"; };
120+
DF240E1E2971E996009F38CD /* MockSubscriberSDK.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockSubscriberSDK.swift; sourceTree = "<group>"; };
115121
DF33DA6428E4941100F7B88B /* AppQualityDevAppApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppQualityDevAppApp.swift; sourceTree = "<group>"; };
116122
DF33DA6528E4941100F7B88B /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
117123
DF33DA6628E4941400F7B88B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -140,7 +146,7 @@
140146
isa = PBXFrameworksBuildPhase;
141147
buildActionMask = 2147483647;
142148
files = (
143-
1242A440A78627992C815FEE /* BuildFile in Frameworks */,
149+
1242A440A78627992C815FEE /* (null) in Frameworks */,
144150
11B8D8A180615BBC0D6AA351 /* Pods_AppQualityDevApp_iOS.framework in Frameworks */,
145151
E47C7F742B2E926AAFEFF448 /* Pods_AppQualityDevApp_iOS.framework in Frameworks */,
146152
);
@@ -158,7 +164,7 @@
158164
isa = PBXFrameworksBuildPhase;
159165
buildActionMask = 2147483647;
160166
files = (
161-
F0820554CDC281260638D6D7 /* BuildFile in Frameworks */,
167+
F0820554CDC281260638D6D7 /* (null) in Frameworks */,
162168
687EF774F928ABB40381A18D /* Pods_AppQualityDevApp_Crashlytics_iOS.framework in Frameworks */,
163169
);
164170
runOnlyForDeploymentPostprocessing = 0;
@@ -244,6 +250,7 @@
244250
DF68F14228E4A34B00753C7E /* GoogleService-Info.plist */,
245251
DF33DA6428E4941100F7B88B /* AppQualityDevAppApp.swift */,
246252
DF33DA6528E4941100F7B88B /* ContentView.swift */,
253+
DF240E1E2971E996009F38CD /* MockSubscriberSDK.swift */,
247254
DF33DA6628E4941400F7B88B /* Assets.xcassets */,
248255
);
249256
path = Shared;
@@ -703,6 +710,7 @@
703710
files = (
704711
DF33DA8E28E4941400F7B88B /* ContentView.swift in Sources */,
705712
DF33DA8C28E4941400F7B88B /* AppQualityDevAppApp.swift in Sources */,
713+
DF240E1F2971E996009F38CD /* MockSubscriberSDK.swift in Sources */,
706714
);
707715
runOnlyForDeploymentPostprocessing = 0;
708716
};
@@ -712,6 +720,7 @@
712720
files = (
713721
DF33DA8F28E4941400F7B88B /* ContentView.swift in Sources */,
714722
DF33DA8D28E4941400F7B88B /* AppQualityDevAppApp.swift in Sources */,
723+
DF240E232971E996009F38CD /* MockSubscriberSDK.swift in Sources */,
715724
);
716725
runOnlyForDeploymentPostprocessing = 0;
717726
};
@@ -721,6 +730,7 @@
721730
files = (
722731
DF8AEF2A295CA3F40013BF14 /* ContentView.swift in Sources */,
723732
DF8AEF2B295CA3F40013BF14 /* AppQualityDevAppApp.swift in Sources */,
733+
DF240E202971E996009F38CD /* MockSubscriberSDK.swift in Sources */,
724734
);
725735
runOnlyForDeploymentPostprocessing = 0;
726736
};
@@ -730,6 +740,7 @@
730740
files = (
731741
DF9759AB295CE10700EF01BA /* ContentView.swift in Sources */,
732742
DF9759AC295CE10700EF01BA /* AppQualityDevAppApp.swift in Sources */,
743+
DF240E222971E996009F38CD /* MockSubscriberSDK.swift in Sources */,
733744
);
734745
runOnlyForDeploymentPostprocessing = 0;
735746
};
@@ -739,6 +750,7 @@
739750
files = (
740751
DF9ABFF8295CD14F00EFFEB7 /* ContentView.swift in Sources */,
741752
DF9ABFF9295CD14F00EFFEB7 /* AppQualityDevAppApp.swift in Sources */,
753+
DF240E212971E996009F38CD /* MockSubscriberSDK.swift in Sources */,
742754
);
743755
runOnlyForDeploymentPostprocessing = 0;
744756
};

FirebaseSessions/Tests/TestApp/Shared/AppQualityDevAppApp.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@
1515

1616
import SwiftUI
1717
import FirebaseCore
18+
import FirebaseSessions
1819

1920
@main
20-
struct AppQualityDevAppApp: App {
21-
init() {
21+
class AppQualityDevAppApp: App {
22+
required init() {
23+
// In other Product SDKs, this is called via `+ load`, but
24+
// we're faking that here because Swift doesn't have `+ load`
25+
MockSubscriberSDK.addDependency()
26+
2227
FirebaseApp.configure()
2328
}
2429

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//
2+
// Copyright 2022 Google LLC
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
import Foundation
17+
import FirebaseSessions
18+
19+
// Avoids exposing internal FirebaseCore APIs to Swift users.
20+
@_implementationOnly import FirebaseCoreExtension
21+
22+
@objc(FIRMockSubscriberSDKProtocol)
23+
protocol MockSubscriberSDKProtocol {
24+
func emptyProtocol()
25+
}
26+
27+
///
28+
/// The MockSubscriberSDK pretends to be Firebase Performance because without
29+
/// any Integrated Product SDKs installed, the Sessions SDK will not send events. This
30+
/// is because data collection is handled only in product SDKs.
31+
///
32+
@objc(FIRMockSubscriberSDK) final class MockSubscriberSDK: NSObject, Library, SessionsSubscriber,
33+
MockSubscriberSDKProtocol {
34+
static func addDependency() {
35+
FirebaseApp.registerInternalLibrary(
36+
MockSubscriberSDK.self,
37+
withName: "mock-firebase-sessions-subscriber-sdk"
38+
)
39+
SessionsDependencies.addDependency(name: SessionsSubscriberName.Performance)
40+
}
41+
42+
init(app: FirebaseApp) {
43+
super.init()
44+
45+
let sessions = ComponentType<SessionsProvider>.instance(for: SessionsProvider.self,
46+
in: app.container)
47+
sessions.register(subscriber: self)
48+
}
49+
50+
// MARK: - Library Conformance
51+
52+
static func componentsToRegister() -> [Component] {
53+
let sessionsDependency = Dependency(with: SessionsProvider.self, isRequired: false)
54+
return [Component(MockSubscriberSDKProtocol.self,
55+
instantiationTiming: .alwaysEager,
56+
dependencies: [sessionsDependency]) { container, isCacheable in
57+
// Sessions SDK only works for the default app
58+
guard let app = container.app, app.isDefaultApp else { return nil }
59+
isCacheable.pointee = true
60+
return self.init(app: app)
61+
}]
62+
}
63+
64+
// MARK: - SessionsSubscriber Conformance
65+
66+
func onSessionChanged(_ session: FirebaseSessions.SessionDetails) {}
67+
68+
var isDataCollectionEnabled: Bool {
69+
return true
70+
}
71+
72+
var sessionsSubscriberName: FirebaseSessions.SessionsSubscriberName {
73+
return FirebaseSessions.SessionsSubscriberName.Performance
74+
}
75+
76+
// MARK: - MockSubscriberSDKProtocol Conformance
77+
78+
func emptyProtocol() {}
79+
}

0 commit comments

Comments
 (0)