Fall back to WebBrowser controls when running as admin
The Edge WebView does not at the time of this writing (28. march 2020) support running in an application with elevated permissions. This commit adds a test to `WebViewControlHost.IsSupported` which checks if the application is running as an administrator so that `WebViewCompatible` will fall back to using the legacy WebBrowser controls. The tests will unfortunately only work when running the test suite as administrator, and that will make all the other tests fail. The test will therefore be marked as inconclusive instead of failling when the test suite is running as a non elevated user so that we won't always have at least one breaking test when we run the test suite.
This commit is contained in:
Родитель
5a2a7a58f9
Коммит
d27ee834a6
|
@ -0,0 +1,37 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.Toolkit.Win32.UI.Controls.Test.WebView.Shared;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Should;
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace Microsoft.Toolkit.Win32.UI.Controls.Test.WinForms.WebView.FunctionalTests.WebViewCompatible
|
||||
{
|
||||
[TestClass]
|
||||
public class WebViewCompatibleTests: ContextSpecification
|
||||
{
|
||||
Forms.UI.Controls.WebViewCompatible WebView;
|
||||
|
||||
protected override void Given()
|
||||
{
|
||||
WebView = new Forms.UI.Controls.WebViewCompatible();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WebViewCompatibleShouldBeLegacyIfRunningAsAdministrator()
|
||||
{
|
||||
var identity = WindowsIdentity.GetCurrent();
|
||||
var principal = new WindowsPrincipal(identity);
|
||||
if(principal.IsInRole(WindowsBuiltInRole.Administrator))
|
||||
{
|
||||
WebView.IsLegacy.ShouldBeTrue();
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Inconclusive("This test needs to be run as administrator");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Security;
|
||||
using System.Security.Principal;
|
||||
using Microsoft.Toolkit.Win32.UI.Controls.Interop.Win32;
|
||||
using Windows.Foundation.Metadata;
|
||||
using Windows.Security.EnterpriseData;
|
||||
|
@ -58,6 +59,8 @@ namespace Microsoft.Toolkit.Win32.UI.Controls.Interop
|
|||
|
||||
internal static bool IsWindows10 { get; } = IsWindowsNt && IsSince(WindowsVersions.Win10);
|
||||
|
||||
internal static bool IsRunningAsAdministrator { get; } = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current OS is Windows 10 April 2018 Update (Redstone 4) or greater
|
||||
/// </summary>
|
||||
|
|
|
@ -120,7 +120,8 @@ namespace Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT
|
|||
|
||||
internal static bool IsSupported => OSVersionHelper.IsWindows10April2018OrGreater
|
||||
&& OSVersionHelper.IsWorkstation
|
||||
&& OSVersionHelper.EdgeExists;
|
||||
&& OSVersionHelper.EdgeExists
|
||||
&& !OSVersionHelper.IsRunningAsAdministrator;
|
||||
|
||||
internal bool CanGoBack
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче