Repository: flex-asjs
Updated Branches:
  refs/heads/develop 1cb8e192b -> 5c8c667cb


get checkintests to not fail again


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

Branch: refs/heads/develop
Commit: 5c8c667cb2b93860d98e210ec8201d49c02cd794
Parents: 11ef704
Author: Alex Harui <[email protected]>
Authored: Thu Nov 10 22:50:30 2016 -0800
Committer: Alex Harui <[email protected]>
Committed: Thu Nov 10 22:50:53 2016 -0800

----------------------------------------------------------------------
 build.xml                                       |   1 +
 mustella/tests/basicTests/BasicTestsApp.mxml    |  20 +-
 .../tests/basicTests/DispatchMouseClickEvent.as | 300 ++++++++++++++++++
 mustella/tests/basicTests/DispatchMouseEvent.as | 309 +++++++++++++++++++
 mustella/tests/basicTests/FlexJSContext.as      |  22 +-
 mustella/tests/basicTests/TestStep.as           | 193 ++++++++++++
 6 files changed, 833 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5c8c667c/build.xml
----------------------------------------------------------------------
diff --git a/build.xml b/build.xml
index 15af666..61caf6d 100644
--- a/build.xml
+++ b/build.xml
@@ -1398,6 +1398,7 @@
                file="${basedir}/mustella/tests/basicTests/BasicTestsApp.mxml">
             <jvmarg line="${mxmlc.jvm.args}"/>
             <arg line="-compiler.mxml.children-as-data=true" />
+            <arg line="-compiler.info.flex=false" />
             <library-path dir="${FLEX_SDK_HOME}" append="true">
                 <include name="mustella/mustella.swc"/>
                 <include name="frameworks/libs/framework.swc"/>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5c8c667c/mustella/tests/basicTests/BasicTestsApp.mxml
----------------------------------------------------------------------
diff --git a/mustella/tests/basicTests/BasicTestsApp.mxml 
b/mustella/tests/basicTests/BasicTestsApp.mxml
index 805b535..6d2635e 100644
--- a/mustella/tests/basicTests/BasicTestsApp.mxml
+++ b/mustella/tests/basicTests/BasicTestsApp.mxml
@@ -22,7 +22,25 @@ limitations under the License.
                    xmlns:js="library://ns.apache.org/flexjs/basic" 
                    xmlns:models="models.*" 
                    xmlns:controllers="controllers.*"
-                   >
+                   applicationComplete="forwardEvent(event)" >
+    <fx:Script>
+         <![CDATA[
+           import org.apache.flex.core.WrappedMovieClip;
+           
+           private var r:WrappedMovieClip;
+           override public function setRoot(r:WrappedMovieClip):void
+           {
+             this.r = r;
+             r["info"]().app = this;
+             super.setRoot(r);
+           }
+           
+           private function forwardEvent(e:Event):void
+           {
+               r.dispatchEvent(e);
+           }
+         ]]>
+    </fx:Script>
     <js:valuesImpl>
         <js:SimpleCSSValuesImpl />
     </js:valuesImpl>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5c8c667c/mustella/tests/basicTests/DispatchMouseClickEvent.as
----------------------------------------------------------------------
diff --git a/mustella/tests/basicTests/DispatchMouseClickEvent.as 
b/mustella/tests/basicTests/DispatchMouseClickEvent.as
new file mode 100644
index 0000000..7b5eba0
--- /dev/null
+++ b/mustella/tests/basicTests/DispatchMouseClickEvent.as
@@ -0,0 +1,300 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package {
+
+import flash.display.DisplayObject;
+import flash.display.DisplayObjectContainer;
+import flash.display.InteractiveObject;
+import flash.events.MouseEvent;
+import flash.geom.Point;
+import flash.text.TextField;
+
+import mx.core.mx_internal;
+use namespace mx_internal;
+
+/**
+ *  The test step that fakes a mouse event
+ *  MXML attributes:
+ *  target
+ *  type
+ *  ctrlKey (optional)
+ *  delta (optional)
+ *  localX
+ *  localY
+ *  relatedObject (optional)
+ *  shiftKey (optional)
+ *  stageX
+ *  stageY
+ *  waitTarget (optional)
+ *  waitEvent (optional)
+ *  timeout (optional);
+ */
+public class DispatchMouseClickEvent extends TestStep
+{
+
+       private static var mouseX:QName = new QName(mx_internal, "_mouseX");
+       private static var mouseY:QName = new QName(mx_internal, "_mouseY");
+
+       /**
+        *  @private
+        */
+       override public function execute(root:DisplayObject, 
context:UnitTester, testCase:TestCase, testResult:TestResult):Boolean
+       {
+               if (waitEvent && waitTarget == null)
+                       waitTarget = target;
+               return super.execute(root, context, testCase, testResult);
+       }
+
+       /**
+        *  Set the target's property to the specified value
+        */
+       override protected function doStep():void
+       {
+               UnitTester.blockFocusEvents = false;
+
+               var actualTarget:Object = context.stringToObject(target);
+               if (!(actualTarget is DisplayObject))
+                   if ("element" in actualTarget)
+                           actualTarget = actualTarget["element"];
+               if (!actualTarget)
+               {
+                       testResult.doFail("Target " + target + " not found");
+                       UnitTester.blockFocusEvents = true;
+                       return;
+               }
+               dispatchMouseEvent(actualTarget, "mouseDown");
+               dispatchMouseEvent(actualTarget, "mouseUp");
+               dispatchMouseEvent(actualTarget, "click");
+
+               UnitTester.blockFocusEvents = true;
+
+       }
+
+       private function dispatchMouseEvent(actualTarget:Object, 
type:String):void
+       {
+               var event:MouseEvent = new MouseEvent(type, true); // all mouse 
events bubble
+               event.ctrlKey = ctrlKey;
+               event.shiftKey = shiftKey;
+               event.buttonDown = type == "mouseDown";
+               event.delta = delta;
+               if (relatedObject && relatedObject.length > 0)
+               {
+                       event.relatedObject = 
InteractiveObject(context.stringToObject(relatedObject));
+               }
+               
+               var stagePt:Point;
+               if (!isNaN(localX) && !isNaN(localY))
+               {
+                       stagePt = actualTarget.localToGlobal(new Point(localX, 
localY));
+               }
+               else if (!isNaN(stageX) && !isNaN(stageY))
+               {
+                       stagePt = new Point(stageX, stageY);
+               }
+               else
+               {
+                       stagePt = actualTarget.localToGlobal(new Point(0, 0));
+               }
+        try {
+            root[mouseX] = stagePt.x;
+            root[mouseY] = stagePt.y;
+            UnitTester.setMouseXY(stagePt);
+            if (root["topLevelSystemManager"] != root)
+            {
+                root["topLevelSystemManager"][mouseX] = stagePt.x;
+                root["topLevelSystemManager"][mouseY] = stagePt.y;
+            }            
+        } catch (e:Error) {} // some scenarios don't support this
+
+               if (actualTarget is DisplayObjectContainer)
+               {
+                       var targets:Array = 
actualTarget.stage.getObjectsUnderPoint(stagePt);
+                       var arr:Array = 
UnitTester.getObjectsUnderPoint(DisplayObject(actualTarget), stagePt);
+                       targets = targets.concat(arr);
+
+                       for (var i:int = targets.length - 1; i >= 0; i--)
+                       {
+                               if (targets[i] is InteractiveObject)
+                               {
+                                       if (targets[i] is TextField && 
!targets[i].selectable)
+                                       {
+                                               actualTarget = 
targets[i].parent;
+                                               break;
+                                       }
+
+                                       if 
(isMouseTarget(InteractiveObject(targets[i])))
+                                       {
+                                               actualTarget = targets[i];
+                                               break;
+                                       }
+                               }
+/*                             else
+                               {
+                                       try
+                                       {
+                                               actualTarget = 
targets[i].parent;
+                                               while (actualTarget)
+                                               {
+                                                       if (actualTarget is 
InteractiveObject)
+                                                       {
+                                                               if 
(isMouseTarget(InteractiveObject(actualTarget)))
+                                                               {
+                                                                       break;
+                                                               }
+                                                       }
+                                                       actualTarget = 
actualTarget.parent;
+                                               }
+                                               if (actualTarget && 
actualTarget != root)
+                                                       break;
+                                       }
+                                       catch (e:Error)
+                                       {
+                                               if (actualTarget)
+                                                       break;
+                                       }
+                               }
+*/                     }
+               }
+
+               var localPt:Point = actualTarget.globalToLocal(stagePt);
+               event.localX = localPt.x;
+               event.localY = localPt.y;
+
+               if (actualTarget is TextField)
+               {
+                       if (type == "mouseDown")
+                       {
+                               var charIndex:int = 
actualTarget.getCharIndexAtPoint(event.localX, event.localY);
+                               actualTarget.setSelection(charIndex + 1, 
charIndex + 1);
+                       }
+               }
+
+               try
+               {
+                       actualTarget.dispatchEvent(event);
+               }
+               catch (e2:Error)
+               {
+                       TestOutput.logResult("Exception thrown in 
DispatchMouseClickEvent.");
+                       testResult.doFail (e2.getStackTrace()); 
+                       return;
+               }
+       }
+
+       /**
+        *  The object that receives the mouse event
+        */
+       public var target:String;
+
+       /**
+        *  The ctrlKey property on the MouseEvent (optional)
+        */
+       public var ctrlKey:Boolean;
+
+       /**
+        *  The delta property on the MouseEvent (optional)
+        */
+       public var delta:int;
+
+       /**
+        *  The localX property on the MouseEvent (optional)
+        *  Either set stageX/stageY or localX/localY, but not both.
+        */
+       public var localX:Number;
+
+       /**
+        *  The localY property on the MouseEvent (optional)
+        *  Either set stageX/stageY or localX/localY, but not both.
+        */
+       public var localY:Number;
+
+       /**
+        *  The stageX property on the MouseEvent (optional)
+        *  Either set stageX/stageY or localX/localY, but not both.
+        */
+       public var stageX:Number;
+
+       /**
+        *  The stageY property on the MouseEvent (optional)
+        *  Either set stageX/stageY or localX/localY, but not both.
+        */
+       public var stageY:Number;
+
+       /**
+        *  The shiftKey property on the MouseEvent (optional)
+        */
+       public var shiftKey:Boolean;
+
+       /**
+        *  The relatedObject property on the MouseEvent (optional)
+        */
+       public var relatedObject:String;
+
+
+    private function isMouseTarget(target:InteractiveObject):Boolean
+    {
+        if (!target.mouseEnabled)
+            return false;
+
+               // Examine parent chain for "mouseChildren" set to false:
+               try
+               {
+                       var parent:DisplayObjectContainer = target.parent;
+                       while (parent)
+                       {
+                               if (!parent.mouseChildren)
+                                       return false;
+                               parent = parent.parent;
+                       }
+               }
+               catch (e1:Error)
+               {
+               }
+
+        return true;
+    }
+
+       /**
+        *  customize string representation
+        */
+       override public function toString():String
+       {
+               var s:String = "DispatchMouseClickEvent: target = ";
+               s += target;
+               if (!isNaN(localX))
+                       s += ", localX = " + localX.toString();
+               if (!isNaN(localY))
+                       s += ", localY = " + localY.toString();
+               if (!isNaN(stageX))
+                       s += ", stageX = " + stageX.toString();
+               if (!isNaN(stageY))
+                       s += ", stageY = " + stageY.toString();
+               if (shiftKey)
+                       s += ", shiftKey = " + shiftKey.toString();
+               if (ctrlKey)
+                       s += ", ctrlKey = " + ctrlKey.toString();
+               if (relatedObject)
+                       s += ", relatedObject = " + relatedObject.toString();
+               if (delta)
+                       s += ", delta = " + delta.toString();
+               return s;
+       }
+}
+
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5c8c667c/mustella/tests/basicTests/DispatchMouseEvent.as
----------------------------------------------------------------------
diff --git a/mustella/tests/basicTests/DispatchMouseEvent.as 
b/mustella/tests/basicTests/DispatchMouseEvent.as
new file mode 100644
index 0000000..58f22a5
--- /dev/null
+++ b/mustella/tests/basicTests/DispatchMouseEvent.as
@@ -0,0 +1,309 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package {
+
+import flash.display.DisplayObject;
+import flash.display.DisplayObjectContainer;
+import flash.display.InteractiveObject;
+import flash.text.TextField;
+import flash.events.MouseEvent;
+import flash.geom.Point;
+
+import mx.core.mx_internal;
+use namespace mx_internal;
+
+/**
+ *  The test step that fakes a mouse event
+ *  MXML attributes:
+ *  target
+ *  type
+ *  ctrlKey (optional)
+ *  delta (optional)
+ *  localX
+ *  localY
+ *  relatedObject (optional)
+ *  shiftKey (optional)
+ *  stageX
+ *  stageY
+ *  waitTarget (optional)
+ *  waitEvent (optional)
+ *  timeout (optional);
+ */
+public class DispatchMouseEvent extends TestStep
+{
+       private static var mouseX:QName = new QName(mx_internal, "_mouseX");
+       private static var mouseY:QName = new QName(mx_internal, "_mouseY");
+
+       /**
+        *  @private
+        */
+       override public function execute(root:DisplayObject, 
context:UnitTester, testCase:TestCase, testResult:TestResult):Boolean
+       {
+               if (waitEvent && waitTarget == null)
+                       waitTarget = target;
+               return super.execute(root, context, testCase, testResult);
+       }
+
+       /**
+        *  Set the target's property to the specified value
+        */
+       override protected function doStep():void
+       {
+               UnitTester.blockFocusEvents = false;
+
+               var actualTarget:Object = context.stringToObject(target);
+               if (!(actualTarget is DisplayObject))
+                   if ("element" in actualTarget)
+                           actualTarget = actualTarget["element"];
+               if (!actualTarget)
+               {
+                       testResult.doFail("Target " + target + " not found");
+                       UnitTester.blockFocusEvents = false;
+                       return;
+               }
+
+               var event:MouseEvent = new MouseEvent(type, true); // all mouse 
events bubble
+               event.ctrlKey = ctrlKey;
+               event.shiftKey = shiftKey;
+               event.buttonDown = buttonDown || type == "mouseDown";
+               event.delta = delta;
+               if (relatedObject && relatedObject.length > 0)
+               {
+                       event.relatedObject = 
InteractiveObject(context.stringToObject(relatedObject));
+                       if (!event.relatedObject)
+                       {
+                               testResult.doFail("RelatedObject " + 
relatedObject + " not found");
+                               UnitTester.blockFocusEvents = false;
+                               return;
+                       }
+               }
+               
+               var stagePt:Point;
+               if (!isNaN(localX) && !isNaN(localY))
+               {
+                       stagePt = actualTarget.localToGlobal(new Point(localX, 
localY));
+               }
+               else if (!isNaN(stageX) && !isNaN(stageY))
+               {
+                       stagePt = new Point(stageX, stageY);
+               }
+               else
+               {
+                       stagePt = actualTarget.localToGlobal(new Point(0, 0));
+               }
+        try {
+            root[mouseX] = stagePt.x;
+            root[mouseY] = stagePt.y;
+            UnitTester.setMouseXY(stagePt);
+            if (root["topLevelSystemManager"] != root)
+            {
+                root["topLevelSystemManager"][mouseX] = stagePt.x;
+                root["topLevelSystemManager"][mouseY] = stagePt.y;
+            }            
+        } catch (e:Error) {}; // some scenarios don't support this
+
+               if (actualTarget is DisplayObjectContainer)
+               {
+                       var targets:Array = 
actualTarget.stage.getObjectsUnderPoint(stagePt);
+                       var arr:Array = 
UnitTester.getObjectsUnderPoint(DisplayObject(actualTarget), stagePt);
+                       targets = targets.concat(arr);
+
+                       for (var i:int = targets.length - 1; i >= 0; i--)
+                       {
+                               if (targets[i] is InteractiveObject)
+                               {
+                                       if (targets[i] is TextField && 
!targets[i].selectable)
+                                       {
+                                               actualTarget = 
targets[i].parent;
+                                               break;
+                                       }
+
+                                       if 
(isMouseTarget(InteractiveObject(targets[i])))
+                                       {
+                                               actualTarget = targets[i];
+                                               break;
+                                       }
+                               }
+/*                             else
+                               {
+                                       try
+                                       {
+                                               actualTarget = 
targets[i].parent;
+                                               while (actualTarget)
+                                               {
+                                                       if (actualTarget is 
InteractiveObject)
+                                                       {
+                                                               if 
(isMouseTarget(InteractiveObject(actualTarget)))
+                                                               {
+                                                                       break;
+                                                               }
+                                                       }
+                                                       actualTarget = 
actualTarget.parent;
+                                               }
+                                               if (actualTarget && 
actualTarget != root)
+                                                       break;
+                                       }
+                                       catch (e:Error)
+                                       {
+                                               if (actualTarget)
+                                                       break;
+                                       }
+                               }
+*/                     }
+               }
+
+               var localPt:Point = actualTarget.globalToLocal(stagePt);
+               event.localX = localPt.x;
+               event.localY = localPt.y;
+
+               if (actualTarget is TextField)
+               {
+                       if (type == "mouseDown")
+                       {
+                               var charIndex:int = 
actualTarget.getCharIndexAtPoint(event.localX, event.localY);
+                               actualTarget.setSelection(charIndex + 1, 
charIndex + 1);
+                       }
+               }
+
+               try
+               {
+                       actualTarget.dispatchEvent(event);
+               }
+               catch (e2:Error)
+               {
+                       TestOutput.logResult("Exception thrown in 
DispatchMouseClickEvent.");
+                       testResult.doFail (e2.getStackTrace()); 
+               }
+
+               UnitTester.blockFocusEvents = true;
+       }
+
+       /**
+        *  The object that receives the mouse event
+        */
+       public var target:String;
+
+       /**
+        *  The type of the event to send (mouseUp, mouseDown, etc).
+        */
+       public var type:String;
+
+       /**
+        *  The buttonDown property on the MouseEvent (optional)
+        */
+       public var buttonDown:Boolean;
+
+       /**
+        *  The ctrlKey property on the MouseEvent (optional)
+        */
+       public var ctrlKey:Boolean;
+
+       /**
+        *  The delta property on the MouseEvent (optional)
+        */
+       public var delta:int;
+
+       /**
+        *  The localX property on the MouseEvent (optional)
+        *  Either set stageX/stageY or localX/localY, but not both.
+        */
+       public var localX:Number;
+
+       /**
+        *  The localY property on the MouseEvent (optional)
+        *  Either set stageX/stageY or localX/localY, but not both.
+        */
+       public var localY:Number;
+
+       /**
+        *  The stageX property on the MouseEvent (optional)
+        *  Either set stageX/stageY or localX/localY, but not both.
+        */
+       public var stageX:Number;
+
+       /**
+        *  The stageY property on the MouseEvent (optional)
+        *  Either set stageX/stageY or localX/localY, but not both.
+        */
+       public var stageY:Number;
+
+       /**
+        *  The shiftKey property on the MouseEvent (optional)
+        */
+       public var shiftKey:Boolean;
+
+       /**
+        *  The relatedObject property on the MouseEvent (optional)
+        */
+       public var relatedObject:String;
+
+
+    private function isMouseTarget(target:InteractiveObject):Boolean
+    {
+        if (!target.mouseEnabled)
+            return false;
+
+               // Examine parent chain for "mouseChildren" set to false:
+               try
+               {
+                       var parent:DisplayObjectContainer = target.parent;
+                       while (parent)
+                       {
+                               if (!parent.mouseChildren)
+                                       return false;
+                               parent = parent.parent;
+                       }
+               }
+               catch (e1:Error)
+               {
+               }
+
+        return true;
+    }
+
+       /**
+        *  customize string representation
+        */
+       override public function toString():String
+       {
+               var s:String = "DispatchMouseEvent: target = ";
+               s += target;
+               if (type)
+                       s += ", type = " + type;
+               if (!isNaN(localX))
+                       s += ", localX = " + localX.toString();
+               if (!isNaN(localY))
+                       s += ", localY = " + localY.toString();
+               if (!isNaN(stageX))
+                       s += ", stageX = " + stageX.toString();
+               if (!isNaN(stageY))
+                       s += ", stageY = " + stageY.toString();
+               if (shiftKey)
+                       s += ", shiftKey = " + shiftKey.toString();
+               if (ctrlKey)
+                       s += ", ctrlKey = " + ctrlKey.toString();
+               if (relatedObject)
+                       s += ", relatedObject = " + relatedObject.toString();
+               if (delta)
+                       s += ", delta = " + delta.toString();
+               return s;
+       }
+}
+
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5c8c667c/mustella/tests/basicTests/FlexJSContext.as
----------------------------------------------------------------------
diff --git a/mustella/tests/basicTests/FlexJSContext.as 
b/mustella/tests/basicTests/FlexJSContext.as
index 4f03402..2482f9f 100644
--- a/mustella/tests/basicTests/FlexJSContext.as
+++ b/mustella/tests/basicTests/FlexJSContext.as
@@ -16,14 +16,14 @@
 //  limitations under the License.
 //
 
////////////////////////////////////////////////////////////////////////////////
-package 
-{
+package 
+{
 
 [Mixin]
-public class FlexJSContext
+public class FlexJSContext
 {
-       public function FlexJSContext()
-       {
+       public function FlexJSContext()
+       {
                super();
     }
     
@@ -34,10 +34,10 @@ public class FlexJSContext
        
        public static function contextFunction():Object
        {
-               return UnitTester._root["initialView"];         
-       }
-}
+               return UnitTester._root["info"]().app["initialView"];           
+       }
+}
+
+
+}
 
-
-}
-

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5c8c667c/mustella/tests/basicTests/TestStep.as
----------------------------------------------------------------------
diff --git a/mustella/tests/basicTests/TestStep.as 
b/mustella/tests/basicTests/TestStep.as
new file mode 100644
index 0000000..a2304ff
--- /dev/null
+++ b/mustella/tests/basicTests/TestStep.as
@@ -0,0 +1,193 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package {
+
+import flash.display.DisplayObject;
+import flash.events.Event;
+import flash.events.EventDispatcher;
+import flash.events.IEventDispatcher;
+import flash.utils.getTimer;
+
+/**
+ *  The abstract base class for all steps in a test case.  TestStep
+ *  cannot be used directly, instead its subclasses must be used
+ *  such as SetProperty, RunCode, Assert, etc.
+ */
+public class TestStep extends EventDispatcher
+{
+       /**
+        *  Called by the TestCase when it is time to start this step
+        *  The default implementation checks for a wait event and
+        *  returns true if there isn't one and false if there is.
+        */
+       public function execute(root:DisplayObject, context:UnitTester, 
testCase:TestCase, testResult:TestResult):Boolean
+       {
+               var tryLater:Boolean = false;
+
+               this.root = root;
+               this.context = context;
+               this.testCase = testCase;
+               this.testResult = testResult;
+
+               if (waitEvent)
+               {
+                       var actualTarget:IEventDispatcher = 
context.stringToObject(waitTarget) as IEventDispatcher;
+                       if (!(actualTarget is DisplayObject))
+                               if ("element" in actualTarget)
+                                       actualTarget = actualTarget["element"];
+                       if (!actualTarget)
+                       {
+                               // its ok if the target isn't here yet, it may 
be created during this step
+                               tryLater = true;
+                       }
+                       else
+                       {
+                UnitTester.waitEvent = waitEvent;
+                               actualTarget.addEventListener(waitEvent, 
waitEventHandler);
+                               testCase.setExpirationTime(getTimer() + 
timeout);
+                       }
+               }
+
+               if (!UnitTester.hasRTE)
+                       doStep();
+
+               // if test failed, don't bother waiting, just bail
+               if (testResult.hasStatus() || UnitTester.hasRTE)
+               {
+                       if (UnitTester.hasRTE)
+                       { 
+                               testResult.result = 1;
+                               testResult.message = UnitTester.RTEMsg;
+                               dispatchEvent(new Event("runComplete"));
+                               return true;    
+                       }
+
+                       if (waitEvent)
+                       {
+                UnitTester.waitEvent = null;
+                               actualTarget = 
context.stringToObject(waitTarget) as IEventDispatcher;
+                               if (!(actualTarget is DisplayObject))
+                                       if ("element" in actualTarget)
+                                               actualTarget = 
actualTarget["element"];
+                               actualTarget.removeEventListener(waitEvent, 
waitEventHandler);
+                               testCase.setExpirationTime(0);
+                       }
+                       return true;
+               }
+
+               if (tryLater && waitEvent)
+               {
+                       actualTarget = context.stringToObject(waitTarget) as 
IEventDispatcher;
+                       if (!(actualTarget is DisplayObject))
+                           if ("element" in actualTarget)
+                                   actualTarget = actualTarget["element"];
+                       if (!actualTarget)
+                       {
+                               testResult.doFail("Target " + waitTarget + " 
not found");
+                               return true;
+                       }
+            UnitTester.waitEvent = waitEvent;
+                       actualTarget.addEventListener(waitEvent, 
waitEventHandler);
+                       testCase.setExpirationTime(getTimer() + timeout);
+               }
+
+               return (waitEvent == null);
+       }
+
+       /**
+        *  The name of the object to listen for an event we're waiting on
+        */
+       public var waitTarget:String;
+
+       /**
+        *  The name of the event to listen for on the waitTarget
+        */
+       public var waitEvent:String;
+
+       /**
+        *  The number of milliseconds to wait before giving up
+        */
+       public var timeout:int = 3000;
+
+       /**
+        *  The TestResult for this TestCase
+        */
+       protected var testResult:TestResult;
+
+       /**
+        *  The TestCase that this step belongs to
+        */
+       protected var testCase:TestCase;
+
+       /**
+        *  The UnitTester that this step belongs to
+        */
+       protected var context:UnitTester;
+
+       /**
+        *  The root for the SWF
+        */
+       protected var root:DisplayObject;
+
+       /**
+        *  The method that gets called when it is time to perform the work in 
the step.
+        */
+       protected function doStep():void
+       {
+       }
+
+       /**
+        *  The method that gets called back when the event we're waiting on 
fires
+        */
+       protected function waitEventHandler(event:Event):void
+       {
+               stepComplete();
+       }
+
+       /**
+        *  The method that gets called when it is time to clean up the step.
+        */
+       protected function stepComplete():void
+       {
+               if (waitEvent)
+               {
+            UnitTester.waitEvent = null;
+                       var actualTarget:IEventDispatcher = 
context.stringToObject(waitTarget) as IEventDispatcher;
+                       if (!(actualTarget is DisplayObject))
+                           if ("element" in actualTarget)
+                                   actualTarget = actualTarget["element"];
+                       if (actualTarget)       // can be null if object killed 
during step
+                               actualTarget.removeEventListener(waitEvent, 
waitEventHandler);
+                       testCase.setExpirationTime(0);
+               }
+               dispatchEvent(new Event("stepComplete"));
+       }
+
+       /**
+        *  Called by the test case if you time out
+        */
+       public function timeoutCallback():void
+       {
+               testResult.doFail("Timeout waiting for " + waitEvent + " from " 
+ waitTarget);
+               stepComplete();
+       }
+
+}
+
+}

Reply via email to