1 19 20 package org.netbeans.test.gui.web.extbrowser.settings; 21 22 import org.netbeans.jellytools.JellyTestCase; 23 import org.netbeans.jellytools.Bundle; 24 import org.netbeans.jellytools.ExplorerOperator; 25 import org.netbeans.jellytools.OptionsOperator; 26 import org.netbeans.jellytools.NbDialogOperator; 27 28 import org.netbeans.jellytools.properties.TextFieldProperty; 29 import org.netbeans.jellytools.properties.PropertySheetTabOperator; 30 import org.netbeans.jellytools.properties.PropertySheetOperator; 31 import org.netbeans.jellytools.properties.editors.FileCustomEditorOperator; 32 33 34 35 36 import org.netbeans.test.gui.web.util.BrowserUtils; 37 38 import org.netbeans.jemmy.operators.JButtonOperator; 39 import org.netbeans.jemmy.operators.JTextFieldOperator; 40 import org.netbeans.jemmy.operators.JTextComponentOperator; 41 import org.netbeans.junit.NbTestSuite; 42 import java.io.File ; 43 44 public class BrowserRegistry extends JellyTestCase { 45 private static String workDir = null; 46 private static String webModule = null; 47 private static String wmName = "wm1"; 48 private static String fSep = System.getProperty("file.separator"); 49 private static String iSep = "|"; 50 private static String classes = "Classes"; 51 private static boolean wa = false; 52 private static String ideConfiguration = Bundle.getString("org.netbeans.core.Bundle", "UI/Services/IDEConfiguration"); 53 private static String sets = Bundle.getString("org.netbeans.core.Bundle", "UI/Services/IDEConfiguration/ServerAndExternalToolSettings"); 54 private static String browsers = Bundle.getString("org.netbeans.core.Bundle", "Services/Browsers"); 55 private static String cl = Bundle.getString("org.netbeans.modules.extbrowser.Bundle","CTL_SimpleExtBrowser"); 56 private static String ub = Bundle.getString("org.netbeans.modules.extbrowser.Bundle","CTL_UnixBrowserName"); 57 private static String pnameBrowserExecutable = Bundle.getString("org.netbeans.modules.extbrowser.Bundle" ,"PROP_browserExecutable"); 58 private static String pnameBrowserDescr = Bundle.getString("org.netbeans.modules.extbrowser.Bundle" ,"PROP_Description"); 59 public BrowserRegistry(java.lang.String testName) { 60 super(testName); 61 } 62 63 public static void main(java.lang.String [] args) { 64 junit.textui.TestRunner.run(suite()); 65 } 66 67 public static junit.framework.Test suite() { 69 workDir = System.getProperty("extbrowser.workdir").replace('/', fSep.charAt(0)); 70 webModule = workDir + fSep + wmName; 71 72 OptionsOperator oo = OptionsOperator.invoke(); 74 try { 75 oo.selectOption(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl); 76 }catch(Exception e) { 77 try { 78 sets = "ServerAndExternalToolSettings"; 79 oo.selectOption(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl); 80 wa = true; 81 }catch(Exception e1) { 82 System.err.println("BrowserRegistry:suite():Looks like something is wrong with options"); 83 } 84 } 85 oo.close(); 86 return new NbTestSuite(BrowserRegistry.class); 87 } 88 89 92 public void testChangeBrowserDescrEBCL() { 93 String newDescr = "CL Browser"; 94 OptionsOperator oo = OptionsOperator.invoke(); 95 TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserDescr); 96 pr.setValue(newDescr); 97 if (!pr.getValue().equals(newDescr)) { 98 fail("Browser Description field not editable"); 99 } 100 pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserDescr); 101 oo.close(); oo = OptionsOperator.invoke(); 103 pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserDescr); 104 if (!pr.getValue().equals(newDescr)) { 105 fail("Browser Description field not saved"); 106 } 107 } 108 109 112 113 public void testSetProcessToBrowserInPathEBCL() { 114 String newExec = "netscape {URL}"; 115 OptionsOperator oo = OptionsOperator.invoke(); 116 TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable); 117 pr.setValue(newExec); 118 if (!pr.getValue().equals(newExec)) { 119 fail("Browser Executable field not editable"); 120 } 121 oo.close(); 122 oo = OptionsOperator.invoke(); 123 pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable); 124 if (!pr.getValue().equals(newExec)) { 125 fail("Browser Executable field not saved"); 126 } 127 } 128 133 134 public void testSetProcessWithFullPathToBrowserEBCL() { 135 String newExec = fullPathCommand(); 136 OptionsOperator oo = OptionsOperator.invoke(); 137 TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable); 138 pr.openEditor(); 139 NbDialogOperator nbo = new NbDialogOperator(pnameBrowserExecutable); 140 if(!(new JTextComponentOperator(nbo, 1)).getText().equals("{URL}")) { 141 fail("Wrong default arguments field: " + (new JTextFieldOperator(nbo, 1)).getText()); 142 } 143 String custom = "..."; new JButtonOperator(nbo, custom).pushNoBlock(); 145 NbDialogOperator nbo1 = new NbDialogOperator("Open"); 146 new JTextFieldOperator(nbo1, 0).setText(newExec); 147 String openTitle = Bundle.getString("org.openide.explorer.propertysheet.editors.Bundle", "CTL_OpenButtonName"); 148 new JButtonOperator(nbo1, openTitle).push(); 149 nbo.ok(); 150 pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable); 151 if (!pr.getValue().equals(newExec + " {URL}")) { 152 fail("Browser Executable not set via editor. \"" + pr.getValue() + "\" instead of \"" + newExec + " {URL}\""); 153 } 154 oo.close(); 155 oo = OptionsOperator.invoke(); 156 pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable); 157 if (!pr.getValue().equals(newExec + " {URL}")) { 158 fail("Browser Executable field not saved, if set via editor. "+ pr.getValue() + " instead of \"" + newExec + " {URL}\""); 159 } 160 } 161 164 165 public void testChangeProcessCancelEBCL() { 166 String newExec = "UnReal"; 167 OptionsOperator oo = OptionsOperator.invoke(); 168 TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable); 169 String origExec = pr.getValue(); 170 pr.openEditor(); 171 NbDialogOperator nbo = new NbDialogOperator(pnameBrowserExecutable); 172 new JTextFieldOperator(nbo, 0).setText(newExec); 173 nbo.cancel(); 174 pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable); 175 if (!pr.getValue().equals(origExec)) { 176 fail("\"" + pr.getValue() + "\" instead of \"" + origExec + "\""); 177 } 178 } 179 180 183 184 public void testChangeArgumentsCancelEBCL() { 185 String newArg = "UnRealArgs"; 186 OptionsOperator oo = OptionsOperator.invoke(); 187 TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable); 188 String origExec = pr.getValue(); 189 pr.openEditor(); 190 NbDialogOperator nbo = new NbDialogOperator(pnameBrowserExecutable); 191 new JTextComponentOperator(nbo, 1).setText(newArg); 192 nbo.cancel(); 193 pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable); 194 if (!pr.getValue().equals(origExec)) { 195 fail("\"" + pr.getValue() + "\" instead of \"" + origExec + "\""); 196 } 197 } 198 199 202 205 public void testChangeBrowserDescrEBU() { 206 String newDescr = "CL Browser"; 207 OptionsOperator oo = OptionsOperator.invoke(); 208 TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserDescr); 209 if (pr.isEditable()) { 210 fail("Browser Description field is editable"); 211 } 212 oo.close(); 213 214 } 215 216 219 220 public void testSetProcessToBrowserInPathEBU() { 221 String newExec = "netscape {params}"; 222 OptionsOperator oo = OptionsOperator.invoke(); 223 TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable); 224 pr.setValue(newExec); 225 if (!pr.getValue().equals(newExec)) { 226 fail("Browser Executable field not editable"); 227 } 228 oo.close(); 229 oo = OptionsOperator.invoke(); 230 pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable); 231 if (!pr.getValue().equals(newExec)) { 232 fail("Browser Executable field not saved"); 233 } 234 } 235 240 241 public void testSetProcessWithFullPathToBrowserEBU() { 242 String newExec = fullPathCommand(); 243 OptionsOperator oo = OptionsOperator.invoke(); 244 TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable); 245 pr.openEditor(); 246 NbDialogOperator nbo = new NbDialogOperator(pnameBrowserExecutable); 247 if(!(new JTextComponentOperator(nbo, 1)).getText().equals("{params}")) { 248 fail("Wrong default arguments field: " + (new JTextFieldOperator(nbo, 1)).getText()); 249 } 250 String custom = "..."; new JButtonOperator(nbo, custom).pushNoBlock(); 252 System.out.println("Before wait for open"); 253 NbDialogOperator nbo1 = new NbDialogOperator("Open"); 254 System.out.println("After wait for open"); 255 new JTextFieldOperator(nbo1, 0).setText(newExec); 256 String openTitle = Bundle.getString("org.openide.explorer.propertysheet.editors.Bundle", "CTL_OpenButtonName"); 257 new JButtonOperator(nbo1, openTitle).push(); 258 nbo.ok(); 259 pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable); 260 if (!pr.getValue().equals(newExec + " {params}")) { 261 fail("Browser Executable not set via editor. \"" + pr.getValue() + "\" instead of \"" + newExec + " {params}\""); 262 } 263 oo.close(); 264 oo = OptionsOperator.invoke(); 265 pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable); 266 if (!pr.getValue().equals(newExec + " {params}")) { 267 fail("Browser Executable field not saved, if set via editor. "+ pr.getValue() + " instead of \"" + newExec + " {params}\""); 268 } 269 } 270 273 274 public void testChangeProcessCancelEBU() { 275 String newExec = "UnReal"; 276 OptionsOperator oo = OptionsOperator.invoke(); 277 TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable); 278 String origExec = pr.getValue(); 279 pr.openEditor(); 280 NbDialogOperator nbo = new NbDialogOperator(pnameBrowserExecutable); 281 new JTextFieldOperator(nbo, 0).setText(newExec); 282 nbo.cancel(); 283 pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable); 284 if (!pr.getValue().equals(origExec)) { 285 fail("\"" + pr.getValue() + "\" instead of \"" + origExec + "\""); 286 } 287 } 288 289 292 293 public void testChangeArgumentsCancelEBU() { 294 String newArg = "UnRealArgs"; 295 OptionsOperator oo = OptionsOperator.invoke(); 296 TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable); 297 String origExec = pr.getValue(); 298 pr.openEditor(); 299 NbDialogOperator nbo = new NbDialogOperator(pnameBrowserExecutable); 300 new JTextComponentOperator(nbo, 1).setText(newArg); 301 nbo.cancel(); 302 pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable); 303 if (!pr.getValue().equals(origExec)) { 304 fail("\"" + pr.getValue() + "\" instead of \"" + origExec + "\""); 305 } 306 } 307 308 312 313 private TextFieldProperty getTFProperty(String path, String pname) { 314 OptionsOperator oo = OptionsOperator.invoke(); 315 oo.selectOption(path); 316 PropertySheetOperator pso = PropertySheetOperator.invoke(); 317 PropertySheetTabOperator psto = new PropertySheetTabOperator(pso); 318 return new TextFieldProperty(psto, pname); 319 } 320 321 322 323 324 325 private static String fullPathCommand() { 326 String [] paths = null; 327 String command = null; 328 if(System.getProperty("os.name").indexOf("Windows")!=-1) { 329 fail("This test must be extended for Windows platform"); 330 }else { 331 paths = new String [] {"/usr/bin/netscape","/usr/local/bin/netscape","/bin/netscape"}; 332 } 333 for(int i=0;i<paths.length;i++) { 334 if((new File (paths[i])).exists()) { 335 command = paths[i]; 336 i = paths.length; 337 } 338 } 339 if(command == null) { 340 StringBuffer reason = new StringBuffer ("Nothing of following commands found on your system : "); 341 for(int i=0;i<paths.length;i++) { 342 reason.append(paths[i] + ";"); 343 } 344 fail(reason.toString()); 345 } 346 return command; 347 } 348 } 349 350 351 352 353 354 355 356 | Popular Tags |