Path: blob/trunk/java/test/org/openqa/selenium/PlatformTest.java
1865 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617package org.openqa.selenium;1819import static org.assertj.core.api.Assertions.assertThat;20import static org.openqa.selenium.Platform.ANDROID;21import static org.openqa.selenium.Platform.ANY;22import static org.openqa.selenium.Platform.CATALINA;23import static org.openqa.selenium.Platform.IOS;24import static org.openqa.selenium.Platform.LINUX;25import static org.openqa.selenium.Platform.MAC;26import static org.openqa.selenium.Platform.SEQUOIA;27import static org.openqa.selenium.Platform.UNIX;28import static org.openqa.selenium.Platform.VISTA;29import static org.openqa.selenium.Platform.WIN11;30import static org.openqa.selenium.Platform.WIN8;31import static org.openqa.selenium.Platform.WIN8_1;32import static org.openqa.selenium.Platform.WINDOWS;33import static org.openqa.selenium.Platform.XP;3435import org.junit.jupiter.api.Tag;36import org.junit.jupiter.api.Test;3738@Tag("UnitTests")39class PlatformTest {4041@Test42void testXpIsWindows() {43assertThat(XP.is(WINDOWS)).isTrue();44}4546@Test47void testVistaIsWindows() {48assertThat(VISTA.is(WINDOWS)).isTrue();49}5051@Test52void testWin8IsWindows() {53assertThat(WIN8.is(WINDOWS)).isTrue();54}5556@Test57void testWin81IsWindows() {58assertThat(WIN8_1.is(WINDOWS)).isTrue();59}6061@Test62void testWindows11IsWindows() {63assertThat(WIN11.is(WINDOWS)).isTrue();64}6566@Test67void testLinuxIsUnix() {68assertThat(LINUX.is(UNIX)).isTrue();69}7071@Test72void testUnixIsNotLinux() {73assertThat(UNIX.is(LINUX)).isFalse();74}7576@Test77void testXpIsAny() {78assertThat(XP.is(ANY)).isTrue();79}8081@Test82void testWindowsIsAny() {83assertThat(WINDOWS.is(ANY)).isTrue();84}8586@Test87void testLinuxIsAny() {88assertThat(LINUX.is(ANY)).isTrue();89}9091@Test92void windowsIsNotMacOS() {93// Both of these are platform definitions, so return "null" for the family.94assertThat(WINDOWS.is(MAC)).isFalse();95}9697@Test98void testUnixIsAny() {99assertThat(UNIX.is(ANY)).isTrue();100}101102@Test103void testShouldIdentifyXPVariants() {104assertAllAre(Platform.WINDOWS, "Windows 2003", "xp", "windows", "winnt");105}106107@Test108void testShouldIdentifyVistaVariants() {109assertAllAre(Platform.VISTA, "Windows Vista", "windows server 2008");110}111112@Test113void testShouldIdentifyMacVariants() {114assertAllAre(Platform.MAC, "Darwin", "Mac OS X");115}116117@Test118void testShouldIdentifyUnixVariants() {119assertAllAre(Platform.UNIX, "solaris", "bsd");120}121122@Test123void testShouldIdentifyLinux() {124assertAllAre(Platform.LINUX, "Linux");125}126127@Test128void windowsIsWindows() {129assertThat(WINDOWS.is(WINDOWS)).isTrue();130}131132@Test133void macIsMac() {134assertThat(MAC.is(MAC)).isTrue();135}136137@Test138void linuxIsLinux() {139assertThat(LINUX.is(LINUX)).isTrue();140}141142@Test143void unixIsUnix() {144assertThat(UNIX.is(UNIX)).isTrue();145}146147@Test148void androidIAndroid() {149assertThat(ANDROID.is(ANDROID)).isTrue();150}151152@Test153void iosIsIos() {154assertThat(IOS.is(IOS)).isTrue();155}156157@Test158void testWindows8Detection() {159assertThat(Platform.extractFromSysProperty("windows nt (unknown)", "6.2"))160.isEqualTo(Platform.WIN8);161}162163@Test164void testWindows81Detection() {165assertThat(Platform.extractFromSysProperty("windows nt (unknown)", "6.3"))166.isEqualTo(Platform.WIN8_1);167}168169@Test170void testWindowsIsWindows() {171assertThat(WINDOWS).isEqualTo(Platform.fromString("windows"));172}173174@Test175void testWindowsIsNotEmpty() {176assertThat(WINDOWS).isNotEqualTo(Platform.fromString(""));177}178179@Test180void canParseMacOsXCorrectly() {181assertThat(Platform.fromString("Mac OS X")).isEqualTo(MAC);182}183184@Test185void testAnyIsFromStringEmpty() {186assertThat(ANY).isEqualTo(Platform.fromString(""));187}188189@Test190void testAnyIsFromStringAny() {191assertThat(ANY).isEqualTo(Platform.fromString("any"));192}193194@Test195void testAnyIsNotFromStringWindows() {196assertThat(ANY).isNotEqualTo(Platform.fromString("windows"));197}198199@Test200void catalinaIsMac() {201assertThat(CATALINA.is(MAC)).isTrue();202}203204@Test205void sequoiaIsMac() {206assertThat(SEQUOIA.is(MAC)).isTrue();207}208209@Test210void canParseCatalinaFromOSName() {211assertThat(Platform.fromString("macOS 10.15")).isEqualTo(CATALINA);212}213214private void assertAllAre(Platform platform, String... osNames) {215for (String osName : osNames) {216Platform seen = Platform.extractFromSysProperty(osName);217assertThat(seen.is(platform)).isTrue();218}219}220}221222223