mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 09:46:54 +02:00
This pull request refactors the LightSwitch module to introduce a new shared static library, `LightSwitchLib`, which centralizes theme management logic and enables code sharing between the service and module interface. The changes move theme-related code from the service and module interface into this new library, update project references, and clean up now-redundant files and includes. **LightSwitchLib introduction and code deduplication:** - Added a new static library project, `LightSwitchLib`, containing all theme management logic (`SetSystemTheme`, `SetAppsTheme`, `GetCurrentSystemTheme`, `GetCurrentAppsTheme`, `IsNightLightEnabled`) and related files (`ThemeHelper.cpp`, `ThemeHelper.h`, `pch.h`, `pch.cpp`). This code was previously duplicated in both the service and module interface. (`src/modules/LightSwitch/LightSwitchLib/LightSwitchLib.vcxproj` [[1]](diffhunk://#diff-c38e95060ad294c9ed5c2bb769616bb52032a4330af7e268ad63d81a99dc1cadR1-R123) `LightSwitchLib.vcxproj.filters` [[2]](diffhunk://#diff-fcfc49f1628c274cd9a40aca385e03a1937f9e42958298f36155ad16a267ba9aR1-R33) `ThemeHelper.cpp` [[3]](diffhunk://#diff-f5ab83c022406172501172ee88e21294c7aba2a87fb30334d7c4d4fc9d736a56L1-R3) `ThemeHelper.h` [[4]](diffhunk://#diff-6609a7fc7abc61d4d0029f0fb605a9f4732511642af6e12851e86c234108169aR1-R10) `pch.h` [[5]](diffhunk://#diff-57e4d6ddad1d356a24555bce4d6cbb0d6a93386515254abf95573324454c94c2R1-R5) `pch.cpp` [[6]](diffhunk://#diff-87fbf215a559e7833ec06ff32aa7f8109fdf86d92b360fe44302fc16f1784d52R1) - Updated the solution file and relevant project files to add and reference `LightSwitchLib` from both `LightSwitchService` and `LightSwitchModuleInterface`, ensuring both components use the shared implementation. (`PowerToys.slnx` [[1]](diffhunk://#diff-40c552fef4118125c3ccd6b156db518acec74b11150b193b31f18a2cc17a531eR668) `LightSwitchService.vcxproj` [[2]](diffhunk://#diff-51f54bd015aa96b38ddf4e96134ea542fac4b648566a23c2c86fe91a2b5a6bdaR58) [[3]](diffhunk://#diff-51f54bd015aa96b38ddf4e96134ea542fac4b648566a23c2c86fe91a2b5a6bdaR113-R115) `LightSwitchModuleInterface.vcxproj` [[4]](diffhunk://#diff-72e859ee44b3f0087018e55708e850fb5040c5b8f72449d1cac30e8efb28e2c2R205-R207) [[5]](diffhunk://#diff-72e859ee44b3f0087018e55708e850fb5040c5b8f72449d1cac30e8efb28e2c2L169-R179) **Cleanup and removal of redundant code:** - Removed old theme management code and headers from `LightSwitchService` and `LightSwitchModuleInterface` now that logic resides in `LightSwitchLib`. (`ThemeHelper.cpp` [[1]](diffhunk://#diff-3e2766504c1cf989390508c613b2177cd5de14fb9de46df3b416f95f955338bfL1-L106) `ThemeHelper.h` [[2]](diffhunk://#diff-0e8540cace398ec3eebca416ca38d81262b689eca76a004584e686a605b7a242L1-L5) `LightSwitchService.vcxproj` [[3]](diffhunk://#diff-51f54bd015aa96b38ddf4e96134ea542fac4b648566a23c2c86fe91a2b5a6bdaL81) [[4]](diffhunk://#diff-51f54bd015aa96b38ddf4e96134ea542fac4b648566a23c2c86fe91a2b5a6bdaL96) `LightSwitchModuleInterface.vcxproj` [[5]](diffhunk://#diff-72e859ee44b3f0087018e55708e850fb5040c5b8f72449d1cac30e8efb28e2c2L190) - Removed duplicated registry path constants from `SettingsConstants.h`, as they are now defined in the shared header. (`SettingsConstants.h` [src/modules/LightSwitch/LightSwitchService/SettingsConstants.hL15-L17](diffhunk://#diff-e74db005ffb8b881a08c4dae1c1ead9dc732928a69cafb4c9e0bae8b86d4e24aL15-L17)) **Module interface improvements:** - Added `ExportedFunctions.cpp` to the module interface, exposing theme management functions as exports and using the shared library implementation. (`ExportedFunctions.cpp` [[1]](diffhunk://#diff-48acf3b77a8b6ac6fd1129afe1a677b34447ce39454e86ea04f1a1181a23b546R1-R22) `LightSwitchModuleInterface.vcxproj` [[2]](diffhunk://#diff-72e859ee44b3f0087018e55708e850fb5040c5b8f72449d1cac30e8efb28e2c2L169-R179) **Minor test and logging adjustments:** - Fixed a UI test to use the correct toggle name for the Hosts File Editor. (`HostsSettingTests.cs` [src/modules/Hosts/Hosts.UITests/HostsSettingTests.csL116-R116](diffhunk://#diff-3782109c99cd66a2c1b870a83d1f9d9807422479c89e03799b311ef5f13a2098L116-R116)) - Updated a log message to refer to `LightSwitchLib` instead of `LightSwitchService` for clarity. (`ThemeHelper.cpp` [src/modules/LightSwitch/LightSwitchLib/ThemeHelper.cppL66-R63](diffhunk://#diff-f5ab83c022406172501172ee88e21294c7aba2a87fb30334d7c4d4fc9d736a56L66-R63))
634 lines
28 KiB
C#
634 lines
28 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 System.Globalization;
|
|
using System.Threading.Tasks;
|
|
using System.Xml.Linq;
|
|
using Microsoft.PowerToys.UITest;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using Windows.Devices.Printers;
|
|
|
|
namespace MouseUtils.UITests
|
|
{
|
|
[TestClass]
|
|
public class FindMyMouseTests : UITestBase
|
|
{
|
|
/// <summary>
|
|
/// Test Warning Dialog at startup
|
|
/// <list type="bullet">
|
|
/// <item>
|
|
/// <description>Validating Warning-Dialog will be shown if 'Show a warning at startup' toggle is On.</description>
|
|
/// </item>
|
|
/// <item>
|
|
/// <description>Validating Warning-Dialog will NOT be shown if 'Show a warning at startup' toggle is Off.</description>
|
|
/// </item>
|
|
/// <item>
|
|
/// <description>Validating click 'Quit' button in Warning-Dialog, the Hosts File Editor window would be closed.</description>
|
|
/// </item>
|
|
/// <item>
|
|
/// <description>Validating click 'Accept' button in Warning-Dialog, the Hosts File Editor window would NOT be closed.</description>
|
|
/// </item>
|
|
/// </list>
|
|
/// </summary>
|
|
[TestMethod("MouseUtils.FindMyMouse.EnableFindMyMouse")]
|
|
[TestCategory("Mouse Utils #1")]
|
|
[TestCategory("Mouse Utils #2")]
|
|
[TestCategory("Mouse Utils #3")]
|
|
[TestCategory("Mouse Utils #4")]
|
|
public void TestEnableFindMyMouse()
|
|
{
|
|
LaunchFromSetting();
|
|
|
|
var settings = new FindMyMouseSettings();
|
|
settings.OverlayOpacity = "100";
|
|
settings.Radius = "50";
|
|
settings.InitialZoom = "1";
|
|
settings.AnimationDuration = "0";
|
|
settings.BackgroundColor = "000000";
|
|
settings.SpotlightColor = "FFFFFF";
|
|
|
|
var foundCustom = this.Find<Custom>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouse));
|
|
Assert.IsNotNull(foundCustom);
|
|
|
|
if (CheckAnimationEnable(ref foundCustom))
|
|
{
|
|
foundCustom = this.Find<Custom>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouse));
|
|
}
|
|
|
|
if (foundCustom != null)
|
|
{
|
|
foundCustom.Find<ToggleSwitch>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseToggle)).Toggle(true);
|
|
|
|
SetFindMyMouseActivationMethod(ref foundCustom, "Press Left Control twice");
|
|
Assert.IsNotNull(foundCustom, "Find My Mouse group not found.");
|
|
SetFindMyMouseAppearanceBehavior(ref foundCustom, ref settings);
|
|
|
|
var excludedApps = foundCustom.Find(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseExcludedApps));
|
|
if (excludedApps != null)
|
|
{
|
|
excludedApps.Click();
|
|
excludedApps.Click();
|
|
}
|
|
else
|
|
{
|
|
Assert.Fail("Activation method group not found.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Assert.Fail("Find My Mouse group not found.");
|
|
}
|
|
|
|
// [Test Case]Enable FindMyMouse. Then, without moving your mouse: Press Left Ctrl twice and verify the overlay appears.
|
|
VerifySpotlightSettings(ref settings);
|
|
|
|
// [Test Case]Enable FindMyMouse. Then, without moving your mouse: Press any other key and verify the overlay disappears.
|
|
Session.SendKeys(Key.A);
|
|
VerifySpotlightDisappears(ref settings);
|
|
|
|
// [Test Case]Enable FindMyMouse. Then, without moving your mouse: Press Left Ctrl twice and verify the overlay appears.
|
|
VerifySpotlightSettings(ref settings);
|
|
|
|
// [Test Case]Enable FindMyMouse. Then, without moving your mouse: Press a mouse button and verify the overlay disappears.
|
|
Task.Delay(1000).Wait();
|
|
|
|
Session.PerformMouseAction(MouseActionType.LeftClick, 500, 1000);
|
|
|
|
VerifySpotlightDisappears(ref settings);
|
|
}
|
|
|
|
[TestMethod("MouseUtils.FindMyMouse.FindMyMouseDifferentSettings")]
|
|
[TestCategory("Mouse Utils #10")]
|
|
[TestCategory("Mouse Utils #11")]
|
|
[TestCategory("Mouse Utils #12")]
|
|
public void TestFindMyMouseDifferentSettings()
|
|
{
|
|
LaunchFromSetting();
|
|
|
|
var settings = new FindMyMouseSettings();
|
|
settings.OverlayOpacity = "100";
|
|
settings.Radius = "80";
|
|
settings.InitialZoom = "1";
|
|
settings.AnimationDuration = "0";
|
|
settings.BackgroundColor = "FF0000";
|
|
settings.SpotlightColor = "0000FF";
|
|
|
|
var foundCustom = this.Find<Custom>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouse));
|
|
Assert.IsNotNull(foundCustom);
|
|
|
|
if (CheckAnimationEnable(ref foundCustom))
|
|
{
|
|
foundCustom = this.Find<Custom>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouse));
|
|
}
|
|
|
|
if (foundCustom != null)
|
|
{
|
|
foundCustom.Find<ToggleSwitch>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseToggle)).Toggle(true);
|
|
|
|
SetFindMyMouseActivationMethod(ref foundCustom, "Press Left Control twice");
|
|
Assert.IsNotNull(foundCustom, "Find My Mouse group not found.");
|
|
SetFindMyMouseAppearanceBehavior(ref foundCustom, ref settings);
|
|
|
|
var excludedApps = foundCustom.Find(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseExcludedApps));
|
|
if (excludedApps != null)
|
|
{
|
|
excludedApps.Click();
|
|
excludedApps.Click();
|
|
}
|
|
else
|
|
{
|
|
Assert.Fail("Excluded apps group not found.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Assert.Fail("Find My Mouse group not found.");
|
|
}
|
|
|
|
// [Test Case]Test the different settings and verify they apply, Background color
|
|
// [Test Case]Test the different settings and verify they apply, Spotlight color
|
|
// [Test Case]Test the different settings and verify they apply, Spotlight radius
|
|
VerifySpotlightSettings(ref settings);
|
|
|
|
Session.SendKeys(Key.A);
|
|
VerifySpotlightDisappears(ref settings);
|
|
}
|
|
|
|
[TestMethod("MouseUtils.FindMyMouse.DisableFindMyMouse")]
|
|
[TestCategory("Mouse Utils #5")]
|
|
[TestCategory("Mouse Utils #6")]
|
|
public void TestDisableFindMyMouse()
|
|
{
|
|
LaunchFromSetting();
|
|
|
|
var settings = new FindMyMouseSettings();
|
|
settings.OverlayOpacity = "100";
|
|
settings.Radius = "50";
|
|
settings.InitialZoom = "1";
|
|
settings.AnimationDuration = "0";
|
|
settings.BackgroundColor = "000000";
|
|
settings.SpotlightColor = "FFFFFF";
|
|
var foundCustom = this.Find<Custom>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouse));
|
|
|
|
Assert.IsNotNull(foundCustom);
|
|
|
|
if (CheckAnimationEnable(ref foundCustom))
|
|
{
|
|
foundCustom = this.Find<Custom>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouse));
|
|
}
|
|
|
|
if (foundCustom != null)
|
|
{
|
|
foundCustom.Find<ToggleSwitch>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseToggle)).Toggle(true);
|
|
|
|
foundCustom.Find<ToggleSwitch>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseToggle)).Toggle(false);
|
|
|
|
foundCustom.Find<ToggleSwitch>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseToggle)).Toggle(true);
|
|
SetFindMyMouseActivationMethod(ref foundCustom, "Press Left Control twice");
|
|
Assert.IsNotNull(foundCustom);
|
|
SetFindMyMouseAppearanceBehavior(ref foundCustom, ref settings);
|
|
|
|
var excludedApps = foundCustom.Find<Group>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseExcludedApps));
|
|
if (excludedApps != null)
|
|
{
|
|
excludedApps.Click();
|
|
excludedApps.Click();
|
|
}
|
|
else
|
|
{
|
|
Assert.Fail("Activation method group not found.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Assert.Fail("Find My Mouse group not found.");
|
|
}
|
|
|
|
// [Test Case]Enable FindMyMouse. Then, without moving your mouse: Press Left Ctrl twice and verify the overlay appears.
|
|
// VerifySpotlightSettings(ref settings);
|
|
ActivateSpotlight(ref settings);
|
|
VerifySpotlightAppears(ref settings);
|
|
|
|
// [Test Case] Disable FindMyMouse. Verify the overlay no longer appears when you press Left Ctrl twice
|
|
foundCustom.Find<ToggleSwitch>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseToggle)).Toggle(false);
|
|
Task.Delay(1000).Wait();
|
|
ActivateSpotlight(ref settings);
|
|
|
|
VerifySpotlightDisappears(ref settings);
|
|
|
|
// [Test Case] Press Left Ctrl twice and verify the overlay appears
|
|
foundCustom.Find<ToggleSwitch>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseToggle)).Toggle(true);
|
|
Task.Delay(2000).Wait();
|
|
ActivateSpotlight(ref settings);
|
|
VerifySpotlightAppears(ref settings);
|
|
|
|
Session.PerformMouseAction(MouseActionType.LeftClick);
|
|
}
|
|
|
|
[TestMethod("MouseUtils.FindMyMouse.DisableFindMyMouse3")]
|
|
[TestCategory("Mouse Utils #6")]
|
|
public void TestDisableFindMyMouse3()
|
|
{
|
|
LaunchFromSetting();
|
|
|
|
var settings = new FindMyMouseSettings();
|
|
settings.OverlayOpacity = "100";
|
|
settings.Radius = "50";
|
|
settings.InitialZoom = "1";
|
|
settings.AnimationDuration = "0";
|
|
settings.BackgroundColor = "000000";
|
|
settings.SpotlightColor = "FFFFFF";
|
|
var foundCustom = this.Find<Custom>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouse));
|
|
|
|
Assert.IsNotNull(foundCustom);
|
|
|
|
if (CheckAnimationEnable(ref foundCustom))
|
|
{
|
|
foundCustom = this.Find<Custom>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouse));
|
|
}
|
|
|
|
if (foundCustom != null)
|
|
{
|
|
foundCustom.Find<ToggleSwitch>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseToggle)).Toggle(true);
|
|
|
|
foundCustom.Find<ToggleSwitch>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseToggle)).Toggle(false);
|
|
|
|
foundCustom.Find<ToggleSwitch>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseToggle)).Toggle(true);
|
|
SetFindMyMouseActivationMethod(ref foundCustom, "Press Left Control twice");
|
|
Assert.IsNotNull(foundCustom);
|
|
SetFindMyMouseAppearanceBehavior(ref foundCustom, ref settings);
|
|
|
|
var excludedApps = foundCustom.Find(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseExcludedApps));
|
|
if (excludedApps != null)
|
|
{
|
|
excludedApps.Click();
|
|
excludedApps.Click();
|
|
}
|
|
else
|
|
{
|
|
Assert.Fail("Activation method group not found.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Assert.Fail("Find My Mouse group not found.");
|
|
}
|
|
|
|
// [Test Case]Enable FindMyMouse. Then, without moving your mouse: Press Left Ctrl twice and verify the overlay appears.
|
|
// VerifySpotlightSettings(ref settings);
|
|
ActivateSpotlight(ref settings);
|
|
VerifySpotlightAppears(ref settings);
|
|
|
|
// [Test Case] Disable FindMyMouse. Verify the overlay no longer appears when you press Left Ctrl twice
|
|
foundCustom.Find<ToggleSwitch>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseToggle)).Toggle(false);
|
|
Task.Delay(1000).Wait();
|
|
ActivateSpotlight(ref settings);
|
|
|
|
VerifySpotlightDisappears(ref settings);
|
|
|
|
// [Test Case] Press Left Ctrl twice and verify the overlay appears
|
|
foundCustom.Find<ToggleSwitch>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseToggle)).Toggle(true);
|
|
Task.Delay(2000).Wait();
|
|
ActivateSpotlight(ref settings);
|
|
VerifySpotlightAppears(ref settings);
|
|
|
|
Session.PerformMouseAction(MouseActionType.LeftClick);
|
|
}
|
|
|
|
[TestMethod("MouseUtils.FindMyMouse.DisableFindMyMouse2")]
|
|
[TestCategory("Mouse Utils #5")]
|
|
public void TestDisableFindMyMouse2()
|
|
{
|
|
LaunchFromSetting();
|
|
|
|
var settings = new FindMyMouseSettings();
|
|
settings.OverlayOpacity = "100";
|
|
settings.Radius = "50";
|
|
settings.InitialZoom = "1";
|
|
settings.AnimationDuration = "0";
|
|
settings.BackgroundColor = "000000";
|
|
settings.SpotlightColor = "FFFFFF";
|
|
var foundCustom = this.Find<Custom>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouse));
|
|
if (foundCustom != null)
|
|
{
|
|
foundCustom.Find<ToggleSwitch>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseToggle)).Toggle(true);
|
|
|
|
// foundCustom.Find<ToggleSwitch>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseToggle)).Toggle(false);
|
|
SetFindMyMouseActivationMethod(ref foundCustom, "Press Left Control twice");
|
|
Assert.IsNotNull(foundCustom, "Find My Mouse group not found.");
|
|
|
|
// SetFindMyMouseAppearanceBehavior(ref foundCustom, ref settings);
|
|
var excludedApps = foundCustom.Find(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseExcludedApps));
|
|
if (excludedApps != null)
|
|
{
|
|
excludedApps.Click();
|
|
excludedApps.Click();
|
|
}
|
|
else
|
|
{
|
|
Assert.Fail("Activation method group not found.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Assert.Fail("Find My Mouse group not found.");
|
|
}
|
|
|
|
// [Test Case]Enable FindMyMouse. Then, without moving your mouse: Press Left Ctrl twice and verify the overlay appears.
|
|
// VerifySpotlightSettings(ref settings);
|
|
|
|
// [Test Case] Disable FindMyMouse. Verify the overlay no longer appears when you press Left Ctrl twice
|
|
foundCustom.Find<ToggleSwitch>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseToggle)).Toggle(false);
|
|
Task.Delay(2000).Wait();
|
|
Session.SendKey(Key.LCtrl, 0, 0);
|
|
Task.Delay(100).Wait();
|
|
Session.SendKey(Key.LCtrl, 0, 0);
|
|
|
|
VerifySpotlightDisappears(ref settings);
|
|
}
|
|
|
|
private void VerifySpotlightDisappears(ref FindMyMouseSettings settings)
|
|
{
|
|
Task.Delay(2000).Wait();
|
|
|
|
var location = Session.GetMousePosition();
|
|
int radius = int.Parse(settings.Radius, CultureInfo.InvariantCulture);
|
|
var colorSpotlight = this.GetPixelColorString(location.Item1, location.Item2);
|
|
Assert.AreNotEqual("#" + settings.SpotlightColor, colorSpotlight);
|
|
|
|
var colorBackground = this.GetPixelColorString(location.Item1 + radius + 50, location.Item2 + radius + 50);
|
|
Assert.AreNotEqual("#" + settings.BackgroundColor, colorBackground);
|
|
|
|
var colorBackground2 = this.GetPixelColorString(location.Item1 + radius + 100, location.Item2 + radius + 100);
|
|
Assert.AreNotEqual("#" + settings.BackgroundColor, colorBackground2);
|
|
}
|
|
|
|
private void VerifySpotlightAppears(ref FindMyMouseSettings settings)
|
|
{
|
|
Task.Delay(2000).Wait();
|
|
|
|
var location = Session.GetMousePosition();
|
|
int radius = int.Parse(settings.Radius, CultureInfo.InvariantCulture);
|
|
var colorSpotlight = this.GetPixelColorString(location.Item1, location.Item2);
|
|
Assert.AreEqual("#" + settings.SpotlightColor, colorSpotlight);
|
|
|
|
var colorSpotlight2 = this.GetPixelColorString(location.Item1 + radius - 1, location.Item2);
|
|
|
|
// Session.MoveMouseTo(location.Item1 + radius - 10, location.Item2);
|
|
Assert.AreEqual("#" + settings.SpotlightColor, colorSpotlight2);
|
|
Task.Delay(100).Wait();
|
|
|
|
var colorBackground = this.GetPixelColorString(location.Item1 + radius + 50, location.Item2 + radius + 50);
|
|
Assert.AreEqual("#" + settings.BackgroundColor, colorBackground);
|
|
}
|
|
|
|
private void ActivateSpotlight(ref FindMyMouseSettings settings)
|
|
{
|
|
var xy = Session.GetMousePosition();
|
|
Session.MoveMouseTo(xy.Item1 - 200, xy.Item2 - 100);
|
|
Task.Delay(1000).Wait();
|
|
|
|
Session.PerformMouseAction(MouseActionType.LeftClick);
|
|
Task.Delay(1000).Wait();
|
|
if (settings.SelectedActivationMethod == FindMyMouseSettings.ActivationMethod.PressLeftControlTwice)
|
|
{
|
|
Session.SendKey(Key.LCtrl, 0, 0);
|
|
Task.Delay(200).Wait();
|
|
Session.SendKey(Key.LCtrl, 0, 0);
|
|
}
|
|
else if (settings.SelectedActivationMethod == FindMyMouseSettings.ActivationMethod.PressRightControlTwice)
|
|
{
|
|
Session.SendKey(Key.RCtrl, 0, 0);
|
|
Task.Delay(200).Wait();
|
|
Session.SendKey(Key.RCtrl, 0, 0);
|
|
}
|
|
else if (settings.SelectedActivationMethod == FindMyMouseSettings.ActivationMethod.ShakeMouse)
|
|
{
|
|
// Simulate shake mouse;
|
|
}
|
|
else if (settings.SelectedActivationMethod == FindMyMouseSettings.ActivationMethod.CustomShortcut)
|
|
{
|
|
// Simulate custom shortcut
|
|
}
|
|
}
|
|
|
|
private void VerifySpotlightSettings(ref FindMyMouseSettings settings, bool equal = true)
|
|
{
|
|
ActivateSpotlight(ref settings);
|
|
|
|
VerifySpotlightAppears(ref settings);
|
|
}
|
|
|
|
private void SetFindMyMouseActivationMethod(ref Custom? foundCustom, string method)
|
|
{
|
|
Assert.IsNotNull(foundCustom);
|
|
var groupActivation = foundCustom.Find(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseActivationMethod));
|
|
if (groupActivation != null)
|
|
{
|
|
groupActivation.Click();
|
|
string findMyMouseComboBoxKey = "Activation method";
|
|
var foundElements = foundCustom.FindAll<ComboBox>(findMyMouseComboBoxKey);
|
|
if (foundElements.Count != 0)
|
|
{
|
|
var myMouseComboBox = foundCustom.Find<ComboBox>(findMyMouseComboBoxKey);
|
|
Assert.IsNotNull(myMouseComboBox);
|
|
myMouseComboBox.Click();
|
|
var selectedItem = myMouseComboBox.Find<NavigationViewItem>(method);
|
|
Assert.IsNotNull(selectedItem);
|
|
selectedItem.Click();
|
|
}
|
|
else
|
|
{
|
|
Assert.IsTrue(false, "ComboBox is not found in the setting page.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Assert.Fail("Activation method group not found.");
|
|
}
|
|
}
|
|
|
|
private void SetFindMyMouseAppearanceBehavior(ref Custom foundCustom, ref FindMyMouseSettings settings)
|
|
{
|
|
Assert.IsNotNull(foundCustom);
|
|
var groupAppearanceBehavior = foundCustom.Find(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseAppearanceBehavior));
|
|
if (groupAppearanceBehavior != null)
|
|
{
|
|
var expandState = groupAppearanceBehavior.Selected;
|
|
if (!expandState)
|
|
{
|
|
groupAppearanceBehavior.Click();
|
|
Task.Delay(500).Wait();
|
|
}
|
|
|
|
// Set the BackGround color
|
|
var backgroundColor = foundCustom.Find(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseBackgroundColor));
|
|
Assert.IsNotNull(backgroundColor);
|
|
|
|
var button = backgroundColor.Find<Button>(By.XPath(".//Button"));
|
|
Assert.IsNotNull(button);
|
|
button.Click();
|
|
|
|
var popupWindow = this.Find<Window>("Popup");
|
|
Assert.IsNotNull(popupWindow);
|
|
Task.Delay(1000).Wait();
|
|
var colorModelComboBox = this.Find<ComboBox>("Color model");
|
|
Assert.IsNotNull(colorModelComboBox);
|
|
colorModelComboBox.Click();
|
|
var selectedItem = colorModelComboBox.Find<NavigationViewItem>("RGB");
|
|
selectedItem.Click();
|
|
Task.Delay(500).Wait();
|
|
var rgbHexEdit = this.Find<TextBox>("RGB hex");
|
|
Assert.IsNotNull(rgbHexEdit);
|
|
Task.Delay(500).Wait();
|
|
int retry = 5;
|
|
while (retry > 0)
|
|
{
|
|
Task.Delay(500).Wait();
|
|
rgbHexEdit.SetText(settings.BackgroundColor);
|
|
Task.Delay(500).Wait();
|
|
string rgbHex = rgbHexEdit.Text;
|
|
bool isValid = rgbHex.StartsWith('#') && rgbHex.Length == 7 && rgbHex.Substring(1) == settings.BackgroundColor;
|
|
Task.Delay(500).Wait();
|
|
if (isValid)
|
|
{
|
|
break;
|
|
}
|
|
|
|
retry--;
|
|
}
|
|
|
|
button.Click();
|
|
|
|
// Set the Spotlight color
|
|
var spotlightColor = foundCustom.Find(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseSpotlightColor));
|
|
Assert.IsNotNull(spotlightColor);
|
|
|
|
var spotlightColorButton = spotlightColor.Find<Button>(By.XPath(".//Button"));
|
|
Assert.IsNotNull(spotlightColorButton);
|
|
spotlightColorButton.Click();
|
|
|
|
var spotlightColorPopupWindow = Session.Find<Window>("Popup");
|
|
Assert.IsNotNull(spotlightColorPopupWindow);
|
|
var spotlightColorModelComboBox = this.Find<ComboBox>("Color model");
|
|
Assert.IsNotNull(spotlightColorModelComboBox);
|
|
spotlightColorModelComboBox.Click();
|
|
var selectedItem2 = spotlightColorModelComboBox.Find<NavigationViewItem>("RGB");
|
|
Assert.IsNotNull(selectedItem2);
|
|
selectedItem2.Click();
|
|
Task.Delay(500).Wait();
|
|
var rgbHexEdit2 = this.Find<TextBox>("RGB hex");
|
|
Assert.IsNotNull(rgbHexEdit2);
|
|
Task.Delay(500).Wait();
|
|
retry = 5;
|
|
while (retry > 0)
|
|
{
|
|
Task.Delay(500).Wait();
|
|
rgbHexEdit2.SetText(settings.SpotlightColor);
|
|
Task.Delay(500).Wait();
|
|
string rgbHex = rgbHexEdit2.Text;
|
|
bool isValid = rgbHex.StartsWith('#') && rgbHex.Length == 7 && rgbHex.Substring(1) == settings.SpotlightColor;
|
|
Task.Delay(500).Wait();
|
|
if (isValid)
|
|
{
|
|
break;
|
|
}
|
|
|
|
retry--;
|
|
}
|
|
|
|
Task.Delay(500).Wait();
|
|
spotlightColorButton.Click(false, 500, 1500);
|
|
|
|
// Set the Fade Initial zoom to 0
|
|
var spotlightInitialZoomSlider = foundCustom.Find<Slider>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseSpotlightZoom));
|
|
Assert.IsNotNull(spotlightInitialZoomSlider);
|
|
Task.Delay(1000).Wait();
|
|
spotlightInitialZoomSlider.QuickSetValue(int.Parse(settings.InitialZoom, CultureInfo.InvariantCulture));
|
|
Assert.AreEqual(settings.InitialZoom, spotlightInitialZoomSlider.Text);
|
|
Task.Delay(1000).Wait();
|
|
|
|
//// Change the edit value
|
|
var spotlightRadius = foundCustom.Find(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseSpotlightRadius));
|
|
var spotlightRadiusEdit = spotlightRadius.Find<TextBox>(By.AccessibilityId("InputBox"));
|
|
Assert.IsNotNull(spotlightRadiusEdit);
|
|
Task.Delay(1000).Wait();
|
|
spotlightRadiusEdit.SetText(settings.Radius);
|
|
Assert.AreEqual(settings.Radius, spotlightRadiusEdit.Text);
|
|
Task.Delay(1000).Wait();
|
|
|
|
// Set the duration to 0 ms
|
|
var spotlightAnimationDuration = foundCustom.Find(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.FindMyMouseAnimationDuration));
|
|
var spotlightAnimationDurationEdit = spotlightAnimationDuration.Find<TextBox>(By.AccessibilityId("InputBox"));
|
|
Assert.IsNotNull(spotlightAnimationDurationEdit);
|
|
Task.Delay(1000).Wait();
|
|
spotlightAnimationDurationEdit.SetText(settings.AnimationDuration);
|
|
Assert.AreEqual(settings.AnimationDuration, spotlightAnimationDurationEdit.Text);
|
|
Task.Delay(1000).Wait();
|
|
|
|
// groupAppearanceBehavior.Click();
|
|
}
|
|
else
|
|
{
|
|
Assert.Fail("Appearance & behavior group not found.");
|
|
}
|
|
}
|
|
|
|
private bool CheckAnimationEnable(ref Custom? foundCustom)
|
|
{
|
|
Assert.IsNotNull(foundCustom, "Find My Mouse group not found.");
|
|
var foundElements = foundCustom.FindAll<TextBlock>("Animations are disabled in your system settings.");
|
|
|
|
// Assert.IsNull(animationDisabledWarning);
|
|
if (foundElements.Count != 0)
|
|
{
|
|
var openSettingsLink = foundCustom.Find<Element>("Open animation settings");
|
|
Assert.IsNotNull(openSettingsLink);
|
|
openSettingsLink.Click(false, 500, 3000);
|
|
|
|
string settingsWindow = "Settings";
|
|
this.Session.Attach(settingsWindow);
|
|
var animationEffects = this.Find<ToggleSwitch>("Animation effects");
|
|
Assert.IsNotNull(animationEffects);
|
|
animationEffects.Toggle(true);
|
|
|
|
Task.Delay(2000).Wait();
|
|
Session.SendKeys(Key.Alt, Key.F4);
|
|
this.Session.Attach(PowerToysModule.PowerToysSettings);
|
|
this.LaunchFromSetting(reload: true);
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private void LaunchFromSetting(bool reload = false, bool launchAsAdmin = false)
|
|
{
|
|
Session = RestartScopeExe("FindMyMouse,MouseHighlighter,MouseJump,MousePointerCrosshairs,CursorWrap");
|
|
|
|
// this.Session.Attach(PowerToysModule.PowerToysSettings);
|
|
this.Session.SetMainWindowSize(WindowSize.Large);
|
|
|
|
// Goto Hosts File Editor setting page
|
|
if (this.FindAll(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.MouseUtilitiesNavItem)).Count == 0)
|
|
{
|
|
// Expand Advanced list-group if needed
|
|
this.Find(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.InputOutputNavItem)).Click();
|
|
}
|
|
|
|
if (reload)
|
|
{
|
|
this.Find<NavigationViewItem>(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.KeyboardManagerNavItem)).Click();
|
|
}
|
|
|
|
Task.Delay(1000).Wait();
|
|
this.Find(By.AccessibilityId(MouseUtilsSettings.AccessibilityIds.MouseUtilitiesNavItem)).Click();
|
|
}
|
|
}
|
|
}
|