8216353: Use utility APIs introduced in org/netbeans/jemmy/util/LookAndFeel class in client sanity test cases

Reviewed-by: serb
This commit is contained in:
Vikrant Agarwal 2019-03-13 00:51:28 -07:00
parent 6bd1eaf323
commit b8867e273e
8 changed files with 135 additions and 25 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -61,6 +61,7 @@ import org.netbeans.jemmy.operators.JFileChooserOperator;
import org.netbeans.jemmy.operators.JDialogOperator; import org.netbeans.jemmy.operators.JDialogOperator;
import org.netbeans.jemmy.operators.JComponentOperator.JComponentByTipFinder; import org.netbeans.jemmy.operators.JComponentOperator.JComponentByTipFinder;
import org.netbeans.jemmy.util.Platform; import org.netbeans.jemmy.util.Platform;
import org.netbeans.jemmy.util.LookAndFeel;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Listeners; import org.testng.annotations.Listeners;
import org.jemmy2ext.JemmyExt.ByToolTipChooser; import org.jemmy2ext.JemmyExt.ByToolTipChooser;
@ -141,9 +142,7 @@ public class FileChooserDemoTest {
fileChooser = new JFileChooserOperator(JFileChooserOperator.findJFileChooser((Container) frame.getSource())); fileChooser = new JFileChooserOperator(JFileChooserOperator.findJFileChooser((Container) frame.getSource()));
// In Aqua, GTK and Motif L&Fs, JFileChooser does not have // In Aqua, GTK and Motif L&Fs, JFileChooser does not have
// "Go Home", "Up One Level", "Get Details", "Get List" buttons. // "Go Home", "Up One Level", "Get Details", "Get List" buttons.
if (!UIManager.getLookAndFeel().getID().equals("Aqua") if (!LookAndFeel.isAqua() && !LookAndFeel.isMotif() && !LookAndFeel.isGTK()) {
&& !UIManager.getLookAndFeel().getID().equals("Motif")
&& !UIManager.getLookAndFeel().getID().equals("GTK")) {
File previousDirectory = fileChooser.getCurrentDirectory(); File previousDirectory = fileChooser.getCurrentDirectory();
fileChooser.goHome(); fileChooser.goHome();
// In Windows, pressing goHome navigates to Desktop inside the home directory. // In Windows, pressing goHome navigates to Desktop inside the home directory.
@ -157,7 +156,7 @@ public class FileChooserDemoTest {
fileChooser.rescanCurrentDirectory(); fileChooser.rescanCurrentDirectory();
// In Windows and Windows Classic L&F, List and Details views are // In Windows and Windows Classic L&F, List and Details views are
// implemented as a popup menu item // implemented as a popup menu item
if(UIManager.getLookAndFeel().getID().equals("Windows")) { if(LookAndFeel.isWindows() || LookAndFeel.isWindowsClassic()) {
JButtonOperator popupButton = new JButtonOperator(fileChooser, new JComponentByTipFinder( JButtonOperator popupButton = new JButtonOperator(fileChooser, new JComponentByTipFinder(
UIManager.getString("FileChooser.viewMenuButtonToolTipText", fileChooser.getLocale()))); UIManager.getString("FileChooser.viewMenuButtonToolTipText", fileChooser.getLocale())));
popupButton.push(); popupButton.push();
@ -274,8 +273,7 @@ public class FileChooserDemoTest {
fileChooserDialog = new JDialogOperator(OPEN); fileChooserDialog = new JDialogOperator(OPEN);
String openButtonText = OPEN; String openButtonText = OPEN;
// In GTK and Motif L&F, open button text is 'OK' // In GTK and Motif L&F, open button text is 'OK'
if (UIManager.getLookAndFeel().getID().equals("Motif") if (LookAndFeel.isMotif() || LookAndFeel.isGTK()) {
|| UIManager.getLookAndFeel().getID().equals("GTK")) {
openButtonText = OK; openButtonText = OK;
} }
openButton = new JButtonOperator(fileChooser, openButtonText); openButton = new JButtonOperator(fileChooser, openButtonText);

View File

@ -36,6 +36,8 @@ import org.netbeans.jemmy.ComponentChooser;
import org.netbeans.jemmy.operators.JFrameOperator; import org.netbeans.jemmy.operators.JFrameOperator;
import org.netbeans.jemmy.operators.JSliderOperator; import org.netbeans.jemmy.operators.JSliderOperator;
import org.netbeans.jemmy.accessibility.AccessibleNameChooser; import org.netbeans.jemmy.accessibility.AccessibleNameChooser;
import org.netbeans.jemmy.util.LookAndFeel;
import static com.sun.swingset3.demos.slider.SliderDemo.*; import static com.sun.swingset3.demos.slider.SliderDemo.*;
import org.testng.annotations.Listeners; import org.testng.annotations.Listeners;
@ -65,12 +67,10 @@ public class SliderDemoTest {
private static final int HORIZONTAL_MINOR_TICKS_SLIDER_MAXIMUM = 11; private static final int HORIZONTAL_MINOR_TICKS_SLIDER_MAXIMUM = 11;
private static final int VERTICAL_MINOR_TICKS_SLIDER_MINIMUM = 0; private static final int VERTICAL_MINOR_TICKS_SLIDER_MINIMUM = 0;
private static final int VERTICAL_MINOR_TICKS_SLIDER_MAXIMUM = 100; private static final int VERTICAL_MINOR_TICKS_SLIDER_MAXIMUM = 100;
private String currentLookAndFeel;
@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class) @Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)
public void test(String lookAndFeel) throws Exception { public void test(String lookAndFeel) throws Exception {
UIManager.setLookAndFeel(lookAndFeel); UIManager.setLookAndFeel(lookAndFeel);
currentLookAndFeel = lookAndFeel;
new ClassReference(SliderDemo.class.getCanonicalName()).startApplication(); new ClassReference(SliderDemo.class.getCanonicalName()).startApplication();
JFrameOperator frame = new JFrameOperator(DEMO_TITLE); JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
plain(frame, HORIZONTAL_PLAIN_SLIDER); plain(frame, HORIZONTAL_PLAIN_SLIDER);
@ -148,7 +148,7 @@ public class SliderDemoTest {
} }
private void checkKeyboard(JSliderOperator jso) { private void checkKeyboard(JSliderOperator jso) {
boolean isMotif = currentLookAndFeel.equals("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); boolean isMotif = LookAndFeel.isMotif();
checkKeyPress(jso, KeyEvent.VK_HOME, checkKeyPress(jso, KeyEvent.VK_HOME,
jSlider -> jSlider.getValue() == jso.getMinimum()); jSlider -> jSlider.getValue() == jso.getMinimum());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -41,6 +41,7 @@ import org.netbeans.jemmy.operators.JFrameOperator;
import org.netbeans.jemmy.operators.JRadioButtonOperator; import org.netbeans.jemmy.operators.JRadioButtonOperator;
import org.netbeans.jemmy.operators.JSplitPaneOperator; import org.netbeans.jemmy.operators.JSplitPaneOperator;
import org.netbeans.jemmy.operators.JTextFieldOperator; import org.netbeans.jemmy.operators.JTextFieldOperator;
import org.netbeans.jemmy.util.LookAndFeel;
import org.testng.annotations.Listeners; import org.testng.annotations.Listeners;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -76,7 +77,7 @@ public class SplitPaneDemoTest {
JSplitPaneOperator splitPane = new JSplitPaneOperator(frame); JSplitPaneOperator splitPane = new JSplitPaneOperator(frame);
// OneTouch feature is not available in GTK L&F // OneTouch feature is not available in GTK L&F
if(!"GTK".equals(UIManager.getLookAndFeel().getID())) { if(!LookAndFeel.isGTK()) {
// Toggle OneTouch Expandable // Toggle OneTouch Expandable
checkOneTouch(frame, splitPane, true); checkOneTouch(frame, splitPane, true);
checkOneTouch(frame, splitPane, false); checkOneTouch(frame, splitPane, false);
@ -89,7 +90,7 @@ public class SplitPaneDemoTest {
// TODO Skipping this code for Motif L&F as the fix for "CODETOOLS-7902324" // TODO Skipping this code for Motif L&F as the fix for "CODETOOLS-7902324"
// is deferred now // is deferred now
if(!("Motif".equals(UIManager.getLookAndFeel().getID()))) { if(!LookAndFeel.isMotif()) {
// Check moving the divider // Check moving the divider
checkDividerMoves(frame, splitPane, false); checkDividerMoves(frame, splitPane, false);
checkDividerMoves(frame, splitPane, true); checkDividerMoves(frame, splitPane, true);

View File

@ -53,6 +53,7 @@ import org.netbeans.jemmy.drivers.windows.DefaultFrameDriver;
import org.netbeans.jemmy.drivers.windows.DefaultInternalFrameDriver; import org.netbeans.jemmy.drivers.windows.DefaultInternalFrameDriver;
import org.netbeans.jemmy.drivers.windows.DefaultWindowDriver; import org.netbeans.jemmy.drivers.windows.DefaultWindowDriver;
import org.netbeans.jemmy.drivers.windows.InternalFramePopupMenuDriver; import org.netbeans.jemmy.drivers.windows.InternalFramePopupMenuDriver;
import org.netbeans.jemmy.util.LookAndFeel;
/** /**
* Installs all necessary drivers for Jemmy operators except low-level drivers * Installs all necessary drivers for Jemmy operators except low-level drivers
@ -122,9 +123,9 @@ public class DefaultDriverInstaller extends ArrayDriverInstaller {
new ChoiceDriver(), new ChoiceDriver(),
new DefaultFrameDriver(), new DefaultFrameDriver(),
new DefaultWindowDriver(), new DefaultWindowDriver(),
"Motif".equals(UIManager.getLookAndFeel().getID())? new InternalFramePopupMenuDriver(): new DefaultInternalFrameDriver(), LookAndFeel.isMotif()? new InternalFramePopupMenuDriver(): new DefaultInternalFrameDriver(),
"Motif".equals(UIManager.getLookAndFeel().getID())? new InternalFramePopupMenuDriver(): new DefaultInternalFrameDriver(), LookAndFeel.isMotif()? new InternalFramePopupMenuDriver(): new DefaultInternalFrameDriver(),
"Motif".equals(UIManager.getLookAndFeel().getID())? new InternalFramePopupMenuDriver(): new DefaultInternalFrameDriver(), LookAndFeel.isMotif()? new InternalFramePopupMenuDriver(): new DefaultInternalFrameDriver(),
new APIFocusDriver(), new APIFocusDriver(),
new MouseFocusDriver(), new MouseFocusDriver(),
(shortcutEvents ? new QueueJMenuDriver() : new DefaultJMenuDriver()), (shortcutEvents ? new QueueJMenuDriver() : new DefaultJMenuDriver()),

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -43,7 +43,6 @@ import javax.swing.JTable;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.JToggleButton; import javax.swing.JToggleButton;
import javax.swing.ListModel; import javax.swing.ListModel;
import javax.swing.UIManager;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileSystemView; import javax.swing.filechooser.FileSystemView;
import javax.swing.filechooser.FileView; import javax.swing.filechooser.FileView;
@ -60,6 +59,7 @@ import org.netbeans.jemmy.Timeoutable;
import org.netbeans.jemmy.Timeouts; import org.netbeans.jemmy.Timeouts;
import org.netbeans.jemmy.Waitable; import org.netbeans.jemmy.Waitable;
import org.netbeans.jemmy.Waiter; import org.netbeans.jemmy.Waiter;
import org.netbeans.jemmy.util.LookAndFeel;
/** /**
* *
@ -344,8 +344,7 @@ public class JFileChooserOperator extends JComponentOperator
int index = 0; int index = 0;
// In GTK and Motif L&F, there are two JLists, one is to list folders // In GTK and Motif L&F, there are two JLists, one is to list folders
// and second one one is to list files // and second one one is to list files
if (UIManager.getLookAndFeel().getID().equals("Motif") if (LookAndFeel.isMotif() || LookAndFeel.isGTK()) {
|| UIManager.getLookAndFeel().getID().equals("GTK")) {
index =1; index =1;
} }
return innerSearcher. return innerSearcher.
@ -445,7 +444,7 @@ public class JFileChooserOperator extends JComponentOperator
// In Windows and Windows Classic L&F, there is no 'Go Home' button, // In Windows and Windows Classic L&F, there is no 'Go Home' button,
// but there is a toggle button to go desktop. In Windows platform // but there is a toggle button to go desktop. In Windows platform
// 'Go Home' button usually navigates to Desktop only. // 'Go Home' button usually navigates to Desktop only.
if(UIManager.getLookAndFeel().getID().equals("Windows")) { if(LookAndFeel.isWindows() || LookAndFeel.isWindowsClassic()) {
homeOper =new JToggleButtonOperator(this, 1); homeOper =new JToggleButtonOperator(this, 1);
} else { } else {
homeOper = new JButtonOperator(getHomeButton()); homeOper = new JButtonOperator(getHomeButton());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -57,6 +57,7 @@ import org.netbeans.jemmy.drivers.FrameDriver;
import org.netbeans.jemmy.drivers.InternalFrameDriver; import org.netbeans.jemmy.drivers.InternalFrameDriver;
import org.netbeans.jemmy.drivers.WindowDriver; import org.netbeans.jemmy.drivers.WindowDriver;
import org.netbeans.jemmy.util.EmptyVisualizer; import org.netbeans.jemmy.util.EmptyVisualizer;
import org.netbeans.jemmy.util.LookAndFeel;
import org.netbeans.jemmy.util.Platform; import org.netbeans.jemmy.util.Platform;
/** /**
@ -1419,7 +1420,7 @@ public class JInternalFrameOperator extends JComponentOperator
return "JInternalFrameOperator.initOperators.ComponentChooser{description = " + getDescription() + '}'; return "JInternalFrameOperator.initOperators.ComponentChooser{description = " + getDescription() + '}';
} }
}) != null) { }) != null) {
if("Motif".equals(UIManager.getLookAndFeel().getID())) { if(LookAndFeel.isMotif()) {
popupButtonOper = new JButtonOperator(titleOperator, 0); popupButtonOper = new JButtonOperator(titleOperator, 0);
} else { } else {
minOper = new JButtonOperator(titleOperator, minOper = new JButtonOperator(titleOperator,
@ -1436,7 +1437,7 @@ public class JInternalFrameOperator extends JComponentOperator
maxOper = null; maxOper = null;
} }
if (isClosable()) { if (isClosable()) {
if(!"Motif".equals(UIManager.getLookAndFeel().getID())) { if(!LookAndFeel.isMotif()) {
closeOper = new JButtonOperator(titleOperator, closeOper = new JButtonOperator(titleOperator,
new JComponentByTipFinder(CLOSE_BUTTON_TOOLTIP)); new JComponentByTipFinder(CLOSE_BUTTON_TOOLTIP));
} }

View File

@ -0,0 +1,110 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.netbeans.jemmy.util;
import javax.swing.UIManager;
/**
* Class to provide look and feel related utility APIs
*/
public class LookAndFeel {
/**
* Checking whether the current look and feel is Metal L&F
*
* @return returns true if current look and feel is Metal L&F,
* otherwise false
*/
public static boolean isMetal() {
return isLookAndFeel("Metal");
}
/**
* Checking whether the current look and feel is Nimbus L&F
*
* @return returns true if current look and feel is Nimbus L&F,
* otherwise false
*/
public static boolean isNimbus() {
return isLookAndFeel("Nimbus");
}
/**
* Checking whether the current look and feel is Motif L&F
*
* @return returns true if current look and feel is Motif L&F,
* otherwise false
*/
public static boolean isMotif() {
return isLookAndFeel("Motif");
}
/**
* Checking whether the current look and feel is GTK L&F
*
* @return returns true if current look and feel is GTK L&F,
* otherwise false
*/
public static boolean isGTK() {
return isLookAndFeel("GTK");
}
/**
* Checking whether the current look and feel is Aqua L&F
*
* @return returns true if current look and feel is Aqua L&F,
* otherwise false
*/
public static boolean isAqua() {
return isLookAndFeel("Aqua");
}
/**
* Checking whether the current look and feel is Windows L&F
*
* @return returns true if current look and feel is Windows L&F,
* otherwise false
*/
public static boolean isWindows() {
return UIManager.getLookAndFeel().getClass().
getSimpleName().equals("WindowsLookAndFeel");
}
/**
* Checking whether the current look and feel is WindowsClassic L&F
*
* @return returns true if current look and feel is WindowsClassic L&F,
* otherwise false
*/
public static boolean isWindowsClassic() {
return UIManager.getLookAndFeel().getClass().
getSimpleName().equals("WindowsClassicLookAndFeel");
}
private static boolean isLookAndFeel(String id) {
return UIManager.getLookAndFeel().getID().equals(id);
}
}

View File

@ -1,6 +1,6 @@
Manifest-version: 1.0 Manifest-version: 1.0
Main-Class: org.netbeans.jemmy.JemmyProperties Main-Class: org.netbeans.jemmy.JemmyProperties
Jemmy-MajorVersion: 3.0 Jemmy-MajorVersion: 3.0
Jemmy-MinorVersion: 7.0 Jemmy-MinorVersion: 8.0
Jemmy-Build: @BUILD_NUMBER@ Jemmy-Build: @BUILD_NUMBER@