Repository: flex-sdk Updated Branches: refs/heads/develop 719cb9ab1 -> 11aa9f949
FLEX-34824: Add WaitForCondition mustella script Wait for an ActionScript condition to become true before continuing to the next step. Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/11aa9f94 Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/11aa9f94 Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/11aa9f94 Branch: refs/heads/develop Commit: 11aa9f94937f96111cafa67457aca70583465c3a Parents: 719cb9a Author: dloverin <[email protected]> Authored: Sat May 9 10:29:30 2015 -0400 Committer: dloverin <[email protected]> Committed: Sat May 9 10:29:30 2015 -0400 ---------------------------------------------------------------------- mustella/as3/src/mustella/WaitForCondition.as | 150 +++++++++++++++++++++ mustella/build.xml | 1 + 2 files changed, 151 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/11aa9f94/mustella/as3/src/mustella/WaitForCondition.as ---------------------------------------------------------------------- diff --git a/mustella/as3/src/mustella/WaitForCondition.as b/mustella/as3/src/mustella/WaitForCondition.as new file mode 100755 index 0000000..067d615 --- /dev/null +++ b/mustella/as3/src/mustella/WaitForCondition.as @@ -0,0 +1,150 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.EventDispatcher; +import flash.utils.getTimer; + +import mx.core.mx_internal; +use namespace mx_internal; + +/** + * Instead of a property, we use an event so the MXML + * compiler will wrap the code in a function for us + */ +[Event(name="condition", type="flash.events.Event")] + +/** + * Vector of conditionalValue objects. + */ +[DefaultProperty("conditionalValues")] + +/** + * WaitForCondition - waits for a condition to become true before continuing. + * + * MXML attributes: + * target (not used) + * condition + * timeout (optional) + */ +public class WaitForCondition extends TestStep +{ + public var conditionalValues:Vector.<ConditionalValue> = null; + + /** + * The value the method should return + */ + public var value:Boolean; + + private var dispatcher:EventDispatcher; + + /** + * Test the value of a property, log result if failure. + */ + override public function execute(root:DisplayObject, context:UnitTester, testCase:TestCase, testResult:TestResult):Boolean + { + super.execute(root, context, testCase, testResult); + + var cv:ConditionalValue = null; + + context.resetValue(); + dispatcher = this; + + // Use MultiResult to determine the proper value (or valueExpression, below). + if(conditionalValues){ + cv = new MultiResult().chooseCV(conditionalValues); + if(cv){ + value = cv.value; + dispatcher = cv; + } + } + + if (checkCondition()) + { + testCase.setExpirationTime(getTimer() + timeout); + return false; + } + else + { + testCase.setExpirationTime(0); + stepComplete(); + return true; + } + + } + + /** + * customize string representation + */ + override public function toString():String + { + var s:String = "WaitForCondition (condition cannot be shown) "; + return s; + } + + /** + * Called by the test case if you time out + */ + override public function timeoutCallback():void + { + testResult.doFail("Timeout waiting for condition: (condition cannot be shown) " ); + stepComplete(); + } + + /** + * Evaluate the condition. + * + * @return The value of the condition, true or false. + */ + private function checkCondition():Boolean + { + // Execute the method. + try + { + dispatchEvent(new RunCodeEvent("condition", root["document"], context, testCase, testResult)); + } + catch (e:Error) + { + TestOutput.logResult("Exception thrown executing method."); + testResult.doFail (e.getStackTrace()); + return false; + } + + if (!context.valueChanged) + TestOutput.logResult("WARNING: value was not set by method. 'value=' missing from expression?"); + + var methodValue:Object = context.value; + + if (!methodValue) + { + UnitTester.callback = checkCondition; + return true; + } + else + { + testCase.setExpirationTime(0); + stepComplete(); + return false; + } + + } + +} +} http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/11aa9f94/mustella/build.xml ---------------------------------------------------------------------- diff --git a/mustella/build.xml b/mustella/build.xml index c6d9c99..58f317c 100644 --- a/mustella/build.xml +++ b/mustella/build.xml @@ -1855,6 +1855,7 @@ <arg value="TypeInfo"/> <arg value="UnitTester"/> <arg value="VerboseMode"/> + <arg value="WaitForCondition"/> <arg value="WaitForEffectsToEnd"/> <arg value="WaitForEvent"/> <arg value="WaitForLayoutManager"/>
