mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-04 19:25:01 +00:00
2b4a8cb18e
- Add an UnWrap method to the interfaces (should be hidden from IntelliSense) - For .Net 4.5.2 projects they're not a decorator class which an inner instance of the CefSharp.Core.Runtime Type - For Net Core we have a ref assembly which allows us to reference the CefSharp.Core.Runtime without issues We can potentially remove the ref assembly now and forgo any direct reference.
131 lines
4.3 KiB
C#
131 lines
4.3 KiB
C#
// Copyright © 2017 The CefSharp Authors. All rights reserved.
|
|
//
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
|
|
|
using System.Threading.Tasks;
|
|
using CefSharp.WinForms;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace CefSharp.Test.WinForms
|
|
{
|
|
//NOTE: All Test classes must be part of this collection as it manages the Cef Initialize/Shutdown lifecycle
|
|
[Collection(CefSharpFixtureCollection.Key)]
|
|
public class WinFormsBrowserBasicFacts
|
|
{
|
|
private readonly ITestOutputHelper output;
|
|
private readonly CefSharpFixture fixture;
|
|
|
|
public WinFormsBrowserBasicFacts(ITestOutputHelper output, CefSharpFixture fixture)
|
|
{
|
|
this.fixture = fixture;
|
|
this.output = output;
|
|
}
|
|
|
|
[WinFormsFact]
|
|
public async Task CanLoadGoogle()
|
|
{
|
|
using (var browser = new ChromiumWebBrowser("www.google.com"))
|
|
{
|
|
browser.Size = new System.Drawing.Size(1024, 768);
|
|
browser.CreateControl();
|
|
|
|
await browser.LoadPageAsync();
|
|
|
|
var mainFrame = browser.GetMainFrame();
|
|
Assert.True(mainFrame.IsValid);
|
|
Assert.Contains("www.google", mainFrame.Url);
|
|
|
|
output.WriteLine("Url {0}", mainFrame.Url);
|
|
}
|
|
}
|
|
|
|
[WinFormsFact]
|
|
public async Task CanSetBrowserSettingsDisableImageLoadingViaObjectFactory()
|
|
{
|
|
using (var browser = new ChromiumWebBrowser("www.google.com"))
|
|
{
|
|
var settings = Core.ObjectFactory.CreateBrowserSettings(true);
|
|
settings.ImageLoading = CefState.Disabled;
|
|
browser.BrowserSettings = settings;
|
|
|
|
browser.Size = new System.Drawing.Size(1024, 768);
|
|
browser.CreateControl();
|
|
|
|
await browser.LoadPageAsync();
|
|
|
|
var mainFrame = browser.GetMainFrame();
|
|
Assert.True(mainFrame.IsValid);
|
|
Assert.Contains("www.google", mainFrame.Url);
|
|
|
|
output.WriteLine("Url {0}", mainFrame.Url);
|
|
}
|
|
}
|
|
|
|
[WinFormsFact]
|
|
public async Task CanSetBrowserSettingsDisableImageLoading()
|
|
{
|
|
using (var browser = new ChromiumWebBrowser("www.google.com"))
|
|
{
|
|
browser.BrowserSettings = new BrowserSettings(true)
|
|
{
|
|
ImageLoading = CefState.Disabled
|
|
};
|
|
|
|
browser.Size = new System.Drawing.Size(1024, 768);
|
|
browser.CreateControl();
|
|
|
|
await browser.LoadPageAsync();
|
|
|
|
var mainFrame = browser.GetMainFrame();
|
|
Assert.True(mainFrame.IsValid);
|
|
Assert.Contains("www.google", mainFrame.Url);
|
|
|
|
output.WriteLine("Url {0}", mainFrame.Url);
|
|
}
|
|
}
|
|
|
|
[WinFormsFact]
|
|
public async Task CanSetRequestContextViaRequestContextBuilder()
|
|
{
|
|
using (var browser = new ChromiumWebBrowser("www.google.com"))
|
|
{
|
|
var settings = Core.ObjectFactory.CreateBrowserSettings(true);
|
|
settings.ImageLoading = CefState.Disabled;
|
|
browser.RequestContext = RequestContext.Configure().Create();
|
|
|
|
browser.Size = new System.Drawing.Size(1024, 768);
|
|
browser.CreateControl();
|
|
|
|
await browser.LoadPageAsync();
|
|
|
|
var mainFrame = browser.GetMainFrame();
|
|
Assert.True(mainFrame.IsValid);
|
|
Assert.Contains("www.google", mainFrame.Url);
|
|
|
|
output.WriteLine("Url {0}", mainFrame.Url);
|
|
}
|
|
}
|
|
|
|
[WinFormsFact]
|
|
public async Task CanSetRequestContext()
|
|
{
|
|
using (var browser = new ChromiumWebBrowser("www.google.com"))
|
|
{
|
|
browser.RequestContext = new RequestContext();
|
|
|
|
browser.Size = new System.Drawing.Size(1024, 768);
|
|
browser.CreateControl();
|
|
|
|
await browser.LoadPageAsync();
|
|
|
|
var mainFrame = browser.GetMainFrame();
|
|
Assert.True(mainFrame.IsValid);
|
|
Assert.Contains("www.google", mainFrame.Url);
|
|
|
|
output.WriteLine("Url {0}", mainFrame.Url);
|
|
}
|
|
}
|
|
}
|
|
}
|