Skip to content

Commit

Permalink
Adds DBP pixel tests (#1764)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1205746905965973/f

## Stack PR:

Feel free to look at other PRs in the stack to understand the full set
of changes, but this can be tested individually.

- #1764 <-- You're here
   - #1766

## Description

This PR adds a DBP unit testing target, and some basic pixel tests to
ensure pixel's aren't broken in the transition to offer some level of
PixelKit support.
  • Loading branch information
diegoreymendez authored Oct 18, 2023
1 parent 29e2a19 commit 0f7e8ac
Show file tree
Hide file tree
Showing 17 changed files with 541 additions and 109 deletions.
25 changes: 25 additions & 0 deletions Configuration/Tests/DBPUnitTests.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright © 2022 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include "TestsTargetsBase.xcconfig"

ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES

FEATURE_FLAGS = FEEDBACK NETWORK_PROTECTION

INFOPLIST_FILE = DuckDuckGoDBPTests/Info.plist
PRODUCT_BUNDLE_IDENTIFIER = com.duckduckgo.macos.browser.DuckDuckGoDBPTests

TEST_HOST=$(BUILT_PRODUCTS_DIR)/DuckDuckGoDBP.app/Contents/MacOS/DuckDuckGoDBP
138 changes: 137 additions & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7B96D0CE2ADFDA7E007E02C8"
BuildableName = "DuckDuckGoDBPTests.xctest"
BlueprintName = "DuckDuckGoDBPTests"
ReferencedContainer = "container:DuckDuckGo.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7B96D0CE2ADFDA7E007E02C8"
BuildableName = "DuckDuckGoDBPTests.xctest"
BlueprintName = "DuckDuckGoDBPTests"
ReferencedContainer = "container:DuckDuckGo.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
46 changes: 16 additions & 30 deletions DuckDuckGo/DBP/DBPHomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,40 +128,26 @@ extension DBPHomeViewController: DataBrokerProtectionInviteDialogsViewModelDeleg

public class DataBrokerProtectionPixelsHandler: EventMapping<DataBrokerProtectionPixels> {

// swiftlint:disable:next cyclomatic_complexity
public init() {
super.init { event, _, _, _ in
switch event {
case .error(let error, _):
Pixel.fire(.debug(event: .dataBrokerProtectionError, error: error), withAdditionalParameters: event.params)
case .parentChildMatches:
Pixel.fire(.parentChildMatches, withAdditionalParameters: event.params)
case .optOutStart:
Pixel.fire(.optOutStart, withAdditionalParameters: event.params)
case .optOutEmailGenerate:
Pixel.fire(.optOutEmailGenerate, withAdditionalParameters: event.params)
case .optOutCaptchaParse:
Pixel.fire(.optOutCaptchaParse, withAdditionalParameters: event.params)
case .optOutCaptchaSend:
Pixel.fire(.optOutCaptchaSend, withAdditionalParameters: event.params)
case .optOutCaptchaSolve:
Pixel.fire(.optOutCaptchaSolve, withAdditionalParameters: event.params)
case .optOutSubmit:
Pixel.fire(.optOutSubmit, withAdditionalParameters: event.params)
case .optOutEmailReceive:
Pixel.fire(.optOutEmailReceive, withAdditionalParameters: event.params)
case .optOutEmailConfirm:
Pixel.fire(.optOutEmailConfirm, withAdditionalParameters: event.params)
case .optOutValidate:
Pixel.fire(.optOutValidate, withAdditionalParameters: event.params)
case .optOutFinish:
Pixel.fire(.optOutFinish, withAdditionalParameters: event.params)
case .optOutSubmitSuccess:
Pixel.fire(.optOutSubmitSuccess, withAdditionalParameters: event.params)
case .optOutSuccess:
Pixel.fire(.optOutSuccess, withAdditionalParameters: event.params)
case .optOutFailure:
Pixel.fire(.optOutFailure, withAdditionalParameters: event.params)
Pixel.fire(.debug(event: .pixelKitEvent(event), error: error))
case .parentChildMatches,
.optOutStart,
.optOutEmailGenerate,
.optOutCaptchaParse,
.optOutCaptchaSend,
.optOutCaptchaSolve,
.optOutSubmit,
.optOutEmailReceive,
.optOutEmailConfirm,
.optOutValidate,
.optOutFinish,
.optOutSubmitSuccess,
.optOutSuccess,
.optOutFailure:
Pixel.fire(.pixelKitEvent(event))
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions DuckDuckGo/Statistics/Pixel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ final class Pixel {
}
}

init(store: @escaping @autoclosure () -> PixelDataStore, requestSender: @escaping RequestSender) {
private let appVersion: String

init(appVersion: String = AppVersion.shared.versionNumber,
store: @escaping @autoclosure () -> PixelDataStore,
requestSender: @escaping RequestSender) {

self.appVersion = appVersion
self.store = store
self.sendRequest = requestSender
}
Expand Down Expand Up @@ -124,7 +130,7 @@ final class Pixel {
}

if includeAppVersionParameter {
newParams[PixelKit.Parameters.appVersion] = AppVersion.shared.versionNumber
newParams[PixelKit.Parameters.appVersion] = appVersion
}
#if DEBUG
newParams[PixelKit.Parameters.test] = PixelKit.Values.test
Expand Down
63 changes: 15 additions & 48 deletions DuckDuckGo/Statistics/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ import Foundation
import BrowserServicesKit
import Bookmarks
import Configuration
import PixelKit

extension Pixel {

indirect enum Event {
/// This is a convenience pixel that allows us to fire `PixelKitEvents` using our
/// regular `Pixel.fire()` calls. This is a convenience intermediate step to help ensure
/// nothing breaks in the migration towards `PixelKit`.
case pixelKitEvent(_ event: PixelKitEvent)

case crash

case brokenSiteReport
Expand Down Expand Up @@ -168,29 +174,12 @@ extension Pixel {
case setnewHomePage

case dailyPixel(Event, isFirst: Bool)
#if DBP
case parentChildMatches
// SLO and SLI Pixels: https://app.asana.com/0/1203581873609357/1205337273100857/f

// Stage Pixels
case optOutStart
case optOutEmailGenerate
case optOutCaptchaParse
case optOutCaptchaSend
case optOutCaptchaSolve
case optOutSubmit
case optOutEmailReceive
case optOutEmailConfirm
case optOutValidate
case optOutFinish

// Process Pixels
case optOutSubmitSuccess
case optOutSuccess
case optOutFailure
#endif

enum Debug {
/// This is a convenience pixel that allows us to fire `PixelKitEvents` using our
/// regular `Pixel.fire()` calls. This is a convenience intermediate step to help ensure
/// nothing breaks in the migration towards `PixelKit`.
case pixelKitEvent(_ event: PixelKitEvent)

case assertionFailure(message: String, file: StaticString, line: UInt)

Expand Down Expand Up @@ -335,10 +324,6 @@ extension Pixel {

case networkProtectionRemoteMessageFetchingFailed
case networkProtectionRemoteMessageStorageFailed

#if DBP
case dataBrokerProtectionError
#endif
}

}
Expand All @@ -348,6 +333,9 @@ extension Pixel.Event {

var name: String {
switch self {
case .pixelKitEvent(let event):
return event.name

case .crash:
return "m_mac_crash"

Expand Down Expand Up @@ -498,25 +486,6 @@ extension Pixel.Event {

case .dailyPixel(let pixel, isFirst: let isFirst):
return pixel.name + (isFirst ? "_d" : "_c")
#if DBP
case .parentChildMatches: return "dbp_macos_parent-child-broker-matches"
// Stage Pixels
case .optOutStart: return "dbp_macos_optout_stage_start"
case .optOutEmailGenerate: return "dbp_macos_optout_stage_email-generate"
case .optOutCaptchaParse: return "dbp_macos_optout_stage_captcha-parse"
case .optOutCaptchaSend: return "dbp_macos_optout_stage_captcha-send"
case .optOutCaptchaSolve: return "dbp_macos_optout_stage_captcha-solve"
case .optOutSubmit: return "dbp_macos_optout_stage_submit"
case .optOutEmailReceive: return "dbp_macos_optout_stage_email-receive"
case .optOutEmailConfirm: return "dbp_macos_optout_stage_email-confirm"
case .optOutValidate: return "dbp_macos_optout_stage_validate"
case .optOutFinish: return "dbp_macos_optout_stage_finish"

// Process Pixels
case .optOutSubmitSuccess: return "dbp_macos_optout_process_submit-success"
case .optOutSuccess: return "dbp_macos_optout_process_success"
case .optOutFailure: return "dbp_macos_optout_process_failure"
#endif
}
}
}
Expand All @@ -533,6 +502,8 @@ extension Pixel.Event.Debug {

var name: String {
switch self {
case .pixelKitEvent(let event):
return event.name

case .assertionFailure:
return "assertion_failure"
Expand Down Expand Up @@ -773,10 +744,6 @@ extension Pixel.Event.Debug {

case .networkProtectionRemoteMessageFetchingFailed: return "netp_remote_message_fetching_failed"
case .networkProtectionRemoteMessageStorageFailed: return "netp_remote_message_storage_failed"

#if DBP
case .dataBrokerProtectionError: return "data_broker_error"
#endif
}
}
}
20 changes: 3 additions & 17 deletions DuckDuckGo/Statistics/PixelParameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ extension Pixel.Event {

var parameters: [String: String]? {
switch self {
case .pixelKitEvent(let event):
return event.parameters

case .debug(event: let debugEvent, error: let error):

var params = error?.pixelParameters ?? [:]
Expand Down Expand Up @@ -105,23 +108,6 @@ extension Pixel.Event {
.disableHomeButton,
.setnewHomePage:
return nil
#if DBP
case .optOutStart,
.optOutEmailGenerate,
.optOutCaptchaParse,
.optOutCaptchaSend,
.optOutCaptchaSolve,
.optOutSubmit,
.optOutEmailReceive,
.optOutEmailConfirm,
.optOutValidate,
.optOutFinish,
.optOutSubmitSuccess,
.optOutSuccess,
.optOutFailure,
.parentChildMatches:
return nil
#endif
}
}

Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGoAgent/Info-AppStore.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
<string>$(NETP_APP_GROUP)</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.productivity</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
</dict>
</plist>
2 changes: 2 additions & 0 deletions DuckDuckGoAgent/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
<string>$(NETP_APP_GROUP)</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.productivity</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
</dict>
</plist>
Loading

0 comments on commit 0f7e8ac

Please sign in to comment.