Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public final class AutofillPixelReporter {
private let passwordManager: PasswordManager?
private var installDate: Date?
private var autofillEnabled: Bool
private var deviceAuthEnabled: Bool

private var autofillSearchDauDate: Date? { userDefaults.object(forKey: Keys.autofillSearchDauDateKey) as? Date ?? .distantPast }
private var autofillFillDate: Date? { userDefaults.object(forKey: Keys.autofillFillDateKey) as? Date ?? .distantPast }
Expand All @@ -75,6 +76,7 @@ public final class AutofillPixelReporter {
public init(standardUserDefaults: UserDefaults,
appGroupUserDefaults: UserDefaults?,
autofillEnabled: Bool,
deviceAuthEnabled: Bool,
eventMapping: EventMapping<AutofillPixelEvent>,
secureVault: (any AutofillSecureVault)? = nil,
reporter: SecureVaultReporting? = nil,
Expand All @@ -83,6 +85,7 @@ public final class AutofillPixelReporter {
) {
self.userDefaults = appGroupUserDefaults ?? standardUserDefaults
self.autofillEnabled = autofillEnabled
self.deviceAuthEnabled = deviceAuthEnabled
self.eventMapping = eventMapping
self.secureVault = secureVault
self.reporter = reporter
Expand Down Expand Up @@ -188,7 +191,7 @@ public final class AutofillPixelReporter {
eventMapping.fire(.autofillEnabledUser)
}

if let accountsCountBucket = getAccountsCountBucket() {
if deviceAuthEnabled, let accountsCountBucket = getAccountsCountBucket() {
eventMapping.fire(autofillEnabled ? .autofillToggledOn : .autofillToggledOff,
parameters: [AutofillPixelEvent.Parameter.countBucket: accountsCountBucket])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@
XCTAssertEqual(MockEventMapping.loginsParam, AutofillPixelReporter.BucketName.none.rawValue)
}

func testWhenFirstSearchDauAndDeviceAuthDisabledAndFillDateIsNotTodayAndAccountsCountIsZeroThenNoEventIsFired() throws {
let autofillPixelReporter = createAutofillPixelReporter(deviceAuthEnabled: false)
autofillPixelReporter.resetStoreDefaults()
createAccountsInVault(count: 0)

NotificationCenter.default.post(name: .searchDAU, object: nil)

XCTAssertEqual(MockEventMapping.events.count, 0)
}

func testWhenFirstSearchDauAndAutofillDisabledAndFillDateIsNotTodayAndAndAccountsCountIsTenThenThenOneEventIsFired() throws {
let autofillPixelReporter = createAutofillPixelReporter(autofillEnabled: false)
autofillPixelReporter.resetStoreDefaults()
Expand Down Expand Up @@ -521,7 +531,7 @@
standardDefaults.set(testDate, forKey: AutofillPixelReporter.Keys.autofillFillDateKey)
standardDefaults.set(true, forKey: AutofillPixelReporter.Keys.autofillOnboardedUserKey)

let autofillPixelReporter = createAutofillPixelReporter(appGroupUserDefaults: appGroupDefaults)

Check warning on line 534 in Tests/BrowserServicesKitTests/Autofill/AutofillPixelReporterTests.swift

View workflow job for this annotation

GitHub Actions / Run unit tests (iOS)

initialization of immutable value 'autofillPixelReporter' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 534 in Tests/BrowserServicesKitTests/Autofill/AutofillPixelReporterTests.swift

View workflow job for this annotation

GitHub Actions / Run unit tests (iOS)

initialization of immutable value 'autofillPixelReporter' was never used; consider replacing with assignment to '_' or removing it

XCTAssertEqual(appGroupDefaults.object(forKey: AutofillPixelReporter.Keys.autofillSearchDauDateKey) as? Date, testDate)
XCTAssertEqual(appGroupDefaults.bool(forKey: AutofillPixelReporter.Keys.autofillOnboardedUserKey), true)
Expand All @@ -530,7 +540,7 @@
}

func testWhenMigrationRequiredAndNoDataExistsThenMigratedKeyIsTrue() {
let autofillPixelReporter = createAutofillPixelReporter(appGroupUserDefaults: appGroupDefaults)

Check warning on line 543 in Tests/BrowserServicesKitTests/Autofill/AutofillPixelReporterTests.swift

View workflow job for this annotation

GitHub Actions / Run unit tests (iOS)

initialization of immutable value 'autofillPixelReporter' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 543 in Tests/BrowserServicesKitTests/Autofill/AutofillPixelReporterTests.swift

View workflow job for this annotation

GitHub Actions / Run unit tests (iOS)

initialization of immutable value 'autofillPixelReporter' was never used; consider replacing with assignment to '_' or removing it

XCTAssertTrue(appGroupDefaults.bool(forKey: AutofillPixelReporter.Keys.autofillDauMigratedKey))
XCTAssertNil(appGroupDefaults.object(forKey: AutofillPixelReporter.Keys.autofillSearchDauDateKey))
Expand All @@ -543,7 +553,7 @@
standardDefaults.set(testDate, forKey: AutofillPixelReporter.Keys.autofillSearchDauDateKey)
appGroupDefaults.set(true, forKey: AutofillPixelReporter.Keys.autofillDauMigratedKey)

let autofillPixelReporter = createAutofillPixelReporter(appGroupUserDefaults: appGroupDefaults)

Check warning on line 556 in Tests/BrowserServicesKitTests/Autofill/AutofillPixelReporterTests.swift

View workflow job for this annotation

GitHub Actions / Run unit tests (iOS)

initialization of immutable value 'autofillPixelReporter' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 556 in Tests/BrowserServicesKitTests/Autofill/AutofillPixelReporterTests.swift

View workflow job for this annotation

GitHub Actions / Run unit tests (iOS)

initialization of immutable value 'autofillPixelReporter' was never used; consider replacing with assignment to '_' or removing it

XCTAssertNotNil(standardDefaults.object(forKey: AutofillPixelReporter.Keys.autofillSearchDauDateKey))
XCTAssertNil(appGroupDefaults.object(forKey: AutofillPixelReporter.Keys.autofillSearchDauDateKey))
Expand All @@ -553,16 +563,17 @@
let testDate = Date()
standardDefaults.set(testDate, forKey: AutofillPixelReporter.Keys.autofillSearchDauDateKey)

let autofillPixelReporter = createAutofillPixelReporter(appGroupUserDefaults: nil)

Check warning on line 566 in Tests/BrowserServicesKitTests/Autofill/AutofillPixelReporterTests.swift

View workflow job for this annotation

GitHub Actions / Run unit tests (iOS)

initialization of immutable value 'autofillPixelReporter' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 566 in Tests/BrowserServicesKitTests/Autofill/AutofillPixelReporterTests.swift

View workflow job for this annotation

GitHub Actions / Run unit tests (iOS)

initialization of immutable value 'autofillPixelReporter' was never used; consider replacing with assignment to '_' or removing it

XCTAssertNotNil(standardDefaults.object(forKey: AutofillPixelReporter.Keys.autofillSearchDauDateKey))
XCTAssertNil(appGroupDefaults.object(forKey: AutofillPixelReporter.Keys.autofillDauMigratedKey))
}

private func createAutofillPixelReporter(appGroupUserDefaults: UserDefaults? = nil, installDate: Date? = Date(), autofillEnabled: Bool = true) -> AutofillPixelReporter {
private func createAutofillPixelReporter(appGroupUserDefaults: UserDefaults? = nil, installDate: Date? = Date(), autofillEnabled: Bool = true, deviceAuthEnabled: Bool = true) -> AutofillPixelReporter {
return AutofillPixelReporter(standardUserDefaults: standardDefaults,
appGroupUserDefaults: appGroupUserDefaults,
autofillEnabled: autofillEnabled,
deviceAuthEnabled: deviceAuthEnabled,
eventMapping: eventMapping,
secureVault: vault,
installDate: installDate)
Expand Down
Loading