-
-
Notifications
You must be signed in to change notification settings - Fork 223
Only register MauiSessionReplayMaskControlsOfTypeBinder when relevant #4445
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b8bd70c
Only detect custom session replay masks when necessary
jamescrosswell 8202c1d
Renamed MauiVisualElementEventsBinder to MauiCustomSessionReplayMaskB…
jamescrosswell af50236
Merge branch 'main' into maui-performance-4439
jamescrosswell 34474d3
Update CHANGELOG.md
jamescrosswell 871174a
Merge branch 'main' into maui-performance-4439
jamescrosswell 5700d1c
Merge branch 'main' into maui-performance-4439
jamescrosswell cc9a3c7
Update MauiCustomSessionReplayMaskBinder.cs
jamescrosswell 54cda92
Make custom masking opt in
jamescrosswell f19a466
Renamed binder to MauiSessionReplayMaskControlsOfTypeBinder
jamescrosswell 4bd60e6
Renamed MauiCustomSessionReplayMaskBinder to MauiSessionReplayMaskCon…
jamescrosswell dd4590b
Update SentryMauiAppBuilderExtensionsTests.cs
jamescrosswell e62e8ec
Update CHANGELOG.md
jamescrosswell 0538289
Merge branch 'main' into maui-performance-4439
jamescrosswell 439947d
Added MauiSessionReplayMaskControlsOfTypeBinder.IsEnabled
jamescrosswell 51351b6
Updated tests
jamescrosswell 7c0ecea
Update MauiEventsBinderTests.cs
jamescrosswell 0599c9c
Format code
getsentry-bot 4953592
Inject IOptions<T>
jamescrosswell 02cf175
Update CHANGELOG.md
jamescrosswell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
test/Sentry.Maui.Tests/MauiCustomSessionReplayMaskBinderTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using Sentry.Maui.Internal; | ||
using Sentry.Maui.Tests.Mocks; | ||
#if __ANDROID__ | ||
using View = Android.Views.View; | ||
#endif | ||
|
||
namespace Sentry.Maui.Tests; | ||
|
||
public class MauiSessionReplayMaskControlsOfTypeBinderTests | ||
{ | ||
private class Fixture | ||
{ | ||
public MauiSessionReplayMaskControlsOfTypeBinder ControlsOfTypeBinder { get; } | ||
|
||
public SentryMauiOptions Options { get; } = new(); | ||
|
||
public Fixture() | ||
{ | ||
Options.Debug = true; | ||
var logger = Substitute.For<IDiagnosticLogger>(); | ||
logger.IsEnabled(Arg.Any<SentryLevel>()).Returns(true); | ||
Options.DiagnosticLogger = logger; | ||
var options = Microsoft.Extensions.Options.Options.Create(Options); | ||
ControlsOfTypeBinder = new MauiSessionReplayMaskControlsOfTypeBinder(options); | ||
} | ||
} | ||
|
||
private readonly Fixture _fixture = new(); | ||
|
||
[Fact] | ||
public void OnElementLoaded_SenderIsNotVisualElement_LogsDebugAndReturns() | ||
{ | ||
// Arrange | ||
var element = new MockElement("element"); | ||
|
||
// Act | ||
_fixture.ControlsOfTypeBinder.OnElementLoaded(element, EventArgs.Empty); | ||
|
||
// Assert | ||
_fixture.Options.DiagnosticLogger.Received(1).LogDebug("OnElementLoaded: sender is not a VisualElement"); | ||
} | ||
|
||
[Fact] | ||
public void OnElementLoaded_HandlerIsNull_LogsDebugAndReturns() | ||
{ | ||
// Arrange | ||
var element = new MockVisualElement("element") | ||
{ | ||
Handler = null | ||
}; | ||
|
||
// Act | ||
_fixture.ControlsOfTypeBinder.OnElementLoaded(element, EventArgs.Empty); | ||
|
||
// Assert | ||
_fixture.Options.DiagnosticLogger.Received(1).LogDebug("OnElementLoaded: handler is null"); | ||
} | ||
|
||
#if __ANDROID__ | ||
[Theory] | ||
[InlineData(0.0, 1.0)] | ||
[InlineData(1.0, 0.0)] | ||
[InlineData(1.0, 1.0)] | ||
public void SessionReplayEnabled_IsEnabled( | ||
double sessionSampleRate, double onErrorSampleRate) | ||
{ | ||
// Arrange | ||
var options = new SentryMauiOptions { Dsn = ValidDsn }; | ||
// force custom masking to be enabled | ||
options.Native.ExperimentalOptions.SessionReplay.MaskControlsOfType<object>(); | ||
// One of the below has to be non-zero for session replay to be enabled | ||
options.Native.ExperimentalOptions.SessionReplay.SessionSampleRate = sessionSampleRate; | ||
options.Native.ExperimentalOptions.SessionReplay.OnErrorSampleRate = onErrorSampleRate; | ||
|
||
// Act | ||
var iOptions = Microsoft.Extensions.Options.Options.Create(options); | ||
var binder = new MauiSessionReplayMaskControlsOfTypeBinder(iOptions); | ||
|
||
// Assert | ||
binder.IsEnabled.Should().Be(true); | ||
} | ||
|
||
[Fact] | ||
public void SessionReplayDisabled_IsNotEnabled() | ||
{ | ||
// Arrange | ||
var options = new SentryMauiOptions { Dsn = ValidDsn }; | ||
// force custom masking to be enabled | ||
options.Native.ExperimentalOptions.SessionReplay.MaskControlsOfType<object>(); | ||
// No sessionSampleRate or onErrorSampleRate set... so should be disabled | ||
|
||
// Act | ||
var iOptions = Microsoft.Extensions.Options.Options.Create(options); | ||
var binder = new MauiSessionReplayMaskControlsOfTypeBinder(iOptions); | ||
|
||
// Assert | ||
binder.IsEnabled.Should().Be(false); | ||
} | ||
|
||
[Fact] | ||
public void UseSentry_NoMaskedControls_DoesNotRegisterMauiVisualElementEventsBinder() | ||
{ | ||
// Arrange | ||
var options = new SentryMauiOptions { Dsn = ValidDsn }; | ||
options.Native.ExperimentalOptions.SessionReplay.OnErrorSampleRate = 1.0; | ||
options.Native.ExperimentalOptions.SessionReplay.SessionSampleRate = 1.0; | ||
// Not really necessary, but just to be explicit | ||
options.Native.ExperimentalOptions.SessionReplay.MaskedControls.Clear(); | ||
|
||
// Act | ||
var iOptions = Microsoft.Extensions.Options.Options.Create(options); | ||
var binder = new MauiSessionReplayMaskControlsOfTypeBinder(iOptions); | ||
|
||
// Assert | ||
binder.IsEnabled.Should().Be(false); | ||
} | ||
#endif | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 0 additions & 59 deletions
59
test/Sentry.Maui.Tests/MauiVisualElementEventsBinderTests.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.