|
Lines 18-25
Link Here
|
| 18 |
import junit.framework.TestCase; |
18 |
import junit.framework.TestCase; |
| 19 |
|
19 |
|
| 20 |
import org.eclipse.rwt.Fixture; |
20 |
import org.eclipse.rwt.Fixture; |
| 21 |
import org.eclipse.rwt.internal.engine.RWTFactory; |
21 |
import org.eclipse.rwt.internal.lifecycle.JSConst; |
| 22 |
import org.eclipse.rwt.internal.lifecycle.*; |
|
|
| 23 |
import org.eclipse.rwt.lifecycle.*; |
22 |
import org.eclipse.rwt.lifecycle.*; |
| 24 |
import org.eclipse.swt.SWT; |
23 |
import org.eclipse.swt.SWT; |
| 25 |
import org.eclipse.swt.events.*; |
24 |
import org.eclipse.swt.events.*; |
|
Lines 32-42
Link Here
|
| 32 |
|
31 |
|
| 33 |
private Display display; |
32 |
private Display display; |
| 34 |
private Shell shell; |
33 |
private Shell shell; |
|
|
34 |
private TextLCA textLCA; |
| 35 |
|
35 |
|
| 36 |
protected void setUp() throws Exception { |
36 |
protected void setUp() throws Exception { |
| 37 |
Fixture.setUp(); |
37 |
Fixture.setUp(); |
| 38 |
Fixture.fakePhase( PhaseId.PROCESS_ACTION ); |
38 |
Fixture.fakePhase( PhaseId.PROCESS_ACTION ); |
| 39 |
Fixture.fakeResponseWriter(); |
39 |
Fixture.fakeResponseWriter(); |
|
|
40 |
textLCA = new TextLCA(); |
| 40 |
display = new Display(); |
41 |
display = new Display(); |
| 41 |
shell = new Shell( display ); |
42 |
shell = new Shell( display ); |
| 42 |
} |
43 |
} |
|
Lines 96-102
Link Here
|
| 96 |
Fixture.markInitialized( text ); |
97 |
Fixture.markInitialized( text ); |
| 97 |
Fixture.clearPreserved(); |
98 |
Fixture.clearPreserved(); |
| 98 |
Fixture.preserveWidgets(); |
99 |
Fixture.preserveWidgets(); |
| 99 |
TextLCA textLCA = new TextLCA(); |
|
|
| 100 |
text.setText( "hello" ); |
100 |
text.setText( "hello" ); |
| 101 |
textLCA.renderChanges( text ); |
101 |
textLCA.renderChanges( text ); |
| 102 |
assertTrue( Fixture.getAllMarkup().endsWith( "setValue( \"hello\" );" ) ); |
102 |
assertTrue( Fixture.getAllMarkup().endsWith( "setValue( \"hello\" );" ) ); |
|
Lines 114-120
Link Here
|
| 114 |
Fixture.markInitialized( text ); |
114 |
Fixture.markInitialized( text ); |
| 115 |
Fixture.clearPreserved(); |
115 |
Fixture.clearPreserved(); |
| 116 |
Fixture.preserveWidgets(); |
116 |
Fixture.preserveWidgets(); |
| 117 |
TextLCA textLCA = new TextLCA(); |
|
|
| 118 |
char[] value = new char[] { 'h', 'e', 'l', 0, 'l', 'o' }; |
117 |
char[] value = new char[] { 'h', 'e', 'l', 0, 'l', 'o' }; |
| 119 |
text.setText( String.valueOf( value ) ); |
118 |
text.setText( String.valueOf( value ) ); |
| 120 |
textLCA.renderChanges( text ); |
119 |
textLCA.renderChanges( text ); |
|
Lines 163-170
Link Here
|
| 163 |
public void testSelectionWithVerifyEvent() { |
162 |
public void testSelectionWithVerifyEvent() { |
| 164 |
final java.util.List log = new ArrayList(); |
163 |
final java.util.List log = new ArrayList(); |
| 165 |
// register preserve-values phase-listener |
164 |
// register preserve-values phase-listener |
| 166 |
RWTLifeCycle lifeCycle = ( RWTLifeCycle )RWTFactory.getLifeCycleFactory().getLifeCycle(); |
|
|
| 167 |
lifeCycle.addPhaseListener( new PreserveWidgetsPhaseListener() ); |
| 168 |
final Text text = new Text( shell, SWT.NONE ); |
165 |
final Text text = new Text( shell, SWT.NONE ); |
| 169 |
shell.open(); |
166 |
shell.open(); |
| 170 |
String textId = WidgetUtil.getId( text ); |
167 |
String textId = WidgetUtil.getId( text ); |
|
Lines 240-247
Link Here
|
| 240 |
} |
237 |
} |
| 241 |
|
238 |
|
| 242 |
public void testPreserveText() { |
239 |
public void testPreserveText() { |
| 243 |
RWTLifeCycle lifeCycle = ( RWTLifeCycle )RWTFactory.getLifeCycleFactory().getLifeCycle(); |
|
|
| 244 |
lifeCycle.addPhaseListener( new PreserveWidgetsPhaseListener() ); |
| 245 |
Text text = new Text( shell, SWT.SINGLE ); |
240 |
Text text = new Text( shell, SWT.SINGLE ); |
| 246 |
shell.open(); |
241 |
shell.open(); |
| 247 |
Fixture.markInitialized( display ); |
242 |
Fixture.markInitialized( display ); |
|
Lines 262-270
Link Here
|
| 262 |
|
257 |
|
| 263 |
public void testVerifyAndModifyEvent() { |
258 |
public void testVerifyAndModifyEvent() { |
| 264 |
final java.util.List log = new ArrayList(); |
259 |
final java.util.List log = new ArrayList(); |
| 265 |
// register preserve-values phase-listener |
|
|
| 266 |
RWTLifeCycle lifeCycle = ( RWTLifeCycle )RWTFactory.getLifeCycleFactory().getLifeCycle(); |
| 267 |
lifeCycle.addPhaseListener( new PreserveWidgetsPhaseListener() ); |
| 268 |
// set up widgets to be tested |
260 |
// set up widgets to be tested |
| 269 |
final Text text = new Text( shell, SWT.NONE ); |
261 |
final Text text = new Text( shell, SWT.NONE ); |
| 270 |
shell.open(); |
262 |
shell.open(); |
|
Lines 294-305
Link Here
|
| 294 |
|
286 |
|
| 295 |
public void testTextLimit() throws IOException { |
287 |
public void testTextLimit() throws IOException { |
| 296 |
Text text = new Text( shell, SWT.NONE ); |
288 |
Text text = new Text( shell, SWT.NONE ); |
| 297 |
TextLCA lca = new TextLCA(); |
|
|
| 298 |
// run LCA one to dump the here uninteresting prolog |
289 |
// run LCA one to dump the here uninteresting prolog |
| 299 |
lca.renderChanges( text ); |
290 |
textLCA.renderChanges( text ); |
| 300 |
// Initially no textLimit must be rendered if the initial value is untouched |
291 |
// Initially no textLimit must be rendered if the initial value is untouched |
| 301 |
Fixture.fakeResponseWriter(); |
292 |
Fixture.fakeResponseWriter(); |
| 302 |
lca.renderChanges( text ); |
293 |
textLCA.renderChanges( text ); |
| 303 |
assertEquals( -1, Fixture.getAllMarkup().indexOf( "setMaxLength" ) ); |
294 |
assertEquals( -1, Fixture.getAllMarkup().indexOf( "setMaxLength" ) ); |
| 304 |
// Positive textLimit is written as setMaxLength( ... ) |
295 |
// Positive textLimit is written as setMaxLength( ... ) |
| 305 |
Fixture.fakeResponseWriter(); |
296 |
Fixture.fakeResponseWriter(); |
|
Lines 307-313
Link Here
|
| 307 |
Fixture.clearPreserved(); |
298 |
Fixture.clearPreserved(); |
| 308 |
Fixture.preserveWidgets(); |
299 |
Fixture.preserveWidgets(); |
| 309 |
text.setTextLimit( 12 ); |
300 |
text.setTextLimit( 12 ); |
| 310 |
lca.renderChanges( text ); |
301 |
textLCA.renderChanges( text ); |
| 311 |
String expected = "setMaxLength( 12 );"; |
302 |
String expected = "setMaxLength( 12 );"; |
| 312 |
assertTrue( Fixture.getAllMarkup().indexOf( expected ) != -1 ); |
303 |
assertTrue( Fixture.getAllMarkup().indexOf( expected ) != -1 ); |
| 313 |
// Negative textLimit is tread as 'no limit' |
304 |
// Negative textLimit is tread as 'no limit' |
|
Lines 316-371
Link Here
|
| 316 |
Fixture.clearPreserved(); |
307 |
Fixture.clearPreserved(); |
| 317 |
Fixture.preserveWidgets(); |
308 |
Fixture.preserveWidgets(); |
| 318 |
text.setTextLimit( -50 ); |
309 |
text.setTextLimit( -50 ); |
| 319 |
lca.renderChanges( text ); |
310 |
textLCA.renderChanges( text ); |
| 320 |
expected = "setMaxLength( null );"; |
311 |
expected = "setMaxLength( null );"; |
| 321 |
assertTrue( Fixture.getAllMarkup().indexOf( expected ) != -1 ); |
312 |
assertTrue( Fixture.getAllMarkup().indexOf( expected ) != -1 ); |
| 322 |
} |
313 |
} |
| 323 |
|
314 |
|
| 324 |
public void testEchoCharMultiLine() { |
315 |
public void testEchoCharMultiLine() throws IOException { |
| 325 |
Fixture.fakeNewRequest( display ); |
316 |
Fixture.fakeNewRequest( display ); |
| 326 |
Text text = new Text( shell, SWT.MULTI ); |
317 |
Text text = new Text( shell, SWT.MULTI ); |
| 327 |
Fixture.executeLifeCycleFromServerThread(); |
318 |
textLCA.render( text ); |
| 328 |
String markup = Fixture.getAllMarkup(); |
319 |
String markup = Fixture.getAllMarkup(); |
| 329 |
assertTrue( markup.indexOf( "setPasswordMode" ) == -1 ); |
320 |
assertTrue( markup.indexOf( "setPasswordMode" ) == -1 ); |
|
|
321 |
|
| 322 |
Fixture.preserveWidgets(); |
| 330 |
text.setEchoChar( ( char )27 ); |
323 |
text.setEchoChar( ( char )27 ); |
| 331 |
Fixture.executeLifeCycleFromServerThread(); |
324 |
textLCA.render( text ); |
| 332 |
assertTrue( markup.indexOf( "setPasswordMode" ) == -1 ); |
325 |
assertTrue( markup.indexOf( "setPasswordMode" ) == -1 ); |
| 333 |
} |
326 |
} |
| 334 |
|
327 |
|
| 335 |
public void testEchoCharSingleLine() { |
328 |
public void testEchoCharSingleLine() throws IOException { |
| 336 |
Text text = new Text( shell, SWT.SINGLE ); |
329 |
Text text = new Text( shell, SWT.SINGLE ); |
| 337 |
Fixture.markInitialized( display ); |
330 |
textLCA.render( text ); |
| 338 |
Fixture.fakeNewRequest( display ); |
|
|
| 339 |
Fixture.executeLifeCycleFromServerThread(); |
| 340 |
String markup = Fixture.getAllMarkup(); |
331 |
String markup = Fixture.getAllMarkup(); |
| 341 |
assertTrue( markup.indexOf( "setPasswordMode" ) == -1 ); |
332 |
assertTrue( markup.indexOf( "setPasswordMode" ) == -1 ); |
|
|
333 |
|
| 334 |
Fixture.preserveWidgets(); |
| 342 |
text.setEchoChar( ( char )27 ); |
335 |
text.setEchoChar( ( char )27 ); |
| 343 |
Fixture.fakeNewRequest( display ); |
336 |
textLCA.render( text ); |
| 344 |
Fixture.executeLifeCycleFromServerThread(); |
|
|
| 345 |
markup = Fixture.getAllMarkup(); |
337 |
markup = Fixture.getAllMarkup(); |
| 346 |
assertTrue( markup.indexOf( "setPasswordMode( true )" ) != -1 ); |
338 |
assertTrue( markup.indexOf( "setPasswordMode( true )" ) != -1 ); |
|
|
339 |
|
| 340 |
Fixture.preserveWidgets(); |
| 347 |
text.setEchoChar( ( char )0 ); |
341 |
text.setEchoChar( ( char )0 ); |
| 348 |
Fixture.fakeNewRequest( display ); |
342 |
textLCA.render( text ); |
| 349 |
Fixture.executeLifeCycleFromServerThread(); |
|
|
| 350 |
markup = Fixture.getAllMarkup(); |
343 |
markup = Fixture.getAllMarkup(); |
| 351 |
assertTrue( markup.indexOf( "setPasswordMode( false )" ) != -1 ); |
344 |
assertTrue( markup.indexOf( "setPasswordMode( false )" ) != -1 ); |
| 352 |
} |
345 |
} |
| 353 |
|
346 |
|
| 354 |
public void testEchoCharPassword() { |
347 |
public void testEchoCharPassword() throws IOException { |
| 355 |
Text text = new Text( shell, SWT.PASSWORD ); |
348 |
Text text = new Text( shell, SWT.PASSWORD ); |
| 356 |
Fixture.markInitialized( display ); |
349 |
textLCA.render( text ); |
| 357 |
Fixture.fakeNewRequest( display ); |
|
|
| 358 |
Fixture.executeLifeCycleFromServerThread(); |
| 359 |
String markup = Fixture.getAllMarkup(); |
350 |
String markup = Fixture.getAllMarkup(); |
| 360 |
assertTrue( markup.indexOf( "setPasswordMode( true )" ) != -1 ); |
351 |
assertTrue( markup.indexOf( "setPasswordMode( true )" ) != -1 ); |
|
|
352 |
|
| 353 |
Fixture.preserveWidgets(); |
| 361 |
text.setEchoChar( ( char )0 ); |
354 |
text.setEchoChar( ( char )0 ); |
| 362 |
Fixture.fakeNewRequest( display ); |
355 |
textLCA.render( text ); |
| 363 |
Fixture.executeLifeCycleFromServerThread(); |
|
|
| 364 |
markup = Fixture.getAllMarkup(); |
356 |
markup = Fixture.getAllMarkup(); |
| 365 |
assertTrue( markup.indexOf( "setPasswordMode( false )" ) != -1 ); |
357 |
assertTrue( markup.indexOf( "setPasswordMode( false )" ) != -1 ); |
|
|
358 |
|
| 359 |
Fixture.preserveWidgets(); |
| 366 |
text.setEchoChar( ( char )27 ); |
360 |
text.setEchoChar( ( char )27 ); |
| 367 |
Fixture.fakeNewRequest( display ); |
361 |
textLCA.render( text ); |
| 368 |
Fixture.executeLifeCycleFromServerThread(); |
|
|
| 369 |
markup = Fixture.getAllMarkup(); |
362 |
markup = Fixture.getAllMarkup(); |
| 370 |
assertTrue( markup.indexOf( "setPasswordMode( true )" ) != -1 ); |
363 |
assertTrue( markup.indexOf( "setPasswordMode( true )" ) != -1 ); |
| 371 |
} |
364 |
} |
|
Lines 493-499
Link Here
|
| 493 |
= "org.eclipse.swt.TextUtil.setHasVerifyOrModifyListener( w, true )"; |
486 |
= "org.eclipse.swt.TextUtil.setHasVerifyOrModifyListener( w, true )"; |
| 494 |
Text text = new Text( shell, SWT.READ_ONLY ); |
487 |
Text text = new Text( shell, SWT.READ_ONLY ); |
| 495 |
text.addModifyListener( createModifyListener() ); |
488 |
text.addModifyListener( createModifyListener() ); |
| 496 |
new TextLCA().renderChanges( text ); |
489 |
textLCA.renderChanges( text ); |
| 497 |
assertTrue( Fixture.getAllMarkup().indexOf( setHasModifyListener ) != -1 ); |
490 |
assertTrue( Fixture.getAllMarkup().indexOf( setHasModifyListener ) != -1 ); |
| 498 |
} |
491 |
} |
| 499 |
|
492 |
|
|
Lines 506-512
Link Here
|
| 506 |
Fixture.markInitialized( text ); |
499 |
Fixture.markInitialized( text ); |
| 507 |
Fixture.preserveWidgets(); |
500 |
Fixture.preserveWidgets(); |
| 508 |
text.setEditable( true ); |
501 |
text.setEditable( true ); |
| 509 |
new TextLCA().renderChanges( text ); |
502 |
textLCA.renderChanges( text ); |
| 510 |
assertTrue( Fixture.getAllMarkup().indexOf( setHasModifyListener ) != -1 ); |
503 |
assertTrue( Fixture.getAllMarkup().indexOf( setHasModifyListener ) != -1 ); |
| 511 |
} |
504 |
} |
| 512 |
|
505 |
|
|
Lines 515-521
Link Here
|
| 515 |
Fixture.markInitialized( text ); |
508 |
Fixture.markInitialized( text ); |
| 516 |
Fixture.preserveWidgets(); |
509 |
Fixture.preserveWidgets(); |
| 517 |
text.setText( "abc\u2028abc\u2029abc" ); |
510 |
text.setText( "abc\u2028abc\u2029abc" ); |
| 518 |
new TextLCA().renderChanges( text ); |
511 |
textLCA.renderChanges( text ); |
| 519 |
String expected = "w.setValue( \"abcabcabc\" );"; |
512 |
String expected = "w.setValue( \"abcabcabc\" );"; |
| 520 |
assertTrue( Fixture.getAllMarkup().indexOf( expected ) != -1 ); |
513 |
assertTrue( Fixture.getAllMarkup().indexOf( expected ) != -1 ); |
| 521 |
} |
514 |
} |
|
Lines 525-531
Link Here
|
| 525 |
Fixture.markInitialized( text ); |
518 |
Fixture.markInitialized( text ); |
| 526 |
Fixture.preserveWidgets(); |
519 |
Fixture.preserveWidgets(); |
| 527 |
text.setText( "abc\u2028abc\u2029abc" ); |
520 |
text.setText( "abc\u2028abc\u2029abc" ); |
| 528 |
new TextLCA().renderChanges( text ); |
521 |
textLCA.renderChanges( text ); |
| 529 |
String expected = "w.setValue( \"abcabcabc\" );"; |
522 |
String expected = "w.setValue( \"abcabcabc\" );"; |
| 530 |
assertTrue( Fixture.getAllMarkup().indexOf( expected ) != -1 ); |
523 |
assertTrue( Fixture.getAllMarkup().indexOf( expected ) != -1 ); |
| 531 |
} |
524 |
} |
|
Lines 535-541
Link Here
|
| 535 |
Fixture.markInitialized( text ); |
528 |
Fixture.markInitialized( text ); |
| 536 |
Fixture.preserveWidgets(); |
529 |
Fixture.preserveWidgets(); |
| 537 |
text.setText( "abc\u2028abc\u2029abc" ); |
530 |
text.setText( "abc\u2028abc\u2029abc" ); |
| 538 |
new TextLCA().renderChanges( text ); |
531 |
textLCA.renderChanges( text ); |
| 539 |
String expected = "w.setValue( \"abcabcabc\" );"; |
532 |
String expected = "w.setValue( \"abcabcabc\" );"; |
| 540 |
assertTrue( Fixture.getAllMarkup().indexOf( expected ) != -1 ); |
533 |
assertTrue( Fixture.getAllMarkup().indexOf( expected ) != -1 ); |
| 541 |
} |
534 |
} |