|
3 | 3 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
4 | 4 |
|
5 | 5 | using System.Collections.Generic; |
| 6 | +using System.Net; |
6 | 7 | using System.Text; |
7 | 8 | using System.Threading; |
8 | 9 | using System.Threading.Tasks; |
9 | 10 | using CefSharp.Example; |
10 | 11 | using CefSharp.Example.Handlers; |
11 | 12 | using CefSharp.Internals; |
12 | 13 | using CefSharp.OffScreen; |
| 14 | +using CefSharp.Web; |
13 | 15 | using Xunit; |
14 | 16 | using Xunit.Abstractions; |
15 | 17 |
|
@@ -372,6 +374,43 @@ public async Task CanExecuteJavascriptInMainFrameAfterNavigatingToDifferentOrigi |
372 | 374 | } |
373 | 375 | } |
374 | 376 |
|
| 377 | + [Theory] |
| 378 | + [InlineData("http://httpbin.org/post")] |
| 379 | + public async Task CanLoadRequestWithPostData(string url) |
| 380 | + { |
| 381 | + const string data = "Testing123"; |
| 382 | + //To use LoadRequest we must first load a web page |
| 383 | + using (var browser = new ChromiumWebBrowser(new HtmlString("Testing"))) |
| 384 | + { |
| 385 | + await browser.LoadPageAsync(); |
| 386 | + |
| 387 | + var request = new Request(); |
| 388 | + request.Url = "http://httpbin.org/post"; |
| 389 | + request.Method = "POST"; |
| 390 | + var postData = new PostData(); |
| 391 | + postData.AddElement(new PostDataElement |
| 392 | + { |
| 393 | + Bytes = Encoding.UTF8.GetBytes(data) |
| 394 | + }); |
| 395 | + |
| 396 | + request.PostData = postData; |
| 397 | + |
| 398 | + await browser.LoadRequestAsync(request); |
| 399 | + |
| 400 | + var mainFrame = browser.GetMainFrame(); |
| 401 | + Assert.Equal(url, mainFrame.Url); |
| 402 | + |
| 403 | + var navEntry = await browser.GetVisibleNavigationEntryAsync(); |
| 404 | + |
| 405 | + Assert.Equal((int)HttpStatusCode.OK, navEntry.HttpStatusCode); |
| 406 | + Assert.True(navEntry.HasPostData); |
| 407 | + |
| 408 | + var source = await browser.GetTextAsync(); |
| 409 | + |
| 410 | + Assert.Contains(data, source); |
| 411 | + } |
| 412 | + } |
| 413 | + |
375 | 414 | [SkipIfRunOnAppVeyorFact] |
376 | 415 | public async Task CanLoadHttpWebsiteUsingProxy() |
377 | 416 | { |
|
0 commit comments