Skip to content

Commit

Permalink
Add FXIOS-9021 New trigger for number of app launches (#19978) (#19998)
Browse files Browse the repository at this point in the history
(cherry picked from commit 5ff50ef)

Co-authored-by: Cyndi Chin <cgc95@cornell.edu>
  • Loading branch information
mergify[bot] and cyndichin committed Apr 29, 2024
1 parent 60b4151 commit 3031609
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
Expand Up @@ -13,6 +13,7 @@ class GleanPlumbContextProvider {
case isDefaultBrowser = "is_default_browser"
case isInactiveNewUser = "is_inactive_new_user"
case allowedTipsNotifications = "allowed_tips_notifications"
case numberOfAppLaunches = "number_of_app_launches"
}

struct Constant {
Expand All @@ -21,6 +22,11 @@ class GleanPlumbContextProvider {
}

var userDefaults: UserDefaultsInterface = UserDefaults.standard
private var profile: Profile

init(profile: Profile = AppContainer.shared.resolve()) {
self.profile = profile
}

private var todaysDate: String {
let dateFormatter = DateFormatter()
Expand All @@ -32,6 +38,10 @@ class GleanPlumbContextProvider {
return userDefaults.bool(forKey: RatingPromptManager.UserDefaultsKey.keyIsBrowserDefault.rawValue)
}

private var numberOfAppLaunches: Int32 {
return profile.prefs.intForKey(PrefsKeys.Session.Count) ?? 0
}

var isInactiveNewUser: Bool {
// existing users don't have firstAppUse set
guard let firstAppUse = userDefaults.object(forKey: PrefsKeys.Session.FirstAppUse) as? UInt64,
Expand Down Expand Up @@ -62,6 +72,7 @@ class GleanPlumbContextProvider {
return [ContextKey.todayDate.rawValue: todaysDate,
ContextKey.isDefaultBrowser.rawValue: isDefaultBrowser,
ContextKey.isInactiveNewUser.rawValue: isInactiveNewUser,
ContextKey.numberOfAppLaunches.rawValue: numberOfAppLaunches,
ContextKey.allowedTipsNotifications.rawValue: allowedTipsNotifications]
}
}
Expand Up @@ -17,6 +17,7 @@ class ContextMenuHelperTests: XCTestCase {
profile = MockProfile()

LegacyFeatureFlagsManager.shared.initializeDeveloperFeatures(with: profile)
DependencyHelperMock().bootstrapDependencies()

Glean.shared.resetGlean(clearStores: true)
Glean.shared.enableTestingMode()
Expand All @@ -25,6 +26,7 @@ class ContextMenuHelperTests: XCTestCase {
override func tearDown() {
super.tearDown()
profile = nil
AppContainer.shared.reset()
}

func testHistoryHighlightsTelemetry() {
Expand Down
Expand Up @@ -10,12 +10,14 @@ import XCTest
class GleanPlumbContextProviderTests: XCTestCase {
private var userDefaults: UserDefaultsInterface!
private var contextProvider: GleanPlumbContextProvider!
private var profile: MockProfile!

override func setUp() {
super.setUp()
DependencyHelperMock().bootstrapDependencies()
userDefaults = MockUserDefaults()
contextProvider = GleanPlumbContextProvider()
profile = MockProfile()
contextProvider = GleanPlumbContextProvider(profile: profile)
contextProvider.userDefaults = userDefaults
}

Expand All @@ -25,6 +27,20 @@ class GleanPlumbContextProviderTests: XCTestCase {
contextProvider = nil
}

func testNumberOfLaunches_withFirstLaunch() {
profile.prefs.setInt(1, forKey: PrefsKeys.Session.Count)
let context = contextProvider.createAdditionalDeviceContext()
let numberOfAppLaunches = context["number_of_app_launches"] as? Int32
XCTAssertEqual(numberOfAppLaunches, 1)
}

func testNumberOfLaunches_withSecondLaunch() {
profile.prefs.setInt(2, forKey: PrefsKeys.Session.Count)
let context = contextProvider.createAdditionalDeviceContext()
let numberOfAppLaunches = context["number_of_app_launches"] as? Int32
XCTAssertEqual(numberOfAppLaunches, 2)
}

func testIsInactiveNewUser_noFirstAppUse() {
userDefaults.set(Date.now(), forKey: PrefsKeys.Session.Last)
XCTAssertFalse(contextProvider.isInactiveNewUser)
Expand Down
Expand Up @@ -12,6 +12,16 @@ import Shared
@testable import Client

final class NimbusMessagingMessageTests: XCTestCase {
override func setUp() {
super.setUp()
DependencyHelperMock().bootstrapDependencies()
}

override func tearDown() {
super.tearDown()
AppContainer.shared.reset()
}

lazy var feature = {
FxNimbus.shared.initialize(with: { nil })
return FxNimbusMessaging.shared.features.messaging.value()
Expand Down
Expand Up @@ -12,6 +12,16 @@ import Shared
@testable import Client

final class NimbusMessagingTriggerTests: XCTestCase {
override func setUp() {
super.setUp()
DependencyHelperMock().bootstrapDependencies()
}

override func tearDown() {
super.tearDown()
AppContainer.shared.reset()
}

lazy var feature: Messaging = {
FxNimbus.shared.initialize(with: { nil })
return FxNimbusMessaging.shared.features.messaging.value()
Expand Down

1 comment on commit 3031609

@firefoxci-taskcluster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

InterpreterError at template.tasks[0].extra[0].treeherder[1].symbol: unknown context value cron

Please sign in to comment.