mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
* Add GPOWrapper headers and C++/WinRT library * Check GPO before starting utilities * Show message on GPO having disabled preview panes. * Don't generate thumbnails if GPO disabled * Fix FancyZonesEditor unable to recognize GPOWrapper * Move settings view models to the settings project * Use GPO to block enabling utilities in Settings * Hide context menu entries when gpo disables utilities * Apply gpo policies when enabling PowerToys on runner * Add version and metadata to dll * Add GPOWrapper to the installer * Fix MSBuild errors on WPF apps by using Projection * Signing * Add gpo files and publish them * Add GPO policies to the bug report tool * Add some documentation for using GPO * Mention support to actual lowest supported version of Windows * Move PowerToys to the root of administrative templates tree * Save policies on Software\Policies\PowerToys * Support both machine and user scopes * Fix documentation to reference computer and user scopes * Mention incompatibility with outlook in gpo * Set a better folder structure for gpo assets * Move PDF Handler warning to the description * Update doc/gpo/README.md Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Add actual minimum version of PowerToys to gpo files * Fix identation * Remove GPOWrapper Readme * Add Active Directory instructions to doc Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
254 lines
10 KiB
C#
254 lines
10 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using Microsoft.PowerToys.Settings.UI.Library;
|
|
using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
|
|
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
|
|
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using Moq;
|
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
|
|
|
namespace ViewModelTests
|
|
{
|
|
[TestClass]
|
|
public class General
|
|
{
|
|
public const string GeneralSettingsFileName = "Test\\GeneralSettings";
|
|
|
|
private Mock<ISettingsUtils> mockGeneralSettingsUtils;
|
|
|
|
[TestInitialize]
|
|
public void SetUpStubSettingUtils()
|
|
{
|
|
mockGeneralSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils<GeneralSettings>();
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow("v0.18.2")]
|
|
[DataRow("v0.19.2")]
|
|
[DataRow("v0.20.1")]
|
|
[DataRow("v0.21.1")]
|
|
[DataRow("v0.22.0")]
|
|
public void OriginalFilesModificationTest(string version)
|
|
{
|
|
var settingPathMock = new Mock<ISettingsPath>();
|
|
var fileMock = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
|
|
|
var mockGeneralSettingsUtils = new SettingsUtils(fileMock.Object, settingPathMock.Object);
|
|
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettingsOrDefault<GeneralSettings>();
|
|
|
|
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
|
|
|
// Initialise View Model with test Config files
|
|
// Arrange
|
|
Func<string, int> sendMockIPCConfigMSG = msg => 0;
|
|
Func<string, int> sendRestartAdminIPCMessage = msg => 0;
|
|
Func<string, int> sendCheckForUpdatesIPCMessage = msg => 0;
|
|
var viewModel = new GeneralViewModel(
|
|
settingsRepository: generalSettingsRepository,
|
|
runAsAdminText: "GeneralSettings_RunningAsAdminText",
|
|
runAsUserText: "GeneralSettings_RunningAsUserText",
|
|
isElevated: false,
|
|
isAdmin: false,
|
|
updateTheme: UpdateUIThemeMethod,
|
|
ipcMSGCallBackFunc: sendMockIPCConfigMSG,
|
|
ipcMSGRestartAsAdminMSGCallBackFunc: sendRestartAdminIPCMessage,
|
|
ipcMSGCheckForUpdatesCallBackFunc: sendCheckForUpdatesIPCMessage,
|
|
configFileSubfolder: string.Empty);
|
|
|
|
// Verify that the old settings persisted
|
|
Assert.AreEqual(originalGeneralSettings.AutoDownloadUpdates, viewModel.AutoDownloadUpdates);
|
|
Assert.AreEqual(originalGeneralSettings.PowertoysVersion, viewModel.PowerToysVersion);
|
|
Assert.AreEqual(originalGeneralSettings.RunElevated, viewModel.RunElevated);
|
|
Assert.AreEqual(originalGeneralSettings.Startup, viewModel.Startup);
|
|
|
|
// Verify that the stub file was used
|
|
var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings<T>)
|
|
BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(fileMock, expectedCallCount);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void IsElevatedShouldUpdateRunasAdminStatusAttrsWhenSuccessful()
|
|
{
|
|
// Arrange
|
|
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
|
|
Func<string, int> sendRestartAdminIPCMessage = msg => { return 0; };
|
|
Func<string, int> sendCheckForUpdatesIPCMessage = msg => { return 0; };
|
|
GeneralViewModel viewModel = new GeneralViewModel(
|
|
settingsRepository: SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
|
|
"GeneralSettings_RunningAsAdminText",
|
|
"GeneralSettings_RunningAsUserText",
|
|
false,
|
|
false,
|
|
UpdateUIThemeMethod,
|
|
sendMockIPCConfigMSG,
|
|
sendRestartAdminIPCMessage,
|
|
sendCheckForUpdatesIPCMessage,
|
|
GeneralSettingsFileName);
|
|
|
|
Assert.AreEqual(viewModel.RunningAsUserDefaultText, viewModel.RunningAsText);
|
|
Assert.IsFalse(viewModel.IsElevated);
|
|
|
|
// Act
|
|
viewModel.IsElevated = true;
|
|
|
|
// Assert
|
|
Assert.AreEqual(viewModel.RunningAsAdminDefaultText, viewModel.RunningAsText);
|
|
Assert.IsTrue(viewModel.IsElevated);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void StartupShouldEnableRunOnStartUpWhenSuccessful()
|
|
{
|
|
// Assert
|
|
Func<string, int> sendMockIPCConfigMSG = msg =>
|
|
{
|
|
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
|
|
Assert.IsTrue(snd.GeneralSettings.Startup);
|
|
return 0;
|
|
};
|
|
|
|
// Arrange
|
|
Func<string, int> sendRestartAdminIPCMessage = msg => { return 0; };
|
|
Func<string, int> sendCheckForUpdatesIPCMessage = msg => { return 0; };
|
|
GeneralViewModel viewModel = new GeneralViewModel(
|
|
settingsRepository: SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
|
|
"GeneralSettings_RunningAsAdminText",
|
|
"GeneralSettings_RunningAsUserText",
|
|
false,
|
|
false,
|
|
UpdateUIThemeMethod,
|
|
sendMockIPCConfigMSG,
|
|
sendRestartAdminIPCMessage,
|
|
sendCheckForUpdatesIPCMessage,
|
|
GeneralSettingsFileName);
|
|
Assert.IsFalse(viewModel.Startup);
|
|
|
|
// act
|
|
viewModel.Startup = true;
|
|
}
|
|
|
|
[TestMethod]
|
|
public void RunElevatedShouldEnableAlwaysRunElevatedWhenSuccessful()
|
|
{
|
|
// Assert
|
|
Func<string, int> sendMockIPCConfigMSG = msg =>
|
|
{
|
|
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
|
|
Assert.IsTrue(snd.GeneralSettings.RunElevated);
|
|
return 0;
|
|
};
|
|
|
|
Func<string, int> sendRestartAdminIPCMessage = msg => { return 0; };
|
|
Func<string, int> sendCheckForUpdatesIPCMessage = msg => { return 0; };
|
|
|
|
// Arrange
|
|
GeneralViewModel viewModel = new GeneralViewModel(
|
|
settingsRepository: SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
|
|
"GeneralSettings_RunningAsAdminText",
|
|
"GeneralSettings_RunningAsUserText",
|
|
false,
|
|
false,
|
|
UpdateUIThemeMethod,
|
|
sendMockIPCConfigMSG,
|
|
sendRestartAdminIPCMessage,
|
|
sendCheckForUpdatesIPCMessage,
|
|
GeneralSettingsFileName);
|
|
|
|
Assert.IsFalse(viewModel.RunElevated);
|
|
|
|
// act
|
|
viewModel.RunElevated = true;
|
|
}
|
|
|
|
[TestMethod]
|
|
public void IsLightThemeRadioButtonCheckedShouldThemeToLightWhenSuccessful()
|
|
{
|
|
// Arrange
|
|
GeneralViewModel viewModel = null;
|
|
|
|
// Assert
|
|
Func<string, int> sendMockIPCConfigMSG = msg =>
|
|
{
|
|
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
|
|
Assert.AreEqual("light", snd.GeneralSettings.Theme);
|
|
return 0;
|
|
};
|
|
|
|
Func<string, int> sendRestartAdminIPCMessage = msg => { return 0; };
|
|
Func<string, int> sendCheckForUpdatesIPCMessage = msg => { return 0; };
|
|
viewModel = new GeneralViewModel(
|
|
settingsRepository: SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
|
|
"GeneralSettings_RunningAsAdminText",
|
|
"GeneralSettings_RunningAsUserText",
|
|
false,
|
|
false,
|
|
UpdateUIThemeMethod,
|
|
sendMockIPCConfigMSG,
|
|
sendRestartAdminIPCMessage,
|
|
sendCheckForUpdatesIPCMessage,
|
|
GeneralSettingsFileName);
|
|
Assert.AreNotEqual(1, viewModel.ThemeIndex);
|
|
|
|
// act
|
|
viewModel.ThemeIndex = 1;
|
|
}
|
|
|
|
[TestMethod]
|
|
public void IsDarkThemeRadioButtonCheckedShouldThemeToDarkWhenSuccessful()
|
|
{
|
|
// Arrange
|
|
// Assert
|
|
Func<string, int> sendMockIPCConfigMSG = msg =>
|
|
{
|
|
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
|
|
Assert.AreEqual("dark", snd.GeneralSettings.Theme);
|
|
return 0;
|
|
};
|
|
|
|
Func<string, int> sendRestartAdminIPCMessage = msg => { return 0; };
|
|
Func<string, int> sendCheckForUpdatesIPCMessage = msg => { return 0; };
|
|
GeneralViewModel viewModel = new GeneralViewModel(
|
|
settingsRepository: SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
|
|
"GeneralSettings_RunningAsAdminText",
|
|
"GeneralSettings_RunningAsUserText",
|
|
false,
|
|
false,
|
|
UpdateUIThemeMethod,
|
|
sendMockIPCConfigMSG,
|
|
sendRestartAdminIPCMessage,
|
|
sendCheckForUpdatesIPCMessage,
|
|
GeneralSettingsFileName);
|
|
Assert.AreNotEqual(0, viewModel.ThemeIndex);
|
|
|
|
// act
|
|
viewModel.ThemeIndex = 0;
|
|
}
|
|
|
|
[TestMethod]
|
|
public void AllModulesAreEnabledByDefault()
|
|
{
|
|
// arrange
|
|
EnabledModules modules = new EnabledModules();
|
|
|
|
// Assert
|
|
Assert.IsTrue(modules.FancyZones);
|
|
Assert.IsTrue(modules.ImageResizer);
|
|
Assert.IsTrue(modules.FileExplorerPreview);
|
|
Assert.IsTrue(modules.ShortcutGuide);
|
|
Assert.IsTrue(modules.PowerRename);
|
|
Assert.IsTrue(modules.KeyboardManager);
|
|
Assert.IsTrue(modules.PowerLauncher);
|
|
Assert.IsTrue(modules.ColorPicker);
|
|
}
|
|
|
|
public static int UpdateUIThemeMethod(string themeName)
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
}
|