diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 303d85d4..d0e77161 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -34,9 +34,10 @@ if ([string]::IsNullOrEmpty($env:TestRegistryPath)) { $global:PointerRegistryPath = 'HKCU:\Control Panel\Cursors\' $global:ControlPanelAccessibilityRegistryPath= 'HKCU:\Control Panel\Accessibility\' $global:AudioRegistryPath = 'HKCU:\Software\Microsoft\Multimedia\Audio\' + $global:PersonalizationRegistryPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\' } else { - $global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $global:ControlPanelAccessibilityRegistryPath = $global:AudioRegistryPath = $env:TestRegistryPath + $global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $global:ControlPanelAccessibilityRegistryPath = $global:AudioRegistryPath = $global:PersonalizationRegistryPath = $env:TestRegistryPath } @@ -249,9 +250,11 @@ class VisualEffect { # Key required. Do not set. [DscProperty(Key)] [string] $SID - [DscProperty()] [bool] $AlwaysShowScrollbars = $false + [DscProperty()] [nullable[bool]] $AlwaysShowScrollbars + [DscProperty()] [nullable[bool]] $TransparencyEffects static hidden [string] $DynamicScrollbarsProperty = 'DynamicScrollbars' + static hidden [string] $TransparencySettingProperty = 'EnableTransparency' static [bool] GetShowDynamicScrollbarsStatus() { @@ -266,10 +269,24 @@ class VisualEffect } } + static [bool] GetTransparencyStatus() + { + if (-not(DoesRegistryKeyPropertyExist -Path $global:PersonalizationRegistryPath -Name ([VisualEffect]::TransparencySettingProperty))) + { + return $false + } + else + { + $TransparencySetting = (Get-ItemProperty -Path $global:PersonalizationRegistryPath -Name ([VisualEffect]::TransparencySettingProperty)).EnableTransparency + return ($TransparencySetting -eq 0) + } + } + [VisualEffect] Get() { $currentState = [VisualEffect]::new() $currentState.AlwaysShowScrollbars = [VisualEffect]::GetShowDynamicScrollbarsStatus() + $currentState.TransparencyEffects = [VisualEffect]::GetTransparencyStatus() return $currentState } @@ -277,10 +294,14 @@ class VisualEffect [bool] Test() { $currentState = $this.Get() - if ($this.AlwaysShowScrollbars -ne $currentState.AlwaysShowScrollbars) + if (($null -ne $this.AlwaysShowScrollbars) -and ($this.AlwaysShowScrollbars -ne $currentState.AlwaysShowScrollbars)) { return $false } + if (($null -ne $this.TransparencyEffects) -and ($this.TransparencyEffects -ne $currentState.TransparencyEffects)) + { + return $false + } return $true } @@ -293,10 +314,20 @@ class VisualEffect { New-Item -Path $global:ControlPanelAccessibilityRegistryPath -Force | Out-Null } - - $dynamicScrollbarValue = if ($this.AlwaysShowScrollbars) { 0 } else { 1 } - - Set-ItemProperty -Path $global:ControlPanelAccessibilityRegistryPath -Name ([VisualEffect]::DynamicScrollbarsProperty) -Value $dynamicScrollbarValue + if ($null -ne $this.AlwaysShowScrollbars) + { + $dynamicScrollbarValue = if ($this.AlwaysShowScrollbars) { 0 } else { 1 } + Set-ItemProperty -Path $global:ControlPanelAccessibilityRegistryPath -Name ([VisualEffect]::DynamicScrollbarsProperty) -Value $dynamicScrollbarValue + } + if ($null -ne $this.TransparencyEffects) + { + $transparencyValue = if ($this.TransparencyEffects) { 0 } else { 1 } + + if (-not (DoesRegistryKeyPropertyExist -Path $global:PersonalizationRegistryPath -Name ([VisualEffect]::TransparencySettingProperty))) { + New-ItemProperty -Path $global:PersonalizationRegistryPath -Name ([VisualEffect]::TransparencySettingProperty) -Value $transparencyValue -PropertyType DWord + } + Set-ItemProperty -Path $global:PersonalizationRegistryPath -Name ([VisualEffect]::TransparencySettingProperty) -Value $transparencyValue + } } } } diff --git a/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 b/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 index c5a8cd12..2d8dd75b 100644 --- a/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 +++ b/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 @@ -1,168 +1,186 @@ - -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. -using module Microsoft.Windows.Setting.Accessibility - -$ErrorActionPreference = "Stop" -Set-StrictMode -Version Latest - -<# -.Synopsis - Pester tests related to the Microsoft.Windows.Setting.Accessibility PowerShell module. -#> - -BeforeAll { - if ($null -eq (Get-Module -ListAvailable -Name PSDesiredStateConfiguration)) - { - Install-Module -Name PSDesiredStateConfiguration -Force -SkipPublisherCheck - } - - Import-Module Microsoft.Windows.Setting.Accessibility - - # Create test registry path. - New-Item -Path TestRegistry:\ -Name TestKey - # Set-ItemProperty requires the PSDrive to be in the format 'HKCU:'. - $env:TestRegistryPath = ((Get-Item -Path TestRegistry:\).Name).replace("HKEY_CURRENT_USER", "HKCU:") -} - -Describe 'List available DSC resources' { - It 'Shows DSC Resources' { - $expectedDSCResources = "Text", "Magnifier", "MousePointer", "VisualEffect", "Audio" - $availableDSCResources = (Get-DscResource -Module Microsoft.Windows.Setting.Accessibility).Name - $availableDSCResources.length | Should -Be 5 - $availableDSCResources | Where-Object { $expectedDSCResources -notcontains $_ } | Should -BeNullOrEmpty -ErrorAction Stop - } -} - -Describe 'Text' { - It 'Keeps current value.' { - $initialState = Invoke-DscResource -Name Text -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - - $parameters = @{ Size = 'KeepCurrentValue' } - - $testResult = Invoke-DscResource -Name Text -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters - $testResult.InDesiredState | Should -Be $true - - # Invoking set should not change these values. - Invoke-DscResource -Name Text -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters - $finalState = Invoke-DscResource -Name Text -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - $finalState.Size | Should -Be $initialState.Size - } - - It 'Sets desired value' { - # Randomly generate desired state. Minimum is set to 1 to avoid KeepCurrentValue - $desiredTextSize = [TextSize](Get-Random -Maximum 4 -Minimum 1) - - $desiredState = @{ Size = $desiredTextSize } - - Invoke-DscResource -Name Text -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $desiredState - - $finalState = Invoke-DscResource -Name Text -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - $finalState.Size | Should -Be $desiredTextSize - } -} - -Describe 'Magnifier' { - It 'Keeps current value.' { - $initialState = Invoke-DscResource -Name Magnifier -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - - $parameters = @{ Magnification = 'KeepCurrentValue' } - - $testResult = Invoke-DscResource -Name Magnifier -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters - $testResult.InDesiredState | Should -Be $true - - # Invoking set should not change these values. - Invoke-DscResource -Name Magnifier -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters - $finalState = Invoke-DscResource -Name Magnifier -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - $finalState.Magnification | Should -Be $initialState.Magnification - } - - It 'Sets desired value' { - # Randomly generate desired state. Minimum is set to 1 to avoid KeepCurrentValue - $desiredMagnification = [MagnificationValue](Get-Random -Maximum 4 -Minimum 1) - - $desiredState = @{ Magnification = $desiredMagnification } - - Invoke-DscResource -Name Magnifier -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $desiredState - - $finalState = Invoke-DscResource -Name Magnifier -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - $finalState.Magnification | Should -Be $desiredMagnification - } -} - -Describe 'MousePointer' { - It 'Keeps current value.' { - $initialState = Invoke-DscResource -Name MousePointer -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - - $parameters = @{ PointerSize = 'KeepCurrentValue' } - - $testResult = Invoke-DscResource -Name MousePointer -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters - $testResult.InDesiredState | Should -Be $true - - # Invoking set should not change these values. - Invoke-DscResource -Name MousePointer -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters - $finalState = Invoke-DscResource -Name MousePointer -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - $finalState.PointerSize | Should -Be $initialState.PointerSize - } - - It 'Sets desired value' { - # Randomly generate desired state. Minimum is set to 1 to avoid KeepCurrentValue - $desiredPointerSize = [PointerSize](Get-Random -Maximum 4 -Minimum 1) - - $desiredState = @{ PointerSize = $desiredPointerSize } - - Invoke-DscResource -Name MousePointer -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $desiredState - - $finalState = Invoke-DscResource -Name MousePointer -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - $finalState.PointerSize | Should -Be $desiredPointerSize - } -} - -Describe 'VisualEffect'{ - It 'AlwaysShowScrollbars.'{ - Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property @{ AlwaysShowScrollbars = $false } - - $initialState = Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - $initialState.AlwaysShowScrollbars | Should -Be $false - - # Set 'AlwaysShowScrollbars' to true. - $parameters = @{ AlwaysShowScrollbars = $true } - $testResult = Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters - $testResult.InDesiredState | Should -Be $false - - # Verify the changes are correct. - Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters - $finalState = Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - $finalState.AlwaysShowScrollbars | Should -Be $true - - $testResult2 = Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters - $testResult2.InDesiredState | Should -Be $true - } -} - -Describe 'Audio'{ - It 'EnableMonoAudio.'{ - Invoke-DscResource -Name Audio -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property @{ EnableMonoAudio = $false } - - $initialState = Invoke-DscResource -Name Audio -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - $initialState.EnableMonoAudio | Should -Be $false - - # Set 'EnableMonoAudio' to true. - $parameters = @{ EnableMonoAudio = $true } - $testResult = Invoke-DscResource -Name Audio -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters - $testResult.InDesiredState | Should -Be $false - - # Verify the changes are correct. - Invoke-DscResource -Name Audio -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters - $finalState = Invoke-DscResource -Name Audio -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - $finalState.EnableMonoAudio | Should -Be $true - - $testResult2 = Invoke-DscResource -Name Audio -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters - $testResult2.InDesiredState | Should -Be $true - } -} - - -AfterAll { - $env:TestRegistryPath = "" -} + +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +using module Microsoft.Windows.Setting.Accessibility + +$ErrorActionPreference = "Stop" +Set-StrictMode -Version Latest + +<# +.Synopsis + Pester tests related to the Microsoft.Windows.Setting.Accessibility PowerShell module. +#> + +BeforeAll { + if ($null -eq (Get-Module -ListAvailable -Name PSDesiredStateConfiguration)) + { + Install-Module -Name PSDesiredStateConfiguration -Force -SkipPublisherCheck + } + + Import-Module Microsoft.Windows.Setting.Accessibility + + # Create test registry path. + New-Item -Path TestRegistry:\ -Name TestKey + # Set-ItemProperty requires the PSDrive to be in the format 'HKCU:'. + $env:TestRegistryPath = ((Get-Item -Path TestRegistry:\).Name).replace("HKEY_CURRENT_USER", "HKCU:") +} + +Describe 'List available DSC resources' { + It 'Shows DSC Resources' { + $expectedDSCResources = "Text", "Magnifier", "MousePointer", "VisualEffect", "Audio" + $availableDSCResources = (Get-DscResource -Module Microsoft.Windows.Setting.Accessibility).Name + $availableDSCResources.length | Should -Be 5 + $availableDSCResources | Where-Object { $expectedDSCResources -notcontains $_ } | Should -BeNullOrEmpty -ErrorAction Stop + } +} + +Describe 'Text' { + It 'Keeps current value.' { + $initialState = Invoke-DscResource -Name Text -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + + $parameters = @{ Size = 'KeepCurrentValue' } + + $testResult = Invoke-DscResource -Name Text -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters + $testResult.InDesiredState | Should -Be $true + + # Invoking set should not change these values. + Invoke-DscResource -Name Text -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters + $finalState = Invoke-DscResource -Name Text -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.Size | Should -Be $initialState.Size + } + + It 'Sets desired value' { + # Randomly generate desired state. Minimum is set to 1 to avoid KeepCurrentValue + $desiredTextSize = [TextSize](Get-Random -Maximum 4 -Minimum 1) + + $desiredState = @{ Size = $desiredTextSize } + + Invoke-DscResource -Name Text -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $desiredState + + $finalState = Invoke-DscResource -Name Text -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.Size | Should -Be $desiredTextSize + } +} + +Describe 'Magnifier' { + It 'Keeps current value.' { + $initialState = Invoke-DscResource -Name Magnifier -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + + $parameters = @{ Magnification = 'KeepCurrentValue' } + + $testResult = Invoke-DscResource -Name Magnifier -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters + $testResult.InDesiredState | Should -Be $true + + # Invoking set should not change these values. + Invoke-DscResource -Name Magnifier -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters + $finalState = Invoke-DscResource -Name Magnifier -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.Magnification | Should -Be $initialState.Magnification + } + + It 'Sets desired value' { + # Randomly generate desired state. Minimum is set to 1 to avoid KeepCurrentValue + $desiredMagnification = [MagnificationValue](Get-Random -Maximum 4 -Minimum 1) + + $desiredState = @{ Magnification = $desiredMagnification } + + Invoke-DscResource -Name Magnifier -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $desiredState + + $finalState = Invoke-DscResource -Name Magnifier -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.Magnification | Should -Be $desiredMagnification + } +} + +Describe 'MousePointer' { + It 'Keeps current value.' { + $initialState = Invoke-DscResource -Name MousePointer -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + + $parameters = @{ PointerSize = 'KeepCurrentValue' } + + $testResult = Invoke-DscResource -Name MousePointer -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters + $testResult.InDesiredState | Should -Be $true + + # Invoking set should not change these values. + Invoke-DscResource -Name MousePointer -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters + $finalState = Invoke-DscResource -Name MousePointer -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.PointerSize | Should -Be $initialState.PointerSize + } + + It 'Sets desired value' { + # Randomly generate desired state. Minimum is set to 1 to avoid KeepCurrentValue + $desiredPointerSize = [PointerSize](Get-Random -Maximum 4 -Minimum 1) + + $desiredState = @{ PointerSize = $desiredPointerSize } + + Invoke-DscResource -Name MousePointer -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $desiredState + + $finalState = Invoke-DscResource -Name MousePointer -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.PointerSize | Should -Be $desiredPointerSize + } +} + +Describe 'VisualEffect'{ + It 'AlwaysShowScrollbars.'{ + Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property @{ AlwaysShowScrollbars = $false } + + $initialState = Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $initialState.AlwaysShowScrollbars | Should -Be $false + + # Set 'AlwaysShowScrollbars' to true. + $parameters = @{ AlwaysShowScrollbars = $true } + $testResult = Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters + $testResult.InDesiredState | Should -Be $false + + # Verify the changes are correct. + Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters + $finalState = Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.AlwaysShowScrollbars | Should -Be $true + + $testResult2 = Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters + $testResult2.InDesiredState | Should -Be $true + } + It 'TransparencyEffects.'{ + Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property @{ TransparencyEffects = $false } + + $initialState = Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $initialState.TransparencyEffects | Should -Be $false + + # Set 'TransparencyEffects' to true. + $parameters = @{ TransparencyEffects = $true } + $testResult = Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters + $testResult.InDesiredState | Should -Be $false + + # Verify the changes are correct. + Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters + $finalState = Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.TransparencyEffects | Should -Be $true + + $testResult2 = Invoke-DscResource -Name VisualEffect -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters + $testResult2.InDesiredState | Should -Be $true + } +} + +Describe 'Audio'{ + It 'EnableMonoAudio.'{ + Invoke-DscResource -Name Audio -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property @{ EnableMonoAudio = $false } + + $initialState = Invoke-DscResource -Name Audio -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $initialState.EnableMonoAudio | Should -Be $false + + # Set 'EnableMonoAudio' to true. + $parameters = @{ EnableMonoAudio = $true } + $testResult = Invoke-DscResource -Name Audio -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters + $testResult.InDesiredState | Should -Be $false + + # Verify the changes are correct. + Invoke-DscResource -Name Audio -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters + $finalState = Invoke-DscResource -Name Audio -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.EnableMonoAudio | Should -Be $true + + $testResult2 = Invoke-DscResource -Name Audio -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters + $testResult2.InDesiredState | Should -Be $true + } +} + +AfterAll { + $env:TestRegistryPath = "" +}