Skip to content

Commit 316d8cf

Browse files
nvborisenkodiemol
andauthored
[dotnet] Fix error when we send non-base64 data for fetch command (#12431)
* Fix error when we send non-base64 data for fetch command * Remove unnecessary playground * Return back v114 in test * Fire events asynchronously to avoid handlers which produce new pending task * Use the latest cdp v115 in tests --------- Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
1 parent 25a5189 commit 316d8cf

File tree

12 files changed

+164
-162
lines changed

12 files changed

+164
-162
lines changed

dotnet/src/webdriver/DevTools/DevToolsSession.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,10 @@ private void ProcessIncomingMessage(string message)
582582
var eventData = messageObject["params"];
583583

584584
LogTrace("Recieved Event {0}: {1}", method, eventData.ToString());
585-
OnDevToolsEventReceived(new DevToolsEventReceivedEventArgs(methodParts[0], methodParts[1], eventData));
585+
586+
// fire and forget
587+
Task.Run(() => OnDevToolsEventReceived(new DevToolsEventReceivedEventArgs(methodParts[0], methodParts[1], eventData)));
588+
586589
return;
587590
}
588591

dotnet/src/webdriver/DevTools/v113/V113Network.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public override async Task ContinueRequest(HttpRequestData requestData)
142142

143143
if (!string.IsNullOrEmpty(requestData.PostData))
144144
{
145-
commandSettings.PostData = requestData.PostData;
145+
commandSettings.PostData = Convert.ToBase64String(Encoding.UTF8.GetBytes(requestData.PostData));
146146
}
147147

148148
await fetch.ContinueRequest(commandSettings);

dotnet/src/webdriver/DevTools/v114/V114Network.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public override async Task ContinueRequest(HttpRequestData requestData)
142142

143143
if (!string.IsNullOrEmpty(requestData.PostData))
144144
{
145-
commandSettings.PostData = requestData.PostData;
145+
commandSettings.PostData = Convert.ToBase64String(Encoding.UTF8.GetBytes(requestData.PostData));
146146
}
147147

148148
await fetch.ContinueRequest(commandSettings);

dotnet/src/webdriver/DevTools/v115/V115Network.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public override async Task ContinueRequest(HttpRequestData requestData)
142142

143143
if (!string.IsNullOrEmpty(requestData.PostData))
144144
{
145-
commandSettings.PostData = requestData.PostData;
145+
commandSettings.PostData = Convert.ToBase64String(Encoding.UTF8.GetBytes(requestData.PostData));
146146
}
147147

148148
await fetch.ContinueRequest(commandSettings);
@@ -245,13 +245,16 @@ public override async Task AddResponseBody(HttpResponseData responseData)
245245
if (responseData.StatusCode < 300 || responseData.StatusCode > 399)
246246
{
247247
var bodyResponse = await fetch.GetResponseBody(new Fetch.GetResponseBodyCommandSettings() { RequestId = responseData.RequestId });
248-
if (bodyResponse.Base64Encoded)
248+
if (bodyResponse != null)
249249
{
250-
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
251-
}
252-
else
253-
{
254-
responseData.Body = bodyResponse.Body;
250+
if (bodyResponse.Base64Encoded)
251+
{
252+
responseData.Body = Encoding.UTF8.GetString(Convert.FromBase64String(bodyResponse.Body));
253+
}
254+
else
255+
{
256+
responseData.Body = bodyResponse.Body;
257+
}
255258
}
256259
}
257260
}

dotnet/src/webdriver/DevTools/v85/V85Network.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public override async Task ContinueRequest(HttpRequestData requestData)
142142

143143
if (!string.IsNullOrEmpty(requestData.PostData))
144144
{
145-
commandSettings.PostData = requestData.PostData;
145+
commandSettings.PostData = Convert.ToBase64String(Encoding.UTF8.GetBytes(requestData.PostData));
146146
}
147147

148148
await fetch.ContinueRequest(commandSettings);

dotnet/test/common/DevTools/DevToolsConsoleTest.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
52
using System.Threading;
63
using System.Threading.Tasks;
74
using NUnit.Framework;
85
using OpenQA.Selenium.Environment;
96

107
namespace OpenQA.Selenium.DevTools
118
{
9+
using CurrentCdpVersion = V115;
10+
1211
[TestFixture]
1312
public class DevToolsConsoleTest : DevToolsTestFixture
1413
{
@@ -18,11 +17,11 @@ public class DevToolsConsoleTest : DevToolsTestFixture
1817
[IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")]
1918
public async Task VerifyMessageAdded()
2019
{
21-
var domains = session.GetVersionSpecificDomains<V114.DevToolsSessionDomains>();
20+
var domains = session.GetVersionSpecificDomains<CurrentCdpVersion.DevToolsSessionDomains>();
2221
string consoleMessage = "Hello Selenium";
2322

2423
ManualResetEventSlim sync = new ManualResetEventSlim(false);
25-
EventHandler<V114.Console.MessageAddedEventArgs> messageAddedHandler = (sender, e) =>
24+
EventHandler<CurrentCdpVersion.Console.MessageAddedEventArgs> messageAddedHandler = (sender, e) =>
2625
{
2726
Assert.That(e.Message.Text, Is.EqualTo(consoleMessage));
2827
sync.Set();

dotnet/test/common/DevTools/DevToolsLogTest.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
52
using System.Threading;
63
using System.Threading.Tasks;
74
using NUnit.Framework;
85
using OpenQA.Selenium.Environment;
96

107
namespace OpenQA.Selenium.DevTools
118
{
9+
using CurrentCdpVersion = V115;
10+
1211
[TestFixture]
1312
public class DevToolsLogTest : DevToolsTestFixture
1413
{
@@ -19,12 +18,12 @@ public class DevToolsLogTest : DevToolsTestFixture
1918
[IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")]
2019
public async Task VerifyEntryAddedAndClearLog()
2120
{
22-
var domains = session.GetVersionSpecificDomains<V114.DevToolsSessionDomains>();
21+
var domains = session.GetVersionSpecificDomains<CurrentCdpVersion.DevToolsSessionDomains>();
2322
ManualResetEventSlim sync = new ManualResetEventSlim(false);
24-
EventHandler<V114.Log.EntryAddedEventArgs> entryAddedHandler = (sender, e) =>
23+
EventHandler<CurrentCdpVersion.Log.EntryAddedEventArgs> entryAddedHandler = (sender, e) =>
2524
{
2625
Assert.That(e.Entry.Text.Contains("404"));
27-
Assert.That(e.Entry.Level == V114.Log.LogEntryLevelValues.Error);
26+
Assert.That(e.Entry.Level == CurrentCdpVersion.Log.LogEntryLevelValues.Error);
2827
sync.Set();
2928
};
3029

0 commit comments

Comments
 (0)