You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by mi...@apache.org on 2017/06/07 11:14:52 UTC

[2/2] git commit: [flex-sdk] [refs/heads/develop] - FLEX-35321 Made the unit test more realistic (by having the user's action happen in the next frame), and prevented an error when tearDown() tries to remove a component which is no longer on stage.

FLEX-35321 Made the unit test more realistic (by having the user's action happen in the next frame), and prevented an error when tearDown() tries to remove a component which is no longer on stage.


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

Branch: refs/heads/develop
Commit: 5ea79a20f07bba7aab51dd1a45057cf26c48caa0
Parents: 53a7710
Author: Mihai Chira <mi...@apache.org>
Authored: Wed Jun 7 13:04:32 2017 +0200
Committer: Mihai Chira <mi...@apache.org>
Committed: Wed Jun 7 13:04:32 2017 +0200

----------------------------------------------------------------------
 .../framework/src/mx/managers/LayoutManager.as  |  2 +-
 .../managers/LayoutManager_FLEX_35321_Tests.as  | 36 +++++++++++++++-----
 2 files changed, 28 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/5ea79a20/frameworks/projects/framework/src/mx/managers/LayoutManager.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/managers/LayoutManager.as b/frameworks/projects/framework/src/mx/managers/LayoutManager.as
index 45395ac..feebeff 100644
--- a/frameworks/projects/framework/src/mx/managers/LayoutManager.as
+++ b/frameworks/projects/framework/src/mx/managers/LayoutManager.as
@@ -780,7 +780,7 @@ public class LayoutManager extends EventDispatcher implements ILayoutManager
      */
     private function doPhasedInstantiation():void
     {
-        // trace(">>DoPhasedInstantation");
+        // trace(">>DoPhasedInstantiation");
 
         // If phasing, do only one phase: validateProperties(),
         // validateSize(), or validateDisplayList().

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/5ea79a20/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 bb969ba..47d5f14 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
@@ -1,16 +1,23 @@
 package mx.managers {
+    import flash.events.Event;
+    import flash.events.EventDispatcher;
+
     import mx.core.UIComponentGlobals;
     import mx.core.mx_internal;
     import mx.events.FlexEvent;
 
     import org.flexunit.asserts.assertFalse;
     import org.flexunit.asserts.assertNull;
+    import org.flexunit.async.Async;
     import org.fluint.uiImpersonation.UIImpersonator;
 
     use namespace mx_internal;
 
     public class LayoutManager_FLEX_35321_Tests
     {
+        private static var noEnterFramesRemaining:int = NaN;
+        private static const _finishNotifier:EventDispatcher = new EventDispatcher();
+
         private var _objectWhichIsRemovedOnSizeValidation:SomeComponent;
         private var _creationCompleteCalled:Boolean;
 
@@ -25,7 +32,7 @@ package mx.managers {
         [After]
         public function tearDown():void
         {
-            UIImpersonator.removeChild(_objectWhichIsRemovedOnSizeValidation);
+            UIImpersonator.removeAllChildren();
             _objectWhichIsRemovedOnSizeValidation = null;
         }
 
@@ -44,7 +51,7 @@ package mx.managers {
             assertFalse("Yep, this is the bug. Why call initialized=true on an object that's not on stage?", _creationCompleteCalled);
         }
 
-        [Test]
+        [Test(async, timeout=500)]
         public function test_object_removed_from_stage_via_user_action_is_not_initialized():void
         {
             //given
@@ -55,11 +62,28 @@ package mx.managers {
             _objectWhichIsRemovedOnSizeValidation.validateNow();
             _objectWhichIsRemovedOnSizeValidation.pretendUserAskedForComponentRemoval();
 
+            //then wait 2 frames
+            noEnterFramesRemaining = 2;
+            UIImpersonator.testDisplay.addEventListener(Event.ENTER_FRAME, onEnterFrame);
+            Async.handleEvent(this, _finishNotifier, Event.COMPLETE, then_assert, 300);
+        }
+
+        private function then_assert(event:Event, passThroughData:Object):void
+        {
             //then
             assertNull("The object was actually not removed from stage. Huh?", _objectWhichIsRemovedOnSizeValidation.parent);
             assertFalse("Yep, this is the bug. Why call initialized=true on an object that's not on stage?", _creationCompleteCalled);
         }
 
+        private static function onEnterFrame(event:Event):void
+        {
+            if(!--noEnterFramesRemaining)
+            {
+                UIImpersonator.testDisplay.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
+                _finishNotifier.dispatchEvent(new Event(Event.COMPLETE));
+            }
+        }
+
         private function onCreationComplete(event:FlexEvent):void
         {
             _creationCompleteCalled = true;
@@ -96,12 +120,6 @@ class SomeComponent extends UIComponent
 
     public function pretendUserAskedForComponentRemoval():void
     {
-        _timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
-        _timer.start();
-    }
-
-    private function onTimerComplete(event:TimerEvent):void
-    {
-        removeFromStage();
+        callLater(removeFromStage);
     }
 }
\ No newline at end of file