Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUMM-1324 Fix RUM views tracking issue for iOS 11 (and make tests green for 11.x and 12.x) #474

Merged
merged 3 commits into from
Apr 27, 2021
Merged
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 @@ -11,8 +11,8 @@ internal class TSConsentSettingViewController: UIViewController {

@IBOutlet weak var consentValueControl: UISegmentedControl!

override func viewDidLoad() {
super.viewDidLoad()
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

switch homeViewController.currentConsentValue {
case .granted: consentValueControl.selectedSegmentIndex = 0
Expand Down
5 changes: 4 additions & 1 deletion Sources/Datadog/Utils/UIKitExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ internal extension UIViewController {
}

internal extension Bundle {
var isUIKit: Bool { bundleURL.lastPathComponent == "UIKitCore.framework" }
var isUIKit: Bool {
return bundleURL.lastPathComponent == "UIKitCore.framework" // on iOS 12+
|| bundleURL.lastPathComponent == "UIKit.framework" // on iOS 11
}
}
20 changes: 11 additions & 9 deletions Tests/DatadogTests/Datadog/Core/FeatureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ class FeatureStorageTests: XCTestCase {
let currentConsent = consentProvider.currentValue
let nextConsent: TrackingConsent = .mockRandom(otherThan: currentConsent)

let stringValue = "current consent: \(currentConsent), next consent: \(nextConsent)"
storage.writer.write(value: stringValue)
// We write array because prior to iOS 13 the top-level element passed to JSON encoder must be array or object
let data = ["current consent: \(currentConsent), next consent: \(nextConsent)"]
storage.writer.write(value: data)

consentProvider.changeConsent(to: nextConsent)
}
Expand All @@ -46,10 +47,10 @@ class FeatureStorageTests: XCTestCase {

let expectedAuthorizedValues = [
// Data collected with `.granted` consent is allowed no matter of the next consent
"\"current consent: \(TrackingConsent.granted), next consent: \(TrackingConsent.pending)\"",
"\"current consent: \(TrackingConsent.granted), next consent: \(TrackingConsent.notGranted)\"",
"[\"current consent: \(TrackingConsent.granted), next consent: \(TrackingConsent.pending)\"]",
"[\"current consent: \(TrackingConsent.granted), next consent: \(TrackingConsent.notGranted)\"]",
// Data collected with `.pending` consent is allowed only if the next consent was `.granted`
"\"current consent: \(TrackingConsent.pending), next consent: \(TrackingConsent.granted)\"",
"[\"current consent: \(TrackingConsent.pending), next consent: \(TrackingConsent.granted)\"]",
]

XCTAssertEqual(
Expand All @@ -71,8 +72,9 @@ class FeatureStorageTests: XCTestCase {
// swiftlint:disable opening_brace
callConcurrently(
closures: [
{ storage.writer.write(value: "regular write") },
{ storage.arbitraryAuthorizedWriter.write(value: "arbitrary write") }
// We write arrays because prior to iOS 13 the top-level element passed to JSON encoder must be array or object
{ storage.writer.write(value: ["regular write"]) },
{ storage.arbitraryAuthorizedWriter.write(value: ["arbitrary write"]) }
],
iterations: 25
)
Expand All @@ -81,8 +83,8 @@ class FeatureStorageTests: XCTestCase {
// Then
let dataWritten = readAllAuthorizedDataWritten(to: storage, limit: 50)
.map { $0.utf8String }
XCTAssertEqual(dataWritten.filter { $0 == "\"regular write\"" }.count, 25)
XCTAssertEqual(dataWritten.filter { $0 == "\"arbitrary write\"" }.count, 25)
XCTAssertEqual(dataWritten.filter { $0 == "[\"regular write\"]" }.count, 25)
XCTAssertEqual(dataWritten.filter { $0 == "[\"arbitrary write\"]" }.count, 25)
}

// MARK: - Helpers
Expand Down