FLEX-35321 test_object_removed_from_stage_via_user_action_is_not_initialized() 
needed one more frame to complete (made sure it fails without the proposed fix, 
and passes with it). Also made some variable and function renames, plus now we 
can also test how many times each validation function has been called.


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/75b4d39d
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/75b4d39d
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/75b4d39d

Branch: refs/heads/master
Commit: 75b4d39d806d6a3bef3cd123493fe4b718f9b2c3
Parents: f475aed
Author: Mihai Chira <mih...@apache.org>
Authored: Sat Jun 10 11:52:14 2017 +0200
Committer: Mihai Chira <mih...@apache.org>
Committed: Sat Jun 10 11:52:14 2017 +0200

----------------------------------------------------------------------
 .../managers/LayoutManager_FLEX_35321_Tests.as  | 135 +++++++++++++------
 1 file changed, 96 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/75b4d39d/frameworks/projects/framework/tests/mx/managers/LayoutManager_FLEX_35321_Tests.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/framework/tests/mx/managers/LayoutManager_FLEX_35321_Tests.as
 
b/frameworks/projects/framework/tests/mx/managers/LayoutManager_FLEX_35321_Tests.as
index a23d002..1fef434 100644
--- 
a/frameworks/projects/framework/tests/mx/managers/LayoutManager_FLEX_35321_Tests.as
+++ 
b/frameworks/projects/framework/tests/mx/managers/LayoutManager_FLEX_35321_Tests.as
@@ -19,101 +19,108 @@ package mx.managers {
         private static var noEnterFramesRemaining:int = NaN;
         private static const _finishNotifier:EventDispatcher = new 
EventDispatcher();
 
-        private var _objectWhichIsRemovedOnSizeValidation:SomeComponent;
+        private var _objectWhichIsRemovedAtValidation:SomeComponent;
         private var _creationCompleteCalls:int;
 
         [Before]
         public function setUp():void
         {
             _creationCompleteCalls = 0;
-            _objectWhichIsRemovedOnSizeValidation = new SomeComponent();
-            
_objectWhichIsRemovedOnSizeValidation.addEventListener(FlexEvent.CREATION_COMPLETE,
 onCreationComplete);
-            UIImpersonator.addElement(_objectWhichIsRemovedOnSizeValidation);
+            _objectWhichIsRemovedAtValidation = new SomeComponent();
+            
_objectWhichIsRemovedAtValidation.addEventListener(FlexEvent.CREATION_COMPLETE, 
onCreationComplete);
+            UIImpersonator.addChild(_objectWhichIsRemovedAtValidation);
         }
 
         [After]
         public function tearDown():void
         {
             UIImpersonator.removeAllChildren();
-            _objectWhichIsRemovedOnSizeValidation = null;
+            _objectWhichIsRemovedAtValidation = null;
         }
 
+
+        
//--------------------------------------------------------------------------
+        //
+        //  Test method
+        //
+        
//--------------------------------------------------------------------------
+
+
         [Test]
         public function 
test_object_removed_from_stage_via_code_is_not_initialized():void
         {
             //given
             
UIComponentGlobals.mx_internal::layoutManager.usePhasedInstantiation = false;
-            
_objectWhichIsRemovedOnSizeValidation.removeFromStageOnValidateProperties = 
true;
+            
_objectWhichIsRemovedAtValidation.removeFromStageOnValidateProperties = true;
 
             //when
-            _objectWhichIsRemovedOnSizeValidation.validateNow();
+            _objectWhichIsRemovedAtValidation.validateNow();
 
             //then
-            assertNull("The object was actually not removed from stage. Huh?", 
_objectWhichIsRemovedOnSizeValidation.parent);
-            assertEquals("Yep, this is the bug. Why call initialized=true on 
an object that's not on stage?", 0, _creationCompleteCalls);
+            then_assert_not_initialized();
         }
 
+
+
+        
//--------------------------------------------------------------------------
+        //
+        //  Test method
+        //
+        
//--------------------------------------------------------------------------
+
+
         [Test(async, timeout=500)]
         public function 
test_object_removed_from_stage_via_user_action_is_not_initialized():void
         {
             //given
             
UIComponentGlobals.mx_internal::layoutManager.usePhasedInstantiation = true;
-            
_objectWhichIsRemovedOnSizeValidation.removeFromStageOnValidateProperties = 
false;
+            
_objectWhichIsRemovedAtValidation.removeFromStageOnValidateProperties = false;
 
             //when
-            _objectWhichIsRemovedOnSizeValidation.invalidateDisplayList();
-            _objectWhichIsRemovedOnSizeValidation.invalidateProperties();
-            _objectWhichIsRemovedOnSizeValidation.invalidateSize();
+            _objectWhichIsRemovedAtValidation.invalidateDisplayList();
+            _objectWhichIsRemovedAtValidation.invalidateProperties();
+            _objectWhichIsRemovedAtValidation.invalidateSize();
 
             //then wait 1 frame
             noEnterFramesRemaining = 1;
             UIImpersonator.testDisplay.addEventListener(Event.ENTER_FRAME, 
onEnterFrame);
-            Async.handleEvent(this, _finishNotifier, Event.COMPLETE, 
then_remove_from_stage_in_next_frame, 300);
+            Async.handleEvent(this, _finishNotifier, Event.COMPLETE, 
then_remove_from_stage_via_callLater, 300, then_assert_not_initialized);
         }
 
-        private function then_remove_from_stage_in_next_frame(event:Event, 
passThroughData:Object):void
-        {
-            //when
-            
_objectWhichIsRemovedOnSizeValidation.pretendUserAskedForComponentRemovalInNextFrame();
 
-            //then wait 2 frames
-            noEnterFramesRemaining = 2;
-            UIImpersonator.testDisplay.addEventListener(Event.ENTER_FRAME, 
onEnterFrame);
-            Async.handleEvent(this, _finishNotifier, Event.COMPLETE, 
then_assert_not_initialized, 300);
-        }
 
-        private function then_assert_not_initialized(event:Event, 
passThroughData:Object):void
-        {
-            //then
-            assertNull("The object was actually not removed from stage. Huh?", 
_objectWhichIsRemovedOnSizeValidation.parent);
-            assertEquals("Yep, this is the bug. Why call initialized=true on 
an object that's not on stage?", 0, _creationCompleteCalls);
-        }
 
+        
//--------------------------------------------------------------------------
+        //
+        //  Test method
+        //
+        
//--------------------------------------------------------------------------
 
         [Test(async, timeout=750)]
         public function 
test_object_removed_from_stage_then_readded_is_initialized_once():void
         {
             //given
             
UIComponentGlobals.mx_internal::layoutManager.usePhasedInstantiation = true;
-            
_objectWhichIsRemovedOnSizeValidation.removeFromStageOnValidateProperties = 
false;
+            
_objectWhichIsRemovedAtValidation.removeFromStageOnValidateProperties = false;
 
             //when
-            _objectWhichIsRemovedOnSizeValidation.validateNow();
-            
_objectWhichIsRemovedOnSizeValidation.pretendUserAskedForComponentRemovalInNextFrame();
+            _objectWhichIsRemovedAtValidation.invalidateDisplayList();
+            _objectWhichIsRemovedAtValidation.invalidateProperties();
+            _objectWhichIsRemovedAtValidation.invalidateSize();
 
             //then wait 1 frame
             noEnterFramesRemaining = 1;
             UIImpersonator.testDisplay.addEventListener(Event.ENTER_FRAME, 
onEnterFrame);
-            Async.handleEvent(this, _finishNotifier, Event.COMPLETE, 
then_readd_object, 200);
+            Async.handleEvent(this, _finishNotifier, Event.COMPLETE, 
then_remove_from_stage_via_callLater, 300, then_readd_object);
         }
 
         private function then_readd_object(event:Event, 
passThroughData:Object):void
         {
             //then
-            assertNull("The object was actually not removed from stage. Huh?", 
_objectWhichIsRemovedOnSizeValidation.parent);
+            assertNull("The object was actually not removed from stage. Huh?", 
_objectWhichIsRemovedAtValidation.parent);
 
             //when
-            UIImpersonator.addElement(_objectWhichIsRemovedOnSizeValidation);
+            UIImpersonator.addElement(_objectWhichIsRemovedAtValidation);
 
             //then wait 4 frames, to make sure validation is done
             noEnterFramesRemaining = 4;
@@ -124,11 +131,43 @@ package mx.managers {
         private function then_assert_one_initialization_only(event:Event, 
passThroughData:Object):void
         {
             //then
-            assertNotNull("The object should be on stage...", 
_objectWhichIsRemovedOnSizeValidation.parent);
+            assertNotNull("The object should be on stage...", 
_objectWhichIsRemovedAtValidation.parent);
             assertEquals("When validation is interrupted half-way it should be 
complete once the object is re-added to stage", 1, _creationCompleteCalls);
         }
 
 
+        
//--------------------------------------------------------------------------
+        //
+        //  Shared test methods
+        //
+        
//--------------------------------------------------------------------------
+
+        private function then_remove_from_stage_via_callLater(event:Event, 
passThroughData:Object):void
+        {
+            //then
+            assertEquals("The first validation step should have completed by 
now", 1, _objectWhichIsRemovedAtValidation.numValidatePropertiesCalls);
+            assertEquals("But not validateSize()", 0, 
_objectWhichIsRemovedAtValidation.numValidateSizeCalls);
+            assertEquals("Nor validateDisplayList()", 0, 
_objectWhichIsRemovedAtValidation.numValidateDisplayListCalls);
+
+            //given
+            const whereToGoNext:Function = passThroughData as Function;
+
+            //when
+            
_objectWhichIsRemovedAtValidation.pretendUserAskedForComponentRemovalInNextFrame();
+
+            //then wait 2 frames
+            noEnterFramesRemaining = 3;
+            UIImpersonator.testDisplay.addEventListener(Event.ENTER_FRAME, 
onEnterFrame);
+            Async.handleEvent(this, _finishNotifier, Event.COMPLETE, 
whereToGoNext, 300);
+        }
+
+        private function then_assert_not_initialized(event:Event = null, 
passThroughData:Object = null):void
+        {
+            //then
+            assertNull("The object was actually not removed from stage. Huh?", 
_objectWhichIsRemovedAtValidation.parent);
+            assertEquals("Yep, this is the bug. Why call initialized=true on 
an object that's not on stage?", 0, _creationCompleteCalls);
+        }
+
 
 
         private static function onEnterFrame(event:Event):void
@@ -147,19 +186,20 @@ package mx.managers {
     }
 }
 
-import flash.events.TimerEvent;
-import flash.utils.Timer;
-
 import mx.core.IVisualElementContainer;
 import mx.core.UIComponent;
 
 class SomeComponent extends UIComponent
 {
     private var _removeFromStageOnValidateProperties:Boolean = false;
+    private var _numValidatePropertiesCalls:int = 0;
+    private var _numValidateSizeCalls:int = 0;
+    private var _numValidateDisplayListCalls:int = 0;
 
     override public function validateProperties():void
     {
         super.validateProperties();
+        _numValidatePropertiesCalls++;
         if(_removeFromStageOnValidateProperties)
             removeFromStage();
     }
@@ -167,11 +207,13 @@ class SomeComponent extends UIComponent
     override public function validateSize(recursive:Boolean = false):void
     {
         super.validateSize(recursive);
+        _numValidateSizeCalls++;
     }
 
     override public function validateDisplayList():void
     {
         super.validateDisplayList();
+        _numValidateDisplayListCalls++;
     }
 
     private function removeFromStage():void
@@ -194,4 +236,19 @@ class SomeComponent extends UIComponent
     {
         _removeFromStageOnValidateProperties = value;
     }
+
+    public function get numValidateDisplayListCalls():int
+    {
+        return _numValidateDisplayListCalls;
+    }
+
+    public function get numValidateSizeCalls():int
+    {
+        return _numValidateSizeCalls;
+    }
+
+    public function get numValidatePropertiesCalls():int
+    {
+        return _numValidatePropertiesCalls;
+    }
 }
\ No newline at end of file

Reply via email to