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:51 UTC
[1/2] git commit: [flex-sdk] [refs/heads/develop] - FLEX-35321 Adding
unit test (currently fails, as expected).
Repository: flex-sdk
Updated Branches:
refs/heads/develop 2750254ba -> 5ea79a20f
FLEX-35321 Adding unit test (currently fails, as expected).
Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/53a77105
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/53a77105
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/53a77105
Branch: refs/heads/develop
Commit: 53a771056b9f7c8bf7c1127a50f2bd2c7923e0c7
Parents: 2750254
Author: Mihai Chira <mi...@apache.org>
Authored: Mon Jun 5 14:14:13 2017 +0200
Committer: Mihai Chira <mi...@apache.org>
Committed: Mon Jun 5 14:14:13 2017 +0200
----------------------------------------------------------------------
.../managers/LayoutManager_FLEX_35321_Tests.as | 107 +++++++++++++++++++
1 file changed, 107 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/53a77105/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
new file mode 100644
index 0000000..bb969ba
--- /dev/null
+++ b/frameworks/projects/framework/tests/mx/managers/LayoutManager_FLEX_35321_Tests.as
@@ -0,0 +1,107 @@
+package mx.managers {
+ 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.fluint.uiImpersonation.UIImpersonator;
+
+ use namespace mx_internal;
+
+ public class LayoutManager_FLEX_35321_Tests
+ {
+ private var _objectWhichIsRemovedOnSizeValidation:SomeComponent;
+ private var _creationCompleteCalled:Boolean;
+
+ [Before]
+ public function setUp():void
+ {
+ _creationCompleteCalled = false;
+ _objectWhichIsRemovedOnSizeValidation = new SomeComponent();
+ UIImpersonator.addChild(_objectWhichIsRemovedOnSizeValidation);
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ UIImpersonator.removeChild(_objectWhichIsRemovedOnSizeValidation);
+ _objectWhichIsRemovedOnSizeValidation = null;
+ }
+
+ [Test]
+ public function test_object_removed_from_stage_via_code_is_not_initialized():void
+ {
+ //given
+ UIComponentGlobals.mx_internal::layoutManager.usePhasedInstantiation = false;
+ _objectWhichIsRemovedOnSizeValidation.addEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete);
+
+ //when
+ _objectWhichIsRemovedOnSizeValidation.validateNow();
+
+ //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);
+ }
+
+ [Test]
+ public function test_object_removed_from_stage_via_user_action_is_not_initialized():void
+ {
+ //given
+ UIComponentGlobals.mx_internal::layoutManager.usePhasedInstantiation = true;
+ _objectWhichIsRemovedOnSizeValidation.addEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete);
+
+ //when
+ _objectWhichIsRemovedOnSizeValidation.validateNow();
+ _objectWhichIsRemovedOnSizeValidation.pretendUserAskedForComponentRemoval();
+
+ //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 function onCreationComplete(event:FlexEvent):void
+ {
+ _creationCompleteCalled = true;
+ }
+ }
+}
+
+import flash.events.TimerEvent;
+import flash.utils.Timer;
+
+import mx.core.IVisualElementContainer;
+import mx.core.UIComponent;
+
+class SomeComponent extends UIComponent
+{
+ private var _timer:Timer = new Timer(1, 1);
+
+ override public function validateSize(recursive:Boolean = false):void
+ {
+ super.validateSize(recursive);
+ removeFromStage();
+ }
+
+ private function removeFromStage():void
+ {
+ if(this.parent)
+ {
+ if(this.parent is IVisualElementContainer)
+ IVisualElementContainer(this.parent).removeElement(this);
+ else
+ this.parent.removeChild(this);
+ }
+ }
+
+ public function pretendUserAskedForComponentRemoval():void
+ {
+ _timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
+ _timer.start();
+ }
+
+ private function onTimerComplete(event:TimerEvent):void
+ {
+ removeFromStage();
+ }
+}
\ No newline at end of file
[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.
Posted by mi...@apache.org.
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