Skip to content

Commit

Permalink
Add test for changing subfeature state to disabled during rollout
Browse files Browse the repository at this point in the history
  • Loading branch information
dus7 committed Feb 2, 2024
1 parent 04c0f94 commit 68d9715
Showing 1 changed file with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,73 @@ class AppPrivacyConfigurationTests: XCTestCase {
XCTAssertEqual(config.stateFor(AutofillSubfeature.accessCredentialManagement), .disabled(.disabledInConfig))
}

func testWhenCheckingSubfeatureStateWithRolloutsAndSubfeatureDisabledWhenPreviouslyInRollout_SubfeatureShouldBeDisabled() {
let mockEmbeddedData = MockEmbeddedDataProvider(data: exampleEnabledSubfeatureWithRollout, etag: "test")
let manager = PrivacyConfigurationManager(fetchedETag: nil,
fetchedData: nil,
embeddedDataProvider: mockEmbeddedData,
localProtection: MockDomainsProtectionStore(),
internalUserDecider: DefaultInternalUserDecider())

let config = manager.privacyConfig

clearRolloutData(feature: "autofill", subFeature: "credentialsSaving")
XCTAssertTrue(config.isSubfeatureEnabled(AutofillSubfeature.credentialsSaving), "Subfeature should be enabled with 100% rollout")
XCTAssertEqual(config.stateFor(AutofillSubfeature.credentialsSaving), .enabled)

// Update remote config
manager.reload(etag: "foo", data: exampleDisabledSubfeatureWithRollout)

let configAfterUpdate = manager.privacyConfig

XCTAssertFalse(configAfterUpdate.isSubfeatureEnabled(AutofillSubfeature.credentialsSaving), "Subfeature should be disabled")
XCTAssertEqual(configAfterUpdate.stateFor(AutofillSubfeature.credentialsSaving), .disabled(.disabledInConfig))
}

let exampleEnabledSubfeatureWithRollout =
"""
{
"features": {
"autofill": {
"state": "enabled",
"exceptions": [],
"features": {
"credentialsSaving": {
"state": "enabled",
"rollout": {
"steps": [{
"percent": 100
}]
}
}
}
}
}
}
""".data(using: .utf8)!

let exampleDisabledSubfeatureWithRollout =
"""
{
"features": {
"autofill": {
"state": "enabled",
"exceptions": [],
"features": {
"credentialsSaving": {
"state": "disabled",
"rollout": {
"steps": [{
"percent": 100
}]
}
}
}
}
},
}
""".data(using: .utf8)!

func exampleTrackerAllowlistConfig(with state: String) -> Data {
return
"""
Expand Down

0 comments on commit 68d9715

Please sign in to comment.