Skip to content

Commit 52197cf

Browse files
committed
Fixing platform comparison. Fixes issue 7522
1 parent c7b0193 commit 52197cf

File tree

3 files changed

+59
-35
lines changed

3 files changed

+59
-35
lines changed

java/client/src/org/openqa/selenium/Platform.java

+25-21
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,16 @@ public enum Platform {
3232
/**
3333
* Never returned, but can be used to request a browser running on any version of Windows.
3434
*/
35-
WINDOWS("") {
36-
@Override
37-
public boolean is(Platform compareWith) {
38-
return compareWith == WINDOWS || compareWith == XP
39-
|| compareWith == VISTA || compareWith == WIN8;
40-
}
41-
},
35+
WINDOWS("") {},
4236

4337
/**
4438
* For versions of Windows that "feel like" Windows XP. These are ones that store files in
4539
* "\Program Files\" and documents under "\\documents and settings\\username"
4640
*/
4741
XP("Windows Server 2003", "xp", "windows", "winnt") {
4842
@Override
49-
public boolean is(Platform compareWith) {
50-
return compareWith == WINDOWS || compareWith == XP;
43+
public Platform family() {
44+
return WINDOWS;
5145
}
5246
},
5347

@@ -56,8 +50,8 @@ public boolean is(Platform compareWith) {
5650
*/
5751
VISTA("windows vista", "Windows Server 2008", "windows 7", "win7") {
5852
@Override
59-
public boolean is(Platform compareWith) {
60-
return compareWith == WINDOWS || compareWith == VISTA;
53+
public Platform family() {
54+
return WINDOWS;
6155
}
6256
},
6357

@@ -66,15 +60,15 @@ public boolean is(Platform compareWith) {
6660
*/
6761
WIN8("Windows Server 2012", "windows 8", "win8") {
6862
@Override
69-
public boolean is(Platform compareWith) {
70-
return compareWith == WINDOWS || compareWith == WIN8;
63+
public Platform family() {
64+
return WINDOWS;
7165
}
7266
},
7367

7468
WIN8_1("windows 8.1", "win8.1") {
7569
@Override
76-
public boolean is(Platform compareWith) {
77-
return compareWith == WINDOWS || compareWith == WIN8_1;
70+
public Platform family() {
71+
return WINDOWS;
7872
}
7973
},
8074

@@ -87,8 +81,8 @@ public boolean is(Platform compareWith) {
8781

8882
LINUX("linux") {
8983
@Override
90-
public boolean is(Platform compareWith) {
91-
return compareWith == UNIX || compareWith == LINUX;
84+
public Platform family() {
85+
return UNIX;
9286
}
9387
},
9488

@@ -98,8 +92,8 @@ public String getLineEnding() {
9892
}
9993

10094
@Override
101-
public boolean is(Platform compareWith) {
102-
return compareWith == LINUX || compareWith == ANDROID;
95+
public Platform family() {
96+
return LINUX;
10397
}
10498
},
10599

@@ -109,7 +103,7 @@ public boolean is(Platform compareWith) {
109103
ANY("") {
110104
@Override
111105
public boolean is(Platform compareWith) {
112-
return true;
106+
return this == compareWith;
113107
}
114108
};
115109

@@ -230,7 +224,17 @@ private static boolean isBetterMatch(String previous, String matcher) {
230224
* @return true if platforms are approximately similar, false otherwise
231225
*/
232226
public boolean is(Platform compareWith) {
233-
return this.equals(compareWith);
227+
return this == compareWith || this.family().is(compareWith);
228+
}
229+
230+
/**
231+
* Returns a platform that represents a family for the current platform. For instance
232+
* the LINUX if a part of the UNIX family, the XP is a part of the WINDOWS family.
233+
*
234+
* @return the family platform for the current one
235+
*/
236+
public Platform family() {
237+
return ANY;
234238
}
235239

236240
private boolean isCurrentPlatform(String osName, String matchAgainst) {

java/client/test/org/openqa/selenium/PlatformTest.java

+33-11
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525

2626
public class PlatformTest {
2727

28-
@Test
29-
public void testShouldIdentifyWindowsVariants() {
30-
assertAllAre(Platform.WINDOWS, "Windows 2003");
31-
}
32-
3328
@Test
3429
public void testXpIsWindows() {
3530
assertTrue(Platform.XP.is(Platform.WINDOWS));
@@ -55,6 +50,36 @@ public void testLinuxIsUnix() {
5550
assertTrue(Platform.LINUX.is(Platform.UNIX));
5651
}
5752

53+
@Test
54+
public void testUnixIsNotLinux() {
55+
assertFalse(Platform.UNIX.is(Platform.LINUX));
56+
}
57+
58+
@Test
59+
public void testXpIsAny() {
60+
assertTrue(Platform.XP.is(Platform.ANY));
61+
}
62+
63+
@Test
64+
public void testWindowsIsAny() {
65+
assertTrue(Platform.WINDOWS.is(Platform.ANY));
66+
}
67+
68+
@Test
69+
public void testLinuxIsAny() {
70+
assertTrue(Platform.LINUX.is(Platform.ANY));
71+
}
72+
73+
@Test
74+
public void testUnixIsAny() {
75+
assertTrue(Platform.UNIX.is(Platform.ANY));
76+
}
77+
78+
@Test
79+
public void testShouldIdentifyXPVariants() {
80+
assertAllAre(Platform.WINDOWS, "Windows 2003", "xp", "windows", "winnt");
81+
}
82+
5883
@Test
5984
public void testShouldIdentifyVistaVariants() {
6085
assertAllAre(Platform.VISTA, "Windows Vista", "windows server 2008", "Windows 7", "win7");
@@ -82,12 +107,9 @@ public void testWindows8Detection() {
82107
}
83108

84109
@Test
85-
public void testShouldDistinctUnixFromLinux() {
86-
Platform linPlatform = Platform.extractFromSysProperty("Linux");
87-
assertTrue("Linux should be identified as Unix", linPlatform.is(Platform.UNIX));
88-
89-
Platform anyUnixPlatform = Platform.extractFromSysProperty("solaris");
90-
assertFalse("Unix should NOT be identified as Linux", anyUnixPlatform.is(Platform.LINUX));
110+
public void testWindows81Detection() {
111+
assertEquals("Windows NT with os version 6.3 should be detected as Windows 8.1",
112+
Platform.WIN8_1, Platform.extractFromSysProperty("windows nt (unknown)", "6.3"));
91113
}
92114

93115
private void assertAllAre(Platform platform, String... osNames) {

java/server/src/org/openqa/selenium/remote/server/DefaultDriverSessions.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ protected DefaultDriverSessions(Platform runningOn, DriverFactory factory) {
7272
private void registerDefaults(Platform current) {
7373
for (Map.Entry<Capabilities, String> entry : defaultDrivers.entrySet()) {
7474
Capabilities caps = entry.getKey();
75-
if (caps.getPlatform() != null && caps.getPlatform().is(current)) {
76-
registerDriver(caps, entry.getValue());
77-
} else if (caps.getPlatform() == null) {
75+
if (caps.getPlatform() == null || caps.getPlatform() == Platform.ANY || current.is(caps.getPlatform())) {
7876
registerDriver(caps, entry.getValue());
7977
} else {
8078
log.info("Default driver " + entry.getValue() + " registration is skipped: registration capabilities "

0 commit comments

Comments
 (0)