From e094ffaad61254e4af7d71494477aacdcec8982f Mon Sep 17 00:00:00 2001 From: Chris Ventura <45495992+nrcventura@users.noreply.github.com> Date: Tue, 1 Aug 2023 16:26:53 -0700 Subject: [PATCH] test: Add more browser agent injection tests. --- .../NewRelicConfigModifier.cs | 6 +++ .../BrowserAgentAutoInjection.cs | 46 +++++++++++++++++-- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/tests/Agent/IntegrationTests/IntegrationTestHelpers/NewRelicConfigModifier.cs b/tests/Agent/IntegrationTests/IntegrationTestHelpers/NewRelicConfigModifier.cs index 84f8a79319..ba4d425ba9 100644 --- a/tests/Agent/IntegrationTests/IntegrationTestHelpers/NewRelicConfigModifier.cs +++ b/tests/Agent/IntegrationTests/IntegrationTestHelpers/NewRelicConfigModifier.cs @@ -133,6 +133,12 @@ public void BrowserMonitoringEnableAttributes(bool shouldEnableAttributes) new[] { "configuration", "browserMonitoring", "attributes" }, "enabled", stringValue); } + public void BrowserMonitoringLoader(string loaderType) + { + CommonUtils.ModifyOrCreateXmlAttributeInNewRelicConfig(_configFilePath, + new[] { "configuration", "browserMonitoring" }, "loader", loaderType); + } + public void PutForDataSend() { CommonUtils.ModifyOrCreateXmlAttributeInNewRelicConfig(_configFilePath, new[] { "configuration", "dataTransmission" }, diff --git a/tests/Agent/IntegrationTests/IntegrationTests/AgentFeatures/BrowserAgentAutoInjection.cs b/tests/Agent/IntegrationTests/IntegrationTests/AgentFeatures/BrowserAgentAutoInjection.cs index 5de13368ad..28af48a694 100644 --- a/tests/Agent/IntegrationTests/IntegrationTests/AgentFeatures/BrowserAgentAutoInjection.cs +++ b/tests/Agent/IntegrationTests/IntegrationTests/AgentFeatures/BrowserAgentAutoInjection.cs @@ -2,20 +2,20 @@ // SPDX-License-Identifier: Apache-2.0 using NewRelic.Agent.IntegrationTestHelpers; +using NewRelic.Agent.IntegrationTests.RemoteServiceFixtures; using NewRelic.Testing.Assertions; using Xunit; using Xunit.Abstractions; namespace NewRelic.Agent.IntegrationTests.AgentFeatures { - [NetFrameworkTest] - public class BrowserAgentAutoInjection : NewRelicIntegrationTest + public abstract class BrowserAgentAutoInjectionBase : NewRelicIntegrationTest { private readonly RemoteServiceFixtures.BasicMvcApplicationTestFixture _fixture; private string _htmlContent; - public BrowserAgentAutoInjection(RemoteServiceFixtures.BasicMvcApplicationTestFixture fixture, ITestOutputHelper output) + protected BrowserAgentAutoInjectionBase(RemoteServiceFixtures.BasicMvcApplicationTestFixture fixture, ITestOutputHelper output, string loaderType) : base(fixture) { _fixture = fixture; @@ -30,6 +30,10 @@ public BrowserAgentAutoInjection(RemoteServiceFixtures.BasicMvcApplicationTestFi configModifier.AutoInstrumentBrowserMonitoring(true); configModifier.BrowserMonitoringEnableAttributes(true); + if (!string.IsNullOrEmpty(loaderType)) + { + configModifier.BrowserMonitoringLoader(loaderType); + } }, exerciseApplication: () => { @@ -55,4 +59,40 @@ public void Test() Assert.Equal(jsAgentFromConnectResponse, jsAgentFromHtmlContent); } } + + [NetFrameworkTest] + public class BrowserAgentAutoInjectionDefault : BrowserAgentAutoInjectionBase + { + public BrowserAgentAutoInjectionDefault(BasicMvcApplicationTestFixture fixture, ITestOutputHelper output) + : base(fixture, output, null /* use default loader */) + { + } + } + + [NetFrameworkTest] + public class BrowserAgentAutoInjectionRum : BrowserAgentAutoInjectionBase + { + public BrowserAgentAutoInjectionRum(BasicMvcApplicationTestFixture fixture, ITestOutputHelper output) + : base(fixture, output, "rum") + { + } + } + + [NetFrameworkTest] + public class BrowserAgentAutoInjectionFull : BrowserAgentAutoInjectionBase + { + public BrowserAgentAutoInjectionFull(BasicMvcApplicationTestFixture fixture, ITestOutputHelper output) + : base(fixture, output, "full") + { + } + } + + [NetFrameworkTest] + public class BrowserAgentAutoInjectionSpa : BrowserAgentAutoInjectionBase + { + public BrowserAgentAutoInjectionSpa(BasicMvcApplicationTestFixture fixture, ITestOutputHelper output) + : base(fixture, output, "spa") + { + } + } }