Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 318455
Collapse All | Expand All

(-)index.html (+1 lines)
Lines 20-25 Link Here
20
    <script src="./js/resource/Includes.js" type="text/javascript"></script>
20
    <script src="./js/resource/Includes.js" type="text/javascript"></script>
21
    
21
    
22
    <!-- Tests -->
22
    <!-- Tests -->
23
    <script src="./js/org/eclipse/rwt/test/tests/TestUtilTest.js" type="text/javascript"></script>
23
    <script src="./js/org/eclipse/rwt/test/tests/AnimationTest.js" type="text/javascript"></script>
24
    <script src="./js/org/eclipse/rwt/test/tests/AnimationTest.js" type="text/javascript"></script>
24
    <script src="./js/org/eclipse/rwt/test/tests/ASyncKeyEventUtilTest.js" type="text/javascript"></script>
25
    <script src="./js/org/eclipse/rwt/test/tests/ASyncKeyEventUtilTest.js" type="text/javascript"></script>
25
    <script src="./js/org/eclipse/rwt/test/tests/GCTest.js" type="text/javascript"></script>
26
    <script src="./js/org/eclipse/rwt/test/tests/GCTest.js" type="text/javascript"></script>
(-)js/org/eclipse/rwt/test/TestRunner.js (-4 / +29 lines)
Lines 16-22 Link Here
16
    this.base( arguments );
16
    this.base( arguments );
17
    qx.log.Logger.ROOT_LOGGER.setMinLevel( qx.log.Logger.LEVEL_ERROR );
17
    qx.log.Logger.ROOT_LOGGER.setMinLevel( qx.log.Logger.LEVEL_ERROR );
18
    this._FREEZEONFAIL = true; 
18
    this._FREEZEONFAIL = true; 
19
    this._NOTRYCATCH = false; // set to true for better debugging in IE
19
    this._NOTRYCATCH = false; 
20
    this._FULLSCREEN = true;
20
    this._FULLSCREEN = true;
21
    this._presenter = org.eclipse.rwt.test.Presenter.getInstance();
21
    this._presenter = org.eclipse.rwt.test.Presenter.getInstance();
22
    this._presenter.setFullScreen( this._FULLSCREEN );    
22
    this._presenter.setFullScreen( this._FULLSCREEN );    
Lines 101-106 Link Here
101
          for ( this._currentFunction in testFunctions ){   
101
          for ( this._currentFunction in testFunctions ){   
102
            this._asserts = 0;       	
102
            this._asserts = 0;       	
103
            testFunctions[ this._currentFunction ].call( obj );
103
            testFunctions[ this._currentFunction ].call( obj );
104
            this._cleanUp();
104
            this.info( this._currentFunction + " - OK ", true );
105
            this.info( this._currentFunction + " - OK ", true );
105
          }      	  
106
          }      	  
106
      	}  else {    	
107
      	}  else {    	
Lines 110-115 Link Here
110
            for ( this._currentFunction in testFunctions ){   
111
            for ( this._currentFunction in testFunctions ){   
111
              this._asserts = 0;       	
112
              this._asserts = 0;       	
112
              testFunctions[ this._currentFunction ].call( obj );
113
              testFunctions[ this._currentFunction ].call( obj );
114
              this._cleanUp();
113
              this.info( this._currentFunction + " - OK ", true );
115
              this.info( this._currentFunction + " - OK ", true );
114
            }
116
            }
115
          } catch( e ) {
117
          } catch( e ) {
Lines 133-138 Link Here
133
      this.info( "Tests done.", false );
135
      this.info( "Tests done.", false );
134
  	},
136
  	},
135
  	
137
  	
138
  	_cleanUp : function() {
139
  	  org.eclipse.rwt.test.fixture.TestUtil.clearRequestLog();
140
  	  org.eclipse.rwt.test.fixture.TestUtil.clearTimerOnceLog();
141
  	  org.eclipse.rwt.test.fixture.TestUtil.restoreAppearance();
142
  	  qx.ui.core.Widget.flushGlobalQueues();
143
  	},
144
  	
136
  	// called by Asserts.js
145
  	// called by Asserts.js
137
  	processAssert : function( assertType, expected, value, isFailed, message ) {  	  
146
  	processAssert : function( assertType, expected, value, isFailed, message ) {  	  
138
      if( isFailed ) {
147
      if( isFailed ) {
Lines 141-151 Link Here
141
        var errorMessage =   'Assert "' 
150
        var errorMessage =   'Assert "' 
142
                           + ( message ? message : this._asserts + 1 )
151
                           + ( message ? message : this._asserts + 1 )
143
                           + '", type "' 
152
                           + '", type "' 
144
                           + assertType                
153
                           + assertType
145
                           + '" failed : Expected "'
154
                           + '" failed : Expected "'
146
                           + expected
155
                           + this._getObjectSummary( expected )
147
                           + '" but found "'
156
                           + '" but found "'
148
                           + value
157
                           + this._getObjectSummary( value )
149
                           + '"';
158
                           + '"';
150
        var error = {
159
        var error = {
151
          "assert" : true,
160
          "assert" : true,
Lines 165-170 Link Here
165
      }
174
      }
166
  	},
175
  	},
167
  	
176
  	
177
  	_getObjectSummary : function( value ) {
178
  	  var result = value;
179
  	  if( value instanceof Array ) {
180
  	    result = value.join();
181
  	  } else if(    value instanceof Object 
182
  	             && !( value instanceof qx.core.Object ) )
183
  	  {
184
  	    var arr = [];
185
  	    for( var key in value ) {
186
  	      arr.push( " " + key + " : " + value[ key ] ); 
187
  	    }
188
  	    result = "{" + arr.join() + " }";
189
  	  }
190
  	  return result;
191
  	},
192
  	
168
  	_criticalFail : function( msg ) {
193
  	_criticalFail : function( msg ) {
169
  	  this._presenter.log( "Critical error: " + msg, false );
194
  	  this._presenter.log( "Critical error: " + msg, false );
170
  	  this._presenter.log( "Testrunner aborted." , false );
195
  	  this._presenter.log( "Testrunner aborted." , false );
(-)js/org/eclipse/rwt/test/fixture/TestUtil.js (-75 / +193 lines)
Lines 18-52 Link Here
18
    
18
    
19
   getElementBounds : function( node ) {
19
   getElementBounds : function( node ) {
20
      var style = node.style;
20
      var style = node.style;
21
      if( style.cssText.indexOf( "%" ) != -1 ) {
22
        throw( "getElementBounds does not support '%'!" );
23
      }
24
      var result = {
21
      var result = {
25
        top : parseInt( style.top ),
22
        top : this._parseLength( style.top ),
26
        left : parseInt( style.left ),
23
        left : this._parseLength( style.left ),
27
        width : parseInt( style.width ),
24
        width : this._parseLength( style.width ),
28
        height : parseInt( style.height )        
25
        height : this._parseLength( style.height )        
29
      };
26
      };
30
      try {
27
      try {
31
        var ps = node.parentNode.style;
28
        var ps = node.parentNode.style;
32
        if( ps.cssText.indexOf( "%" ) != -1 ) {
29
        result.right =   this._parseLength( ps.width ) 
33
          throw( "getElementBounds does not support '%'!" );
30
                       - this._parseLength( ps.borderLeftWidth || 0 ) 
34
        }
31
                       - this._parseLength( ps.borderRightWidth || 0 ) 
35
        result.right =   parseInt( ps.width ) 
36
                       - parseInt( ps.borderLeftWidth || 0 ) 
37
                       - parseInt( ps.borderRightWidth || 0 ) 
38
                       - ( result.left + result.width )
32
                       - ( result.left + result.width )
39
        result.bottom =   parseInt( ps.height ) 
33
        result.bottom =   this._parseLength( ps.height ) 
40
                        - parseInt( ps.borderTopWidth || 0 ) 
34
                        - this._parseLength( ps.borderTopWidth || 0 ) 
41
                        - parseInt( ps.borderBottomWidth || 0 ) 
35
                        - this._parseLength( ps.borderBottomWidth || 0 ) 
42
                        - ( result.top + result.height );
36
                        - ( result.top + result.height );
43
      } catch( e ) {
37
      } catch( e ) {
44
        this.printStackTrace();
38
        throw( "Could not get bounds: no parentNode!" );
45
        throw( " could not get bounds: no parentNode!" );
39
      }
40
      return result;
41
    },
42
    
43
    _parseLength : function( value ) {
44
      var result = value ? parseInt( value ) : 0;
45
      if(    result != 0 
46
          && typeof value == "string" 
47
          && value.indexOf( "px" ) == -1 ) 
48
      {
49
        throw "getElementBounds only supports \"px\" but found " + value;
46
      }
50
      }
47
      return result;
51
      return result;
48
    },
52
    },
49
    
53
    
54
    getElementFont : function( element ) {
55
      var font = element.style.font;
56
      if( font == "" || typeof font != "string" ) {
57
        var fontData = [ 
58
          element.style.fontSize, 
59
          element.style.fontStyle,
60
          element.style.fontWeight,
61
          element.style.fontFamily
62
        ];
63
        font = fontData.join( " " );
64
      }
65
      return font;
66
    },
67
    
50
    hasElementOpacity : function( node ) {
68
    hasElementOpacity : function( node ) {
51
      return node.style.cssText.search( /opacity/i  ) != -1;
69
      return node.style.cssText.search( /opacity/i  ) != -1;
52
    },
70
    },
Lines 61-72 Link Here
61
      } else if(   node.style.backgroundImage 
79
      } else if(   node.style.backgroundImage 
62
                && node.style.backgroundImage.indexOf( 'url(' ) != -1 ) 
80
                && node.style.backgroundImage.indexOf( 'url(' ) != -1 ) 
63
      {
81
      {
64
        result = node.style.backgroundImage.slice( 4, -1 );              
82
        result = node.style.backgroundImage.slice( 4, -1 );           
65
      }
83
     }
66
      // Webkit re-writes the url in certain situations: 
84
      // Webkit re-writes the url in certain situations: 
67
      if( result.length > 0 && result == document.URL ) {
85
      if( result.length > 0 && result == document.URL ) {
68
        result = "";
86
        result = "";
69
      }
87
      }
88
      // Firefox writes quotation-marks into the URL
89
      if( result[ 0 ] == "\"" && result[ result.length -1 ] == "\"" ) {
90
        result = result.slice( 1, -1 );
91
      }
70
      return result;
92
      return result;
71
    },
93
    },
72
        
94
        
Lines 100-109 Link Here
100
    /////////////////////////////
122
    /////////////////////////////
101
    // Event handling - DOM layer
123
    // Event handling - DOM layer
102
    
124
    
103
    click : function( widget ) {
104
      this.clickDOM( widget._getTargetNode() );      
105
    },
106
    
107
    clickDOM : function( node ) {
125
    clickDOM : function( node ) {
108
      var left = qx.event.type.MouseEvent.buttons.left;
126
      var left = qx.event.type.MouseEvent.buttons.left;
109
      this.fakeMouseEventDOM( node, "mousedown", left );
127
      this.fakeMouseEventDOM( node, "mousedown", left );
Lines 111-126 Link Here
111
      this.fakeMouseEventDOM( node, "click", left );
129
      this.fakeMouseEventDOM( node, "click", left );
112
    },
130
    },
113
      
131
      
114
    rightClick : function( widget ) {
132
    shiftClickDOM : function( node ) {
115
      var right = qx.event.type.MouseEvent.buttons.right;
133
      var left = qx.event.type.MouseEvent.buttons.left;
116
      var node = widget._getTargetNode();
134
      var mod = qx.event.type.DomEvent.SHIFT_MASK;
117
      this.fakeMouseEventDOM( node, "mousedown", right );
135
      this.fakeMouseEventDOM( node, "mousedown", left, 0, 0, mod );
118
      this.fakeMouseEventDOM( node, "mouseup", right );
136
      this.fakeMouseEventDOM( node, "mouseup", left, 0, 0, mod );
119
      this.fakeMouseEventDOM( node, "click", right );
137
      this.fakeMouseEventDOM( node, "click", left, 0, 0, mod );
120
      this.fakeMouseEventDOM( node, "contextmenu", right );      
121
    },
138
    },
122
139
      
123
    fakeMouseEventDOM : function( node, type, button, left, top ) {
140
    ctrlClickDOM : function( node ) {
141
      var left = qx.event.type.MouseEvent.buttons.left;
142
      var mod = qx.event.type.DomEvent.CTRL_MASK;
143
      this.fakeMouseEventDOM( node, "mousedown", left, 0, 0, mod );
144
      this.fakeMouseEventDOM( node, "mouseup", left, 0, 0, mod );
145
      this.fakeMouseEventDOM( node, "click", left, 0, 0, mod );
146
    },
147
      
148
    fakeMouseEventDOM : function( node, type, button, left, top, mod ) {
124
      if( typeof node == "undefined" ) {
149
      if( typeof node == "undefined" ) {
125
        throw( "Error in fakeMouseEventDOM: node not defined! " );
150
        throw( "Error in fakeMouseEventDOM: node not defined! " );
126
      }
151
      }
Lines 130-135 Link Here
130
      if( typeof top == "undefined" ) {
155
      if( typeof top == "undefined" ) {
131
        top = 0;
156
        top = 0;
132
      }
157
      }
158
      if( typeof mod == "undefined" ) {
159
        mod = 0;
160
      }
133
      var clientX = left;
161
      var clientX = left;
134
      var clientY = top;
162
      var clientY = top;
135
      if( qx.core.Client.getEngine() == "mshtml" ) {
163
      if( qx.core.Client.getEngine() == "mshtml" ) {
Lines 137-184 Link Here
137
        clientY -= qx.bom.Viewport.getScrollTop(window);
165
        clientY -= qx.bom.Viewport.getScrollTop(window);
138
      }
166
      }
139
      var domEvent = {
167
      var domEvent = {
168
        "preventDefault" : function(){}, 
140
        "type" : type,
169
        "type" : type,
141
        "target" : node,
170
        "target" : node,
171
        "which" : 1,
142
        "button" : button,
172
        "button" : button,
143
        "pageX" : left,
173
        "pageX" : left,
144
        "pageY" : top,
174
        "pageY" : top,
145
        "clientX" : clientX,
175
        "clientX" : clientX,
146
        "clientY" : clientY,
176
        "clientY" : clientY,
147
        "screenX" : left,
177
        "screenX" : left,
148
        "screenY" : top
178
        "screenY" : top,
179
        "ctrlKey" : ( qx.event.type.DomEvent.CTRL_MASK & mod ) != 0,
180
        "altKey" :  ( qx.event.type.DomEvent.ALT_MASK  & mod ) != 0,
181
        "shiftKey" : ( qx.event.type.DomEvent.SHIFT_MASK  & mod ) != 0
149
      } 
182
      } 
150
      qx.event.handler.EventHandler.getInstance().__onmouseevent( domEvent );
183
      qx.event.handler.EventHandler.getInstance().__onmouseevent( domEvent );
151
    },
184
    },
152
185
186
    fakeKeyEventDOM : function( node, eventType, stringOrKeyCode ) {
187
      var charCode = null;
188
      var keyCode = null;
189
      var isChar = typeof stringOrKeyCode == "string";
190
      if( isChar ) {
191
        charCode = stringOrKeyCode.charCodeAt( 0 );
192
      } else {
193
        keyCode = stringOrKeyCode;
194
      }
195
      var domEvent = {
196
        target : node,
197
        type : eventType,
198
        ctrlKey : false,
199
        altKey :  false,
200
        shiftKey : false,
201
        keyCode : keyCode,
202
        charCode : charCode,
203
        isChar: isChar,
204
        pageX: 0,
205
        pageY: 0,
206
        preventDefault : function(){},
207
        stopPropagation : function(){}
208
      };
209
      var handler = qx.event.handler.KeyEventHandler.getInstance();
210
      handler._idealKeyHandler( keyCode, charCode, eventType, domEvent );
211
    },
212
    
153
    /////////////////////////////
213
    /////////////////////////////
154
    // Event handling - Qooxdoo
214
    // Event handling - Qooxdoo
155
        
215
    click : function( widget ) {
216
      this.clickDOM( widget._getTargetNode() );      
217
    },
218
    
219
    doubleClick : function( widget ) {
220
      var node = widget._getTargetNode();
221
      this.clickDOM( node );
222
      this.clickDOM( node );
223
      var left = qx.event.type.MouseEvent.buttons.left;
224
      this.fakeMouseEventDOM( node, "dblclick", left );
225
    },
226
    
227
    shiftClick : function( widget ) {
228
      var node = widget._getTargetNode();
229
      this.shiftClickDOM( node );
230
    },
231
    
232
    ctrlClick : function( widget ) {
233
      var node = widget._getTargetNode();
234
      this.ctrlClickDOM( node );
235
    },
236
    
237
    rightClick : function( widget ) {
238
      var right = qx.event.type.MouseEvent.buttons.right;
239
      var node = widget._getTargetNode();
240
      this.fakeMouseEventDOM( node, "mousedown", right );
241
      this.fakeMouseEventDOM( node, "mouseup", right );
242
      this.fakeMouseEventDOM( node, "click", right );
243
      this.fakeMouseEventDOM( node, "contextmenu", right );      
244
    },
245
156
    mouseOver : function( widget ) {
246
    mouseOver : function( widget ) {
157
      this.fakeMouseEvent( widget, "mouseover" );
247
      this.fakeMouseEvent( widget, "mouseover" );
158
    },
248
    },
159
    
249
160
    mouseMove : function( widget ) {
250
    mouseMove : function( widget ) {
161
      this.fakeMouseEvent( widget, "mousemove" );
251
      this.fakeMouseEvent( widget, "mousemove" );
162
    },
252
    },
163
    
253
164
    mouseOut : function( widget ) {
254
    mouseOut : function( widget ) {
165
      this.fakeMouseEvent( widget, "mouseout" );
255
      this.fakeMouseEvent( widget, "mouseout" );
166
    },
256
    },
167
    
257
168
    mouseFromTo : function( from, to ) {
258
    mouseFromTo : function( from, to ) {
169
      this.mouseMove( from );
259
      this.mouseMove( from );
170
      this.mouseOut( from );
260
      this.mouseOut( from );
171
      this.mouseOver( to );      
261
      this.mouseOver( to );      
172
      this.mouseMove( to );
262
      this.mouseMove( to );
173
    },
263
    },
174
    
264
175
    fakeMouseClick : function( widget, left, top ) {
265
    fakeMouseClick : function( widget, left, top ) {
176
      this.fakeMouseEvent( widget, "mousedown", left, top );
266
      this.fakeMouseEvent( widget, "mousedown", left, top );
177
      this.fakeMouseEvent( widget, "mouseup", left, top );
267
      this.fakeMouseEvent( widget, "mouseup", left, top );
178
      this.fakeMouseEvent( widget, "click", left, top );
268
      this.fakeMouseEvent( widget, "click", left, top );
179
    },
269
    },
180
    
270
271
    fakeWheel : function( widget, value ) {
272
      var ev = this._createQxMouseEvent( widget, "mousewheel" );
273
      ev.getWheelDelta = function(){ return value; };
274
      widget.dispatchEvent( ev );      
275
    },
276
181
    fakeMouseEvent : function( widget, type, left, top ) {
277
    fakeMouseEvent : function( widget, type, left, top ) {
278
      var ev = this._createQxMouseEvent( widget, type, left, top );
279
      ev.setButton( qx.event.type.MouseEvent.C_BUTTON_LEFT ); 
280
      widget.dispatchEvent( ev );
281
    },
282
283
    _createQxMouseEvent : function( widget, type, left, top ) {
182
      if( !widget._isCreated ) {
284
      if( !widget._isCreated ) {
183
        throw( "Error in testUtil.fakeMouseEvent: widget is not created" );
285
        throw( "Error in testUtil.fakeMouseEvent: widget is not created" );
184
      }
286
      }
Lines 191-197 Link Here
191
        clientX : left,
293
        clientX : left,
192
        clientY : top,
294
        clientY : top,
193
        pageX : left,
295
        pageX : left,
194
        pageY : top
296
        pageY : top,
297
        preventDefault : function(){},
298
        stopPropagation : function(){}        
195
      };
299
      };
196
      var ev = new qx.event.type.MouseEvent(
300
      var ev = new qx.event.type.MouseEvent(
197
        type, 
301
        type, 
Lines 202-217 Link Here
202
        null
306
        null
203
      );
307
      );
204
      ev.setButton( qx.event.type.MouseEvent.C_BUTTON_LEFT ); 
308
      ev.setButton( qx.event.type.MouseEvent.C_BUTTON_LEFT ); 
205
      widget.dispatchEvent( ev );
309
      return ev;
206
    },
310
    },
207
    
311
208
    press : function( widget, key, checkActive ) {
312
    press : function( widget, key, checkActive ) {
209
      this.fakeKeyEvent( widget, "keydown", key, checkActive );
313
      this.fakeKeyEvent( widget, "keydown", key, checkActive );
210
      this.fakeKeyEvent( widget, "keypress", key, checkActive );
314
      this.fakeKeyEvent( widget, "keypress", key, checkActive );
211
      this.fakeKeyEvent( widget, "keyinput", key, checkActive );
315
      this.fakeKeyEvent( widget, "keyinput", key, checkActive );
212
      this.fakeKeyEvent( widget, "keyup", key, checkActive );
316
      this.fakeKeyEvent( widget, "keyup", key, checkActive );
213
    },    
317
    },    
214
    
318
215
    fakeKeyEvent : function( widget, type, key, checkActive  ) {
319
    fakeKeyEvent : function( widget, type, key, checkActive  ) {
216
      if( !widget._isCreated ) {
320
      if( !widget._isCreated ) {
217
        throw( "Error in fakeKeyEvent: " + widget + " is not created" );
321
        throw( "Error in fakeKeyEvent: " + widget + " is not created" );
Lines 236-269 Link Here
236
        widget.warn( type + " not possible: " + widget.__dbKey + " not focused!" );
340
        widget.warn( type + " not possible: " + widget.__dbKey + " not focused!" );
237
      }
341
      }
238
    },
342
    },
239
    
343
240
    fakeKeyEventDOM : function( node, eventType, stringOrKeyCode ) {
241
      var charCode = null;
242
      var keyCode = null;
243
      var isChar = typeof stringOrKeyCode == "string";
244
      if( isChar ) {
245
        charCode = stringOrKeyCode.charCodeAt( 0 );
246
      } else {
247
        keyCode = stringOrKeyCode;
248
      }
249
      var domEvent = {
250
        target : node,
251
        type : eventType,
252
        ctrlKey : false,
253
        altKey :  false,
254
        shiftKey : false,
255
        keyCode : keyCode,
256
        charCode : charCode,
257
        isChar: isChar,
258
        pageX: 0,
259
        pageY: 0,        
260
        preventDefault : function(){},
261
        stopPropagation : function(){}
262
      };
263
      var handler = qx.event.handler.KeyEventHandler.getInstance();
264
      handler._idealKeyHandler( keyCode, charCode, eventType, domEvent );
265
    },
266
    
267
    ////////////////
344
    ////////////////
268
    // client-server
345
    // client-server
269
        
346
        
Lines 275-289 Link Here
275
        return "";
352
        return "";
276
      } );
353
      } );
277
    },
354
    },
278
    
355
279
    getRequestLog : function() {
356
    getRequestLog : function() {
280
      return this._requestLog;
357
      return this._requestLog;
281
    },
358
    },
282
    
359
283
    getRequestsSend : function() {
360
    getRequestsSend : function() {
284
      return this._requestLog.length;
361
      return this._requestLog.length;
285
    },
362
    },
286
    
363
287
    clearRequestLog : function() {
364
    clearRequestLog : function() {
288
      org.eclipse.swt.Request.getInstance().send();        
365
      org.eclipse.swt.Request.getInstance().send();        
289
      this._requestLog = [];
366
      this._requestLog = [];
Lines 334-339 Link Here
334
      timer._oninterval();
411
      timer._oninterval();
335
    },
412
    },
336
    
413
    
414
    //////////
415
    // Theming
416
    
417
    // assumes that the set appearance-theme does never change during tests     
418
    fakeAppearance : function( appearanceId, value ) {
419
      var manager = qx.theme.manager.Appearance.getInstance();
420
      var themeName = manager.getAppearanceTheme().name;
421
      var base = manager.getAppearanceTheme().appearances;
422
      if( typeof this._appearanceBackups[ appearanceId ] == "undefined" ) {
423
        if( base[ appearanceId ] ) {
424
          this._appearanceBackups[ appearanceId ] = base[ appearanceId ];
425
        }  else {
426
          this._appearanceBackups[ appearanceId ] = false;
427
        }
428
      }
429
      base[ appearanceId ] = value;
430
      this._clearAppearanceCache();
431
    },
432
    
433
    restoreAppearance : function() {
434
      var manager = qx.theme.manager.Appearance.getInstance();
435
      var base = manager.getAppearanceTheme().appearances;
436
      for( var appearanceId in this._appearanceBackups ) {
437
        var value = this._appearanceBackups[ appearanceId ];
438
        if( value === false ) {
439
          delete base[ appearanceId ];
440
        } else {
441
          base[ appearanceId ] = value;          
442
        }
443
      }
444
      this._appearanceBackups = {};
445
      this._clearAppearanceCache();
446
    },
447
    
448
    _appearanceBackups : {},
449
    
450
    _clearAppearanceCache : function() {
451
      var manager = qx.theme.manager.Appearance.getInstance()
452
      manager.__cache[ manager.getAppearanceTheme().name ] = {};
453
    },
454
    
337
    ////////
455
    ////////
338
    // Misc
456
    // Misc
339
    
457
    
(-)js/org/eclipse/rwt/test/tests/TestUtilTest.js (+319 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 EclipseSource and others. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html
6
 *
7
 * Contributors:
8
 *   EclipseSource - initial API and implementation
9
 ******************************************************************************/
10
11
qx.Class.define( "org.eclipse.rwt.test.tests.TestUtilTest", {
12
13
  extend : qx.core.Object,
14
  
15
  members : {
16
    
17
    testGetElementBounds : function() {
18
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
19
      var parent = document.createElement( "div" );
20
      var child = document.createElement( "div" );
21
      parent.style.width = "100px";
22
      parent.style.height = "200px";
23
      parent.appendChild( child );
24
      child.style.top = "20px";
25
      child.style.left = "30px";
26
      child.style.width = "50px";
27
      child.style.height = "70px";
28
      var bounds = testUtil.getElementBounds( child );
29
      var expected = {
30
        "top" : 20,
31
        "left" : 30,
32
        "width" : 50,
33
        "height" : 70,
34
        "right" : 20,
35
        "bottom" : 110
36
      };
37
      assertEquals( expected, bounds );
38
    },
39
   
40
    testGetElementBoundsNoParent : function() {
41
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
42
      var child = document.createElement( "div" );
43
      var log = [];
44
      try {
45
        testUtil.getElementBounds( child );
46
      } catch( ex ) {
47
        log.push( ex );
48
      }
49
      assertEquals( 1, log.length );
50
    },
51
   
52
    testGetElementBoundsNoPercantageOnChild : function() {
53
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
54
      var parent = document.createElement( "div" );
55
      var child = document.createElement( "div" );
56
      parent.style.width = "100%";
57
      parent.style.height = "200px";
58
      parent.appendChild( child );
59
      child.style.top = "20px";
60
      child.style.left = "30px";
61
      child.style.width = "50px";
62
      child.style.height = "70px";
63
      var log = [];
64
      try {
65
        testUtil.getElementBounds( child );
66
      } catch( ex ) {
67
        log.push( ex );
68
      }
69
      assertEquals( 1, log.length );
70
    },
71
   
72
    testGetElementBoundsNoPercantageOnParent : function() {
73
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
74
      var parent = document.createElement( "div" );
75
      var child = document.createElement( "div" );
76
      parent.style.width = "100px";
77
      parent.style.height = "200px";
78
      parent.appendChild( child );
79
      child.style.top = "20px";
80
      child.style.left = "30px";
81
      child.style.width = "100%";
82
      child.style.height = "70px";
83
      var log = [];
84
      try {
85
        testUtil.getElementBounds( child );
86
      } catch( ex ) {
87
        log.push( ex );
88
      }
89
      assertEquals( 1, log.length );
90
    },
91
    
92
    testGetElementBoundsWidthImage : function() {
93
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
94
      var parent = document.createElement( "div" );
95
      var child = document.createElement( "div" );
96
      parent.style.width = "100px";
97
      parent.style.height = "200px";
98
      parent.appendChild( child );
99
      child.style.top = "20px";
100
      child.style.left = "30px";
101
      child.style.width = "50px";
102
      child.style.height = "70px";
103
      child.style.backgroundRepeat = "no-repeat";
104
      child.style.backgroundPosition = "center";
105
      var bounds = testUtil.getElementBounds( child );
106
      var expected = {
107
        "top" : 20,
108
        "left" : 30,
109
        "width" : 50,
110
        "height" : 70,
111
        "right" : 20,
112
        "bottom" : 110
113
      };
114
      assertEquals( expected, bounds );
115
    },   
116
    
117
    testGetElementBoundsWidthBorder : function() {
118
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
119
      var parent = document.createElement( "div" );
120
      var child = document.createElement( "div" );
121
      parent.style.width = "100px";
122
      parent.style.height = "200px";
123
      parent.style.border = "5px solid black";
124
      parent.appendChild( child );
125
      child.style.top = "20px";
126
      child.style.left = "30px";
127
      child.style.width = "50px";
128
      child.style.height = "70px";
129
      var bounds = testUtil.getElementBounds( child );
130
      var expected = {
131
        "top" : 20,
132
        "left" : 30,
133
        "width" : 50,
134
        "height" : 70,
135
        "right" : 10,
136
        "bottom" : 100
137
      };
138
      assertEquals( expected, bounds );
139
    },
140
141
    testGetElementBoundsWidthDifferentEdges : function() {
142
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
143
      var parent = document.createElement( "div" );
144
      var child = document.createElement( "div" );
145
      parent.style.width = "100px";
146
      parent.style.height = "200px";
147
      parent.style.borderWidth = "5px 4px 3px 2px";
148
      parent.appendChild( child );
149
      child.style.top = "20px";
150
      child.style.left = "30px";
151
      child.style.width = "50px";
152
      child.style.height = "70px";
153
      var bounds = testUtil.getElementBounds( child );
154
      var expected = {
155
        "top" : 20,
156
        "left" : 30,
157
        "width" : 50,
158
        "height" : 70,
159
        "right" : 14,
160
        "bottom" : 102
161
      };
162
      assertEquals( expected, bounds );
163
    },
164
    
165
    testGetCssBackgroundImage : function() {
166
      // TODO : test for IE-filter
167
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
168
      var div = document.createElement( "div" );
169
      div.style.backgroundImage = "url( test.gif )";
170
      var result = testUtil.getCssBackgroundImage( div );
171
      assertEquals( result.length - 8, result.indexOf( "test.gif" ) );
172
    },
173
    
174
    testFakeAppearance : function() {
175
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
176
      var widget = new qx.ui.basic.Terminator();
177
      widget.setAppearance( "my-appearance" );
178
      testUtil.fakeAppearance( "my-appearance", {
179
        style : function( states ) {
180
          return {
181
            backgroundImage : "my-appearance.gif"
182
          };
183
        }
184
      } );
185
      widget._renderAppearance();
186
      assertEquals( "my-appearance.gif", widget.getBackgroundImage() );
187
      widget.destroy();
188
    },
189
    
190
    testOverwriteAppearance : function() {
191
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
192
      var widget = new org.eclipse.rwt.widgets.Button( "push" );
193
      assertEquals( "push-button", widget.getAppearance() );
194
      testUtil.fakeAppearance( "push-button", {
195
        style : function( states ) {
196
          return {
197
            backgroundImage : "my-appearance.gif"
198
          };
199
        }
200
      } );
201
      widget._renderAppearance();
202
      assertEquals( "my-appearance.gif", widget.getBackgroundImage() );
203
      widget.destroy();
204
    },
205
    
206
    testDeleteFakeAppearance : function() {
207
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
208
      testUtil.fakeAppearance( "my-appearance", {
209
        style : function( states ) {
210
          return {
211
            backgroundImage : "my-appearance.gif"
212
          };
213
        }
214
      } );
215
      testUtil.restoreAppearance();
216
      var widget = new qx.ui.basic.Terminator();
217
      widget.setAppearance( "my-appearance" );
218
      widget._renderAppearance();
219
      assertNull( widget.getBackgroundImage() );
220
      widget.destroy();
221
    },
222
223
    testRestoreAppearance : function() {
224
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
225
      var widget = new org.eclipse.rwt.widgets.Button( "push" );
226
      assertEquals( "push-button", widget.getAppearance() );
227
      testUtil.fakeAppearance( "push-button", {
228
        style : function( states ) {
229
          return {
230
            backgroundImage : "my-appearance.gif"
231
          };
232
        }
233
      } );
234
      widget._renderAppearance();
235
      testUtil.restoreAppearance();
236
      widget._renderAppearance();
237
      assertNull( widget.getBackgroundImage() );
238
      widget.destroy();
239
    },
240
    
241
    testFakeWheel : function() {
242
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
243
      var widget = new qx.ui.basic.Terminator();
244
      widget.addToDocument();
245
      testUtil.flush();
246
      var log = [];
247
      widget.addEventListener( "mousewheel", function( evt ) {
248
        log.push( evt.getWheelDelta() );
249
      } );
250
      testUtil.fakeWheel( widget, 2 );
251
      testUtil.fakeWheel( widget, -3 );
252
      assertEquals( [ 2, -3 ], log );
253
      widget.destroy();
254
    },
255
    
256
    testFakeMouseEventDomModifier : function() {
257
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
258
      var widget = new qx.ui.basic.Terminator();
259
      widget.addToDocument();
260
      testUtil.flush();
261
      var log = [];
262
      widget.addEventListener( "mousedown", function( evt ) {
263
        log.push( evt.getModifiers() );
264
      } );
265
      var node = widget._getTargetNode();
266
      var left = qx.event.type.MouseEvent.buttons.left;
267
      testUtil.fakeMouseEventDOM( node, "mousedown", left, 0, 0, 0 );
268
      testUtil.fakeMouseEventDOM( node, "mousedown", left, 0, 0, 1 );
269
      testUtil.fakeMouseEventDOM( node, "mousedown", left, 0, 0, 2 );
270
      testUtil.fakeMouseEventDOM( node, "mousedown", left, 0, 0, 4 );
271
      testUtil.fakeMouseEventDOM( node, "mousedown", left, 0, 0, 7 );
272
      assertEquals( [ 0, 1, 2, 4, 7 ], log );
273
      widget.destroy();
274
    },
275
    
276
    testGetElementFontShorthand : function() {
277
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
278
      var el = document.createElement( "div" );
279
      el.style.font = "10px italic bold Arial";
280
      var font = testUtil.getElementFont( el );
281
      assertTrue( font.indexOf( "10px" ) != -1 );
282
      assertTrue( font.indexOf( "Arial" ) != -1 );
283
      assertTrue( font.indexOf( "italic" ) != -1 );
284
      assertTrue( font.indexOf( "bold" ) != -1 );
285
    },
286
287
    testGetElementFontSingleProps : function() {
288
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
289
      var el = document.createElement( "div" );
290
      el.style.font = "10px italic bold Arial";
291
      el.style.fontFamily = "Arial";
292
      el.style.fontSize = "10px";
293
      el.style.fontStyle = "italic";
294
      el.style.fontWeight = "bold";
295
      var font = testUtil.getElementFont( el );
296
      assertTrue( font.indexOf( "10px" ) != -1 );
297
      assertTrue( font.indexOf( "Arial" ) != -1 );
298
      assertTrue( font.indexOf( "italic" ) != -1 );
299
      assertTrue( font.indexOf( "bold" ) != -1 );      
300
    },
301
302
    testDoubleClick : function() {
303
      var testUtil = org.eclipse.rwt.test.fixture.TestUtil;
304
      var widget = new qx.ui.basic.Terminator();
305
      widget.addToDocument();
306
      testUtil.flush();
307
      var log = [];
308
      widget.addEventListener( "click" , function() { log.push( "click" ); } );
309
      widget.addEventListener( "dblclick" , function() { 
310
        log.push( "dblclick" ); 
311
      } );
312
      testUtil.doubleClick( widget );
313
      assertEquals( [ "click", "click", "dblclick" ], log );
314
      widget.destroy();
315
    }
316
317
  }
318
319
} );

Return to bug 318455