Skip to content

Commit 0d1b91a

Browse files
committed
Test - Add some basic tests for RequestContext.SetContentSetting/GetContentSetting
Issue #4991
1 parent 633893a commit 0d1b91a

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

CefSharp.Test/Framework/RequestContextTests.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
using System;
66
using System.IO;
7+
using System.Threading.Tasks;
8+
using CefSharp.Enums;
9+
using CefSharp.Example;
10+
using CefSharp.Internals;
711
using Xunit;
812

913
namespace CefSharp.Test.Framework
@@ -31,5 +35,55 @@ public void IsSharingWith()
3135

3236
Assert.True(ctx1.IsSharingWith(ctx2));
3337
}
38+
39+
[Fact]
40+
public void CanGetContentSetting()
41+
{
42+
var ctx = RequestContext.Configure()
43+
.WithCachePath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Tests\\TempCache1"))
44+
.Create();
45+
46+
var actual = ctx.GetContentSetting(CefExample.DefaultUrl, null, ContentSettingTypes.Autoplay);
47+
48+
Assert.Equal(ContentSettingValues.Default, actual);
49+
}
50+
51+
[Fact]
52+
public async Task CanSetContentSetting()
53+
{
54+
var ctx = RequestContext.Configure()
55+
.WithCachePath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Tests\\TempCache1"))
56+
.Create();
57+
58+
var actual = ContentSettingValues.Default;
59+
60+
await CefThread.ExecuteOnUiThread(() =>
61+
{
62+
ctx.SetContentSetting(CefExample.DefaultUrl, null, ContentSettingTypes.Autoplay, ContentSettingValues.Block);
63+
64+
actual = ctx.GetContentSetting(CefExample.DefaultUrl, null, ContentSettingTypes.Autoplay);
65+
});
66+
67+
Assert.Equal(ContentSettingValues.Block, actual);
68+
}
69+
70+
[Fact]
71+
public async Task CanSetWebsiteSetting()
72+
{
73+
var ctx = RequestContext.Configure()
74+
.WithCachePath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Tests\\TempCache1"))
75+
.Create();
76+
77+
object actual = ContentSettingValues.Default;
78+
79+
await CefThread.ExecuteOnUiThread(() =>
80+
{
81+
ctx.SetWebsiteSetting(CefExample.DefaultUrl, null, ContentSettingTypes.Popups, (int)ContentSettingValues.Allow);
82+
83+
actual = ctx.GetWebsiteSetting(CefExample.DefaultUrl, null, ContentSettingTypes.Popups);
84+
});
85+
86+
Assert.Equal(ContentSettingValues.Allow, (ContentSettingValues)actual);
87+
}
3488
}
3589
}

0 commit comments

Comments
 (0)