diff --git a/images/win/scripts/Installers/Install-Chrome.ps1 b/images/win/scripts/Installers/Install-Chrome.ps1 index 5a4d20eb..486d4d76 100644 --- a/images/win/scripts/Installers/Install-Chrome.ps1 +++ b/images/win/scripts/Installers/Install-Chrome.ps1 @@ -3,43 +3,80 @@ ## Desc: Install Google Chrome ################################################################################ -# Get versions info -$ChromeVersionsUrl = "https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json" -$ChromeVersions = Invoke-RestMethod -Uri $ChromeVersionsUrl -$ChromeVersionInfo = $ChromeVersions.channels.Stable +# Download and install latest Chrome browser +$ChromeInstallerFile = "googlechromestandaloneenterprise64.msi" +$ChromeInstallerUrl = "https://dl.google.com/tag/s/dl/chrome/install/${ChromeInstallerFile}" +Install-Binary -Url $ChromeInstallerUrl -Name $ChromeInstallerFile -ArgumentList @() -# Install Google Chrome for Testing -$ChromeVersion = $ChromeVersionInfo.version -$ChromeUrl = ($ChromeVersionInfo.downloads.chrome | Where-Object platform -eq "win64").url +# Prepare firewall rules +Write-Host "Adding the firewall rule for Google update blocking..." +New-NetFirewallRule -DisplayName "BlockGoogleUpdate" -Direction Outbound -Action Block -Program "C:\Program Files (x86)\Google\Update\GoogleUpdate.exe" -Write-Host "Installing Google Chrome for Testing version $ChromeVersion" -$ChromePath = "$($env:SystemDrive)\Program Files\Google\Chrome" -if (-not (Test-Path -Path $ChromePath)) { - New-Item -Path $ChromePath -ItemType Directory -Force +$GoogleSvcs = ('gupdate','gupdatem') +$GoogleSvcs | Stop-SvcWithErrHandling -StopOnError +$GoogleSvcs | Set-SvcWithErrHandling -Arguments @{StartupType = "Disabled"} + +$regGoogleUpdatePath = "HKLM:\SOFTWARE\Policies\Google\Update" +$regGoogleUpdateChrome = "HKLM:\SOFTWARE\Policies\Google\Chrome" +($regGoogleUpdatePath, $regGoogleUpdateChrome) | ForEach-Object { + New-Item -Path $_ -Force } -$ChromeArchivePath = Start-DownloadWithRetry -Url $ChromeUrl -Extract-7Zip -Path $ChromeArchivePath -DestinationPath $ChromePath -Rename-Item "$ChromePath\chrome-win64" "$ChromePath\Application" +$regGoogleParameters = @( + @{ Name = "AutoUpdateCheckPeriodMinutes"; Value = 00000000}, + @{ Name = "UpdateDefault"; Value = 00000000 }, + @{ Name = "DisableAutoUpdateChecksCheckboxValue"; Value = 00000001 }, + @{ Name = "Update{8A69D345-D564-463C-AFF1-A69D9E530F96}"; Value = 00000000 }, + @{ Path = $regGoogleUpdateChrome; Name = "DefaultBrowserSettingEnabled"; Value = 00000000 } +) -$chromeRegPath = "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe" -New-Item $chromeRegPath -Set-ItemProperty $chromeRegPath "(default)" "$ChromePath\Application\chrome.exe" +$regGoogleParameters | ForEach-Object { + $Arguments = $_ + if (-not ($Arguments.Path)) + { + $Arguments.Add("Path", $regGoogleUpdatePath) + } + $Arguments.Add("Force", $true) + New-ItemProperty @Arguments +} -# Install Chrome Driver -$ChromeDriverVersion = $ChromeVersionInfo.version -$ChromeDriverUrl = ($ChromeVersionInfo.downloads.chromedriver | Where-Object platform -eq "win64").url - -Write-Host "Installing ChromeDriver version $ChromeDriverVersion" +# Install Chrome WebDriver +Write-Host "Install Chrome WebDriver..." $ChromeDriverPath = "$($env:SystemDrive)\SeleniumWebDrivers\ChromeDriver" -if (-not (Test-Path -Path $ChromeDriverPath)) { +if (-not (Test-Path -Path $ChromeDriverPath)) +{ New-Item -Path $ChromeDriverPath -ItemType Directory -Force } -$ChromeDriverVersion | Out-File -FilePath "$ChromeDriverPath\versioninfo.txt" -Force; -$ChromeDriverArchivePath = Start-DownloadWithRetry -Url $ChromeDriverUrl -Extract-7Zip -Path $ChromeDriverArchivePath -DestinationPath $ChromeDriverPath -ExtractMethod "e" +Write-Host "Get the Chrome WebDriver download URL..." +$RegistryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths" +$ChromePath = (Get-ItemProperty "$RegistryPath\chrome.exe").'(default)' +[version]$ChromeVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($ChromePath).ProductVersion +$ChromeBuild = "$($ChromeVersion.Major).$($ChromeVersion.Minor).$($ChromeVersion.Build)" +$ChromeDriverVersionsUrl = "https://googlechromelabs.github.io/chrome-for-testing/latest-patch-versions-per-build-with-downloads.json" +Write-Host "Chrome version is $ChromeVersion" +$ChromeDriverVersions = Invoke-RestMethod -Uri $ChromeDriverVersionsUrl +$ChromeDriverVersion = $ChromeDriverVersions.builds.$ChromeBuild + +if (-not ($ChromeDriverVersion)) { + $availableVersions = $ChromeDriverVersions.builds | Get-Member | Select-Object -ExpandProperty Name + Write-Host "Available chromedriver builds are $availableVersions" + Throw "Can't determine chromedriver version that matches chrome build $ChromeBuild" +} + +$ChromeDriverVersion.version | Out-File -FilePath "$ChromeDriverPath\versioninfo.txt" -Force; + +Write-Host "Chrome WebDriver version to install is $($ChromeDriverVersion.version)" +$ChromeDriverZipDownloadUrl = ($ChromeDriverVersion.downloads.chromedriver | Where-Object platform -eq "win64").url + +Write-Host "Download Chrome WebDriver from $ChromeDriverZipDownloadUrl..." +$ChromeDriverArchPath = Start-DownloadWithRetry -Url $ChromeDriverZipDownloadUrl + +Write-Host "Expand Chrome WebDriver archive (without using directory names)..." +Extract-7Zip -Path $ChromeDriverArchPath -DestinationPath $ChromeDriverPath -ExtractMethod "e" + +Write-Host "Setting the environment variables..." setx ChromeWebDriver "$ChromeDriverPath" /M $regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\' diff --git a/images/win/scripts/Tests/Browsers.Tests.ps1 b/images/win/scripts/Tests/Browsers.Tests.ps1 index 1d03c7a6..ba5db877 100644 --- a/images/win/scripts/Tests/Browsers.Tests.ps1 +++ b/images/win/scripts/Tests/Browsers.Tests.ps1 @@ -28,9 +28,18 @@ Describe "Chrome" { $versionInfo | Should -Not -BeNullOrEmpty } - It "Chrome Product Name should be 'Google Chrome for Testing'" -TestCases @{chromePath = $chromePath } { - $productName = (Get-Item $chromePath).VersionInfo.ProductName - $productName | Should -BeExactly "Google Chrome for Testing" + It "gupdate service is stopped" { + $svc = Get-Service -Name gupdate + $svc.Status | Should -BeExactly Stopped + } + + It "gupdatem service is stopped" { + $svc = Get-Service -Name gupdatem + $svc.Status | Should -BeExactly Stopped + } + + It "BlockGoogleUpdate firewall rule exists" { + Get-NetFirewallRule -DisplayName BlockGoogleUpdate | Should -Not -BeNullOrEmpty } It " is installed" -TestCases @{chromePath = $chromePath} {