parameters:
  channel: preview

# Should match https://web-platform-tests.org/running-tests/safari.html
steps:
- script: defaults write com.apple.WebDriver DiagnosticsEnabled 1
  displayName: 'Enable safaridriver diagnostics'
  condition: eq(variables['safaridriver_diagnose'], true)
- ${{ if eq(parameters.channel, 'preview') }}:
  - script: |
      set -eux -o pipefail
      export SYSTEM_VERSION_COMPAT=0
      ./wpt install --channel preview --download-only -d . --rename STP safari browser
      sudo installer -pkg STP.pkg -target LocalSystem
      # Workaround for `sudo safardriver --enable` not working on Catalina:
      # https://github.com/web-platform-tests/wpt/issues/21751
      mkdir -p ~/Library/WebDriver/
      cp tools/ci/azure/com.apple.SafariTechnologyPreview.plist ~/Library/WebDriver/
      defaults write com.apple.SafariTechnologyPreview WebKitJavaScriptCanOpenWindowsAutomatically 1
      defaults write com.apple.SafariTechnologyPreview ExperimentalServerTimingEnabled 1
    displayName: 'Install Safari Technology Preview'
- ${{ if eq(parameters.channel, 'stable') }}:
  - script: |
      set -eux -o pipefail
      export SYSTEM_VERSION_COMPAT=0
      sudo softwareupdate --install $( softwareupdate -l | grep -o '\* Label: \(Safari.*\)' | sed -e 's/* Label: //' )
      sudo safaridriver --enable
      defaults write com.apple.Safari WebKitJavaScriptCanOpenWindowsAutomatically 1
    displayName: 'Configure Safari'
