38 import static com.sun.swingset3.demos.filechooser.FileChooserDemo.getFlipHorizontalCount; |
38 import static com.sun.swingset3.demos.filechooser.FileChooserDemo.getFlipHorizontalCount; |
39 import static com.sun.swingset3.demos.filechooser.FileChooserDemo.getFlipVerticalCount; |
39 import static com.sun.swingset3.demos.filechooser.FileChooserDemo.getFlipVerticalCount; |
40 import static com.sun.swingset3.demos.filechooser.FileChooserDemo.getLastAppliedFilterId; |
40 import static com.sun.swingset3.demos.filechooser.FileChooserDemo.getLastAppliedFilterId; |
41 import static com.sun.swingset3.demos.filechooser.FileChooserDemo.getRotateLeftCount; |
41 import static com.sun.swingset3.demos.filechooser.FileChooserDemo.getRotateLeftCount; |
42 import static com.sun.swingset3.demos.filechooser.FileChooserDemo.getRotateRightCount; |
42 import static com.sun.swingset3.demos.filechooser.FileChooserDemo.getRotateRightCount; |
|
43 |
43 import java.awt.Container; |
44 import java.awt.Container; |
|
45 import java.awt.event.KeyEvent; |
44 import java.io.File; |
46 import java.io.File; |
45 import java.nio.file.Files; |
47 import java.nio.file.Files; |
46 import java.nio.file.Path; |
48 import java.nio.file.Path; |
47 import java.nio.file.Paths; |
49 import java.nio.file.Paths; |
48 import org.testng.annotations.Test; |
50 import org.testng.annotations.Test; |
|
51 import javax.swing.UIManager; |
|
52 |
49 import org.netbeans.jemmy.ClassReference; |
53 import org.netbeans.jemmy.ClassReference; |
50 import org.netbeans.jemmy.operators.JFrameOperator; |
54 import org.netbeans.jemmy.operators.JFrameOperator; |
|
55 import org.netbeans.jemmy.operators.JPopupMenuOperator; |
|
56 import org.netbeans.jemmy.operators.JRadioButtonMenuItemOperator; |
51 import org.netbeans.jemmy.operators.JButtonOperator; |
57 import org.netbeans.jemmy.operators.JButtonOperator; |
52 import org.netbeans.jemmy.operators.JComboBoxOperator; |
58 import org.netbeans.jemmy.operators.JComboBoxOperator; |
53 import org.netbeans.jemmy.operators.JToggleButtonOperator; |
59 import org.netbeans.jemmy.operators.JToggleButtonOperator; |
54 import org.netbeans.jemmy.operators.JFileChooserOperator; |
60 import org.netbeans.jemmy.operators.JFileChooserOperator; |
55 import org.netbeans.jemmy.operators.JDialogOperator; |
61 import org.netbeans.jemmy.operators.JDialogOperator; |
|
62 import org.netbeans.jemmy.operators.JComponentOperator.JComponentByTipFinder; |
56 import org.netbeans.jemmy.util.Platform; |
63 import org.netbeans.jemmy.util.Platform; |
57 import org.testng.annotations.BeforeTest; |
64 import org.testng.annotations.BeforeTest; |
58 import org.testng.annotations.Listeners; |
65 import org.testng.annotations.Listeners; |
59 import org.jemmy2ext.JemmyExt.ByToolTipChooser; |
66 import org.jemmy2ext.JemmyExt.ByToolTipChooser; |
60 |
67 |
70 * @library /sanity/client/lib/SwingSet3/src |
77 * @library /sanity/client/lib/SwingSet3/src |
71 * @modules java.desktop |
78 * @modules java.desktop |
72 * java.logging |
79 * java.logging |
73 * @build org.jemmy2ext.JemmyExt |
80 * @build org.jemmy2ext.JemmyExt |
74 * @build com.sun.swingset3.demos.filechooser.FileChooserDemo |
81 * @build com.sun.swingset3.demos.filechooser.FileChooserDemo |
75 * @run testng FileChooserDemoTest |
82 * @run testng/timeout=600 FileChooserDemoTest |
76 */ |
83 */ |
77 @Listeners(GuiTestListener.class) |
84 @Listeners(GuiTestListener.class) |
78 public class FileChooserDemoTest { |
85 public class FileChooserDemoTest { |
79 |
86 |
80 public static final Path TEST_SRC = Paths.get(System.getProperty("test.src")); |
87 public static final Path TEST_SRC = Paths.get(System.getProperty("test.src")); |
81 public static final Path TEST_WORK_DIR = Paths.get(System.getProperty("user.dir")); |
88 public static final Path TEST_WORK_DIR = Paths.get(System.getProperty("user.dir")); |
82 public static final Path IMAGE_DIR = TEST_SRC.resolve("resources").resolve("images"); |
89 public static final Path IMAGE_DIR = TEST_SRC.resolve("resources").resolve("images"); |
83 public static final String IMAGE = "duke.jpg"; |
90 public static final String IMAGE = "duke.jpg"; |
84 private static final String YES = "Yes"; |
91 private static final String YES = "Yes"; |
85 private static final String NO = "No"; |
92 private static final String NO = "No"; |
86 private static final String SCRATCH = "scratch"; |
|
87 private static final String OPEN = "Open"; |
93 private static final String OPEN = "Open"; |
|
94 private static final String OK = "OK"; |
88 private static final String CANCEL = "Cancel"; |
95 private static final String CANCEL = "Cancel"; |
89 private static final String USER_HOME = "user.home"; |
96 private static final String USER_HOME = "user.home"; |
90 private static final String DESKTOP = "Desktop"; |
97 private static final String DESKTOP = "Desktop"; |
91 private static final int greyFilterID = 7; |
98 private static final int greyFilterID = 7; |
92 |
99 |
114 @BeforeTest |
121 @BeforeTest |
115 public void beforeTest() throws Exception { |
122 public void beforeTest() throws Exception { |
116 Files.copy(IMAGE_DIR.resolve(IMAGE), TEST_WORK_DIR.resolve(IMAGE)); |
123 Files.copy(IMAGE_DIR.resolve(IMAGE), TEST_WORK_DIR.resolve(IMAGE)); |
117 } |
124 } |
118 |
125 |
119 @Test |
126 @Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class) |
120 public void test() throws Exception { |
127 public void test(String lookAndFeel) throws Exception { |
|
128 UIManager.setLookAndFeel(lookAndFeel); |
121 new ClassReference(FileChooserDemo.class.getCanonicalName()).startApplication(); |
129 new ClassReference(FileChooserDemo.class.getCanonicalName()).startApplication(); |
122 frame = new JFrameOperator(DEMO_TITLE); |
130 frame = new JFrameOperator(DEMO_TITLE); |
123 initializeSelectImageButtons(); |
131 initializeSelectImageButtons(); |
124 initializeImageOperationButtons(); |
132 initializeImageOperationButtons(); |
125 checkSelectImage(); |
133 checkSelectImage(); |
129 } |
137 } |
130 |
138 |
131 private void checkSelectImage() throws Exception { |
139 private void checkSelectImage() throws Exception { |
132 selectImageButton.push(); |
140 selectImageButton.push(); |
133 fileChooser = new JFileChooserOperator(JFileChooserOperator.findJFileChooser((Container) frame.getSource())); |
141 fileChooser = new JFileChooserOperator(JFileChooserOperator.findJFileChooser((Container) frame.getSource())); |
134 // In Mac, JFileChooser does not have "Go Home","Up One Level","Get Details","Get List" buttons. |
142 // In Aqua, GTK and Motif L&Fs, JFileChooser does not have |
135 if (!Platform.isOSX()) { |
143 // "Go Home", "Up One Level", "Get Details", "Get List" buttons. |
136 initializeFileChooserButtons(); |
144 if (!UIManager.getLookAndFeel().getID().equals("Aqua") |
|
145 && !UIManager.getLookAndFeel().getID().equals("Motif") |
|
146 && !UIManager.getLookAndFeel().getID().equals("GTK")) { |
137 File previousDirectory = fileChooser.getCurrentDirectory(); |
147 File previousDirectory = fileChooser.getCurrentDirectory(); |
138 fileChooser.goHome(); |
148 fileChooser.goHome(); |
139 // In Windows, pressing goHome navigates to Desktop inside the home directory. |
149 // In Windows, pressing goHome navigates to Desktop inside the home directory. |
140 // This seems to be the expected behavior for windows. |
150 // This is the expected behavior for windows. |
141 if (!Platform.isWindows()) { |
151 if (!Platform.isWindows()) { |
142 waitCurrentPath(Paths.get(System.getProperty(USER_HOME))); |
152 waitCurrentPath(Paths.get(System.getProperty(USER_HOME))); |
143 } else { |
153 } else { |
144 waitCurrentPath(Paths.get(System.getProperty(USER_HOME)).resolve(DESKTOP)); |
154 waitCurrentPath(Paths.get(System.getProperty(USER_HOME)).resolve(DESKTOP)); |
145 } |
155 } |
146 fileChooser.setCurrentDirectory(previousDirectory); |
156 fileChooser.setCurrentDirectory(previousDirectory); |
147 fileChooser.rescanCurrentDirectory(); |
157 fileChooser.rescanCurrentDirectory(); |
148 upLevelButton.push(); |
158 // In Windows and Windows Classic L&F, List and Details views are |
149 waitCurrentPath(previousDirectory.getParentFile().toPath()); |
159 // implemented as a popup menu item |
150 fileChooser.enterSubDir(SCRATCH); |
160 if(UIManager.getLookAndFeel().getID().equals("Windows")) { |
151 getListToggleButton.push(); |
161 JButtonOperator popupButton = new JButtonOperator(fileChooser, new JComponentByTipFinder( |
152 getListToggleButton.waitSelected(true); |
162 UIManager.getString("FileChooser.viewMenuButtonToolTipText", fileChooser.getLocale()))); |
153 getDetailsToggleButton.push(); |
163 popupButton.push(); |
154 getDetailsToggleButton.waitSelected(true); |
164 JPopupMenuOperator popup = new JPopupMenuOperator(); |
155 getListToggleButton.push(); |
165 popup.pushKey(KeyEvent.VK_ENTER); |
156 fileChooser.rescanCurrentDirectory(); |
166 JRadioButtonMenuItemOperator detailsMenuItem = new JRadioButtonMenuItemOperator(popup, 1); |
|
167 detailsMenuItem.push(); |
|
168 detailsMenuItem.waitSelected(true); |
|
169 popupButton.push(); |
|
170 JRadioButtonMenuItemOperator listMenuItem = new JRadioButtonMenuItemOperator(popup); |
|
171 listMenuItem.push(); |
|
172 listMenuItem.waitSelected(true); |
|
173 } else { |
|
174 initializeFileChooserButtons(); |
|
175 upLevelButton.push(); |
|
176 waitCurrentPath(previousDirectory.getParentFile().toPath()); |
|
177 fileChooser.setCurrentDirectory(previousDirectory); |
|
178 fileChooser.rescanCurrentDirectory(); |
|
179 getDetailsToggleButton.push(); |
|
180 getDetailsToggleButton.waitSelected(true); |
|
181 getListToggleButton.push(); |
|
182 getListToggleButton.waitSelected(true); |
|
183 } |
157 // Wait for the count of number of files to be 1 |
184 // Wait for the count of number of files to be 1 |
158 fileChooser.waitFileCount(1); |
185 fileChooser.waitFileCount(1); |
159 fileChooser.selectFile(IMAGE); |
186 fileChooser.selectFile(IMAGE); |
160 } else { |
187 } else { |
161 fileChooser.setCurrentDirectory(TEST_WORK_DIR.toFile()); |
188 fileChooser.setCurrentDirectory(TEST_WORK_DIR.toFile()); |
243 } |
270 } |
244 |
271 |
245 private void initializeSelectWithPreviewDialog() { |
272 private void initializeSelectWithPreviewDialog() { |
246 fileChooser = new JFileChooserOperator(); |
273 fileChooser = new JFileChooserOperator(); |
247 fileChooserDialog = new JDialogOperator(OPEN); |
274 fileChooserDialog = new JDialogOperator(OPEN); |
248 openButton = new JButtonOperator(fileChooser, OPEN); |
275 String openButtonText = OPEN; |
|
276 // In GTK and Motif L&F, open button text is 'OK' |
|
277 if (UIManager.getLookAndFeel().getID().equals("Motif") |
|
278 || UIManager.getLookAndFeel().getID().equals("GTK")) { |
|
279 openButtonText = OK; |
|
280 } |
|
281 openButton = new JButtonOperator(fileChooser, openButtonText); |
249 cancelButton = new JButtonOperator(fileChooser, CANCEL); |
282 cancelButton = new JButtonOperator(fileChooser, CANCEL); |
250 } |
283 } |
251 |
284 |
252 private void initializeImageOperationButtons() { |
285 private void initializeImageOperationButtons() { |
253 rotateLeftButton = new JButtonOperator(frame, |
286 rotateLeftButton = new JButtonOperator(frame, |