http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/27eb06f5/mustella/src/main/flex/AssertNoEvent.as ---------------------------------------------------------------------- diff --git a/mustella/src/main/flex/AssertNoEvent.as b/mustella/src/main/flex/AssertNoEvent.as new file mode 100644 index 0000000..54ca0e3 --- /dev/null +++ b/mustella/src/main/flex/AssertNoEvent.as @@ -0,0 +1,80 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.IBitmapDrawable; +import flash.utils.*; +import flash.net.*; +import flash.events.*; +import flash.display.*; +import flash.geom.Matrix; + +/** + * Tests that the value of a property is as expected + * MXML attributes: + * target + * eventName + * eventType + * waitTarget (optional) + * waitEvent (optional) + * timeout (optional) + */ +public class AssertNoEvent extends AssertEvent +{ + /** + * Test the value of a property, log result if failure. + */ + override public function execute(root:DisplayObject, context:UnitTester, testCase:TestCase, testResult:TestResult):Boolean + { + return true; + } + + /** + * The event listener + */ + override protected function eventListener(event:Event):void + { + testCase.setExpirationTime(0); + + numEvents++; + + if (numEvents) + { + testResult.doFail ("Event " + eventName + " unexpectedly received " + numEvents + " times"); + return; + } + } + + /** + * customize string representation + */ + override public function toString():String + { + var s:String = "AssertNoEvent"; + if (target) + s += ": target = " + target; + if (eventName) + s += ", eventName = " + eventName; + return s; + } + +} + +}
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/27eb06f5/mustella/src/main/flex/AssertPixelValue.as ---------------------------------------------------------------------- diff --git a/mustella/src/main/flex/AssertPixelValue.as b/mustella/src/main/flex/AssertPixelValue.as new file mode 100644 index 0000000..a877fb5 --- /dev/null +++ b/mustella/src/main/flex/AssertPixelValue.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.display.IBitmapDrawable; +import flash.events.EventDispatcher; +import flash.utils.*; +import flash.net.*; +import flash.events.*; +import flash.display.*; +import flash.geom.Matrix; +import flash.geom.Point; + +import mx.core.mx_internal; +use namespace mx_internal; + +/** +* Vector of conditionalValue objects. +**/ +[DefaultProperty("conditionalValues")] + +/** + * Instead of a property, we use an event so the MXML + * compiler will wrap the code in a function for us + */ +[Event(name="valueExpression", type="flash.events.Event")] + +/** + * Tests that the value of a property is as expected + * MXML attributes: + * target + * value + * waitTarget (optional) + * waitEvent (optional) + * timeout (optional) + */ +public class AssertPixelValue extends Assert +{ + public var conditionalValues:Vector.<ConditionalValue> = null; + + /** + * Test the value of a pixel, log result if failure. + */ + override protected function doStep():void + { + var cv:ConditionalValue = null; + var dispatcher:EventDispatcher = this; + var pt:Point = new Point(x, y); + var actualTarget:Object = context.stringToObject(target); + if (!actualTarget) + { + testResult.doFail("Target " + target + " not found"); + return; + } + + // Use MultiResult to determine the proper value (or valueExpression, below). + if(conditionalValues){ + cv = new MultiResult().chooseCV(conditionalValues); + if(cv){ + value = uint(cv.value); + dispatcher = cv; + } + } + + var stagePt:Point = actualTarget.localToGlobal(new Point(0, 0)); + var altPt:Point = actualTarget.localToGlobal(new Point(actualTarget.width, actualTarget.height)); + stagePt.x = Math.min(stagePt.x, altPt.x); + stagePt.y = Math.min(stagePt.y, altPt.y); + var screenBits:BitmapData = new BitmapData(actualTarget.width, actualTarget.height); + try + { + screenBits.draw(root.stage, new Matrix(1, 0, 0, 1, -stagePt.x, -stagePt.y)); + } + catch(se2:SecurityError) + { + screenBits.draw(root, new Matrix(1, 0, 0, 1, -stagePt.x, -stagePt.y)); + } + + if (dispatcher.hasEventListener("valueExpression")) + { + context.resetValue(); + try + { + dispatcher.dispatchEvent(new RunCodeEvent("valueExpression", root["document"], context, testCase, testResult)); + } + catch (e1:Error) + { + TestOutput.logResult("Exception thrown evaluating value expression."); + testResult.doFail (e1.getStackTrace()); + return; + } + value = uint(context.value); + if (!context.valueChanged) + TestOutput.logResult("WARNING: value was not set by valueExpression. 'value=' missing from expression?"); + } + + if (screenBits.getPixel(pt.x, pt.y) != value) + { + testResult.doFail ( target + " pixel at (" + x + "," + y + ") " + + screenBits.getPixel(pt.x, pt.y).toString(16).toUpperCase() + " != 0x" + value.toString(16).toUpperCase()); + } + } + + /** + * The color value the property should have + */ + public var value:uint; + + /** + * The x offset into the component + */ + public var x:Number; + + /** + * The y offset into the component + */ + public var y:Number; + + /** + * customize string representation + */ + override public function toString():String + { + var s:String = "AssertPixelValue"; + if (target) + s += ": target = " + target; + s += ", x = " + x; + s += ", y = " + y; + return s; + } +} + +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/27eb06f5/mustella/src/main/flex/AssertPropertyValue.as ---------------------------------------------------------------------- diff --git a/mustella/src/main/flex/AssertPropertyValue.as b/mustella/src/main/flex/AssertPropertyValue.as new file mode 100644 index 0000000..33c26db --- /dev/null +++ b/mustella/src/main/flex/AssertPropertyValue.as @@ -0,0 +1,142 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 { + +COMPILE::SWF +{ +import flash.display.DisplayObject; +import flash.events.EventDispatcher; +} + +/** +* Vector of conditionalValue objects. +**/ +[DefaultProperty("conditionalValues")] + +/** + * Instead of a property, we use an event so the MXML + * compiler will wrap the code in a function for us + */ +[Event(name="valueExpression", type="flash.events.Event")] + +/** + * Tests that the value of a property is as expected + * MXML attributes: + * target + * propertyName + * value + * waitTarget (optional) + * waitEvent (optional) + * timeout (optional) + */ +public class AssertPropertyValue extends Assert +{ + //TODO (aharui) later + //public var conditionalValues:Vector.<ConditionalValue> = null; + + /** + * See if the property has the correct value + */ + COMPILE::SWF + override protected function doStep():void + { + var actualTarget:Object = context.stringToObject(target); + var multiResultResult:String = ""; + var cv:ConditionalValue = null; + var dispatcher:EventDispatcher = this; + + if (!actualTarget) + { + testResult.doFail("Target " + target + " not found"); + return; + } + + if (!(propertyName in actualTarget)) + { + testResult.doFail ( target + "." + propertyName + " does not exist"); + return; + } + + // Use MultiResult to determine the proper value (or valueExpression, below). + /* TODO (aharui) later + if(conditionalValues){ + cv = new MultiResult().chooseCV(conditionalValues); + if(cv){ + value = cv.value; + dispatcher = cv; + } + } + */ + + if (dispatcher.hasEventListener("valueExpression")) + { + context.resetValue(); + try + { + dispatcher.dispatchEvent(new RunCodeEvent("valueExpression", root["document"], context, testCase, testResult)); + } + catch (e1:Error) + { + TestOutput.logResult("Exception thrown evaluating value expression."); + testResult.doFail (e1.getStackTrace()); + return; + } + + value = context.value; + + if (!context.valueChanged) + TestOutput.logResult("WARNING: value was not set by valueExpression. 'value=' missing from expression?"); + + } + + if (errorArray) { + var errors:ErrorArray = new ErrorArray(errorArray); + if (!contains(actualTarget[propertyName], errors)) + testResult.doFail(target + "." + propertyName + " " + valueToString(actualTarget[propertyName]) + " should contain " + valueToString(errors)); + } else if (valueToString(actualTarget[propertyName]) != valueToString(value)) + testResult.doFail(target + "." + propertyName + " " + valueToString(actualTarget[propertyName]) + " != " + valueToString(value)); + } + + /** + * The name of the property to test + */ + public var propertyName:String; + + /** + * The value the property should have + */ + public var value:*; + + public var errorArray:Array; + + /** + * customize string representation + */ + override public function toString():String + { + var s:String = "AssertPropertyValue"; + if (target) + s += ": target = " + target; + if (propertyName) + s += ", propertyName = " + propertyName; + return s; + } +} + +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/27eb06f5/mustella/src/main/flex/AssertStyleValue.as ---------------------------------------------------------------------- diff --git a/mustella/src/main/flex/AssertStyleValue.as b/mustella/src/main/flex/AssertStyleValue.as new file mode 100644 index 0000000..6eca015 --- /dev/null +++ b/mustella/src/main/flex/AssertStyleValue.as @@ -0,0 +1,124 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 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="valueExpression", type="flash.events.Event")] + +/** +* Vector of conditionalValue objects. +**/ +[DefaultProperty("conditionalValues")] + +/** + * Tests that the value of a property is as expected + * MXML attributes: + * target + * styleName + * value + * waitTarget (optional) + * waitEvent (optional) + * timeout (optional) + */ +public class AssertStyleValue extends Assert +{ + public var conditionalValues:Vector.<ConditionalValue> = null; + + /** + * Test the value of a property, log result if failure. + */ + override protected function doStep():void + { + var cv:ConditionalValue = null; + var dispatcher:EventDispatcher = this; + var actualTarget:Object = context.stringToObject(target); + + if (!actualTarget) + { + testResult.doFail("Target " + target + " not found"); + return; + } + + // 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 (dispatcher.hasEventListener("valueExpression")) + { + context.resetValue(); + try + { + dispatcher.dispatchEvent(new RunCodeEvent("valueExpression", root["document"], context, testCase, testResult)); + } + catch (e1:Error) + { + TestOutput.logResult("Exception thrown evaluating value expression."); + testResult.doFail (e1.getStackTrace()); + return; + } + value = context.value; + if (!context.valueChanged) + TestOutput.logResult("WARNING: value was not set by valueExpression. 'value=' missing from expression?"); + } + + if (valueToString(actualTarget.getStyle(styleName)) != valueToString(value)) + { + testResult.doFail( target + "." + styleName + " " + valueToString(actualTarget.getStyle(styleName)) + " != " + valueToString(value)); + } + } + + /** + * The name of the property to test + */ + public var styleName:String; + + /** + * The value the property should have + */ + public var value:Object; + + /** + * customize string representation + */ + override public function toString():String + { + var s:String = "AssertStyleValue"; + if (target) + s += ": target = " + target; + if (styleName) + s += ", styleName = " + styleName; + return s; + } +} + +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/27eb06f5/mustella/src/main/flex/AssertTitle.as ---------------------------------------------------------------------- diff --git a/mustella/src/main/flex/AssertTitle.as b/mustella/src/main/flex/AssertTitle.as new file mode 100644 index 0000000..006130d --- /dev/null +++ b/mustella/src/main/flex/AssertTitle.as @@ -0,0 +1,70 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.external.ExternalInterface; + +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="valueExpression", type="flash.events.Event")] + +/** + * Tests that the value of a property is as expected + * MXML attributes: + * title + * waitTarget (optional) + * waitEvent (optional) + * timeout (optional) + */ +public class AssertTitle extends Assert +{ + /** + * See if the property has the correct value + */ + override protected function doStep():void + { + var actualTitle:String = ExternalInterface.call("BrowserHistory.getTitle"); + if (valueToString(actualTitle) != valueToString(title)) + { + testResult.doFail ( "Expected " + valueToString(title) + ", got " + valueToString(actualTitle)); + } + } + + /** + * The value the url should have + */ + public var title:String; + + /** + * customize string representation + */ + override public function toString():String + { + var s:String = "AssertTitle"; + return s; + } +} + +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/27eb06f5/mustella/src/main/flex/AssertType.as ---------------------------------------------------------------------- diff --git a/mustella/src/main/flex/AssertType.as b/mustella/src/main/flex/AssertType.as new file mode 100644 index 0000000..fff56d2 --- /dev/null +++ b/mustella/src/main/flex/AssertType.as @@ -0,0 +1,111 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.utils.getQualifiedClassName; + +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="valueExpression", type="flash.events.Event")] + +/** + * Tests that the value of a property is as expected + * MXML attributes: + * target + * propertyName + * value + * waitTarget (optional) + * waitEvent (optional) + * timeout (optional) + */ +public class AssertType extends Assert +{ + /** + * See if the property has the correct value + */ + override protected function doStep():void + { + var actualTarget:Object = context.stringToObject(target); + if (!actualTarget) + { + testResult.doFail("Target " + target + " not found"); + return; + } + + if (hasEventListener("valueExpression")) + { + context.resetValue(); + try + { + dispatchEvent(new RunCodeEvent("valueExpression", root["document"], context, testCase, testResult)); + } + catch (e1:Error) + { + TestOutput.logResult("Exception thrown evaluating value expression."); + testResult.doFail (e1.getStackTrace()); + return; + } + value = context.value; + if (!context.valueChanged) + TestOutput.logResult("WARNING: value was not set by valueExpression. 'value=' missing from expression?"); + } + + if (!(propertyName in actualTarget)) + { + testResult.doFail ( target + "." + propertyName + " does not exist"); + return; + } + + if (getQualifiedClassName(actualTarget[propertyName]) != valueToString(value)) + { + testResult.doFail ( target + "." + propertyName + " " + getQualifiedClassName(actualTarget[propertyName]) + " != " + valueToString(value)); + } + } + + /** + * The name of the property to test + */ + public var propertyName:String; + + /** + * The value the property should have + */ + public var value:Object; + + /** + * customize string representation + */ + override public function toString():String + { + var s:String = "AssertPropertyValue"; + if (target) + s += ": target = " + target; + if (propertyName) + s += ", propertyName = " + propertyName; + return s; + } +} + +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/27eb06f5/mustella/src/main/flex/AssertURL.as ---------------------------------------------------------------------- diff --git a/mustella/src/main/flex/AssertURL.as b/mustella/src/main/flex/AssertURL.as new file mode 100644 index 0000000..d878cba --- /dev/null +++ b/mustella/src/main/flex/AssertURL.as @@ -0,0 +1,79 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.external.ExternalInterface; + +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="valueExpression", type="flash.events.Event")] + +/** + * Tests that the value of a property is as expected + * MXML attributes: + * url + * waitTarget (optional) + * waitEvent (optional) + * timeout (optional) + */ +public class AssertURL extends Assert +{ + /** + * See if the property has the correct value + */ + override protected function doStep():void + { + var actualURL:String = ExternalInterface.call("BrowserHistory.getURL"); + var pos:int = actualURL.indexOf("#"); + var actualHash:String = ""; + if (pos > -1) + actualHash = actualURL.substring(pos + 1); + var hash:String = ""; + pos = url.indexOf("#"); + if (pos > -1) + hash = url.substring(pos + 1); + + if (valueToString(actualHash) != valueToString(hash)) + { + testResult.doFail ( "Expected " + valueToString(hash) + ", got " + valueToString(actualHash)); + } + } + + /** + * The value the url should have + */ + public var url:String; + + /** + * customize string representation + */ + override public function toString():String + { + var s:String = "AssertURL"; + return s; + } +} + +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/27eb06f5/mustella/src/main/flex/Bug.as ---------------------------------------------------------------------- diff --git a/mustella/src/main/flex/Bug.as b/mustella/src/main/flex/Bug.as new file mode 100644 index 0000000..cc59dd9 --- /dev/null +++ b/mustella/src/main/flex/Bug.as @@ -0,0 +1,29 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 +{ + public class Bug extends Object + { + public var bugID:String; + + public function Bug() + { + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/27eb06f5/mustella/src/main/flex/CBTester.mxml ---------------------------------------------------------------------- diff --git a/mustella/src/main/flex/CBTester.mxml b/mustella/src/main/flex/CBTester.mxml new file mode 100644 index 0000000..c02e030 --- /dev/null +++ b/mustella/src/main/flex/CBTester.mxml @@ -0,0 +1,305 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + + 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. + +--> +<UnitTester xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" testSWF="main.mxml"> + + <!-- this set of lines form a template that must be in each unit test --> + <mx:Script> + <![CDATA[ + public static function init(o:DisplayObject):void + { + } + ]]> + </mx:Script> + <mx:Metadata> + <![CDATA[ + [Mixin] + ]]> + </mx:Metadata> + <!-- end of set of lines that must be in each unit test --> + + <mx:Script> + <![CDATA[ + import mx.core.FlexGlobals; + import mx.controls.ComboBox; + import mx.controls.DateField; + import mx.styles.IStyleManager2; + import mx.managers.SystemManager; + + + public function scriptFunction(a:String, b:int):String + { + return a + ":" + b.toString(); + + App + } + + public var styleDecl:Object; + public var styleObj:Object; + + public var validationObject:Object = {}; + + ]]> + </mx:Script> + + <testCases> + <TestCase testID="myScriptTest1"> + <body> + <!-- inline code doesn't need fully qualified class names, but you must import --> + <RunCode code="styleDecl = FlexGlobals.topLevelApplication.styleManager.getStyleDeclaration('Button');" /> + <RunCode code="styleDecl.defaultFactory.prototype = {}; styleObj = new styleDecl.defaultFactory();" /> + <!-- to target a variable in the script block, use script: --> + <AssertPropertyValue target="script:styleObj" propertyName="cornerRadius" value="4" /> + <!-- to target a class, use fully qualified name --> + <AssertPropertyValue target="mx.managers::CursorManager" propertyName="NO_CURSOR" value="0" /> + <AssertPropertyValue target="mx.managers::SystemManager.mx_internal:topLevelSystemManagers.0" propertyName="height" value="375" /> + </body> + </TestCase> + <TestCase testID="myValidatorTest1"> + <setup> + <ResetComponent target="ccv" className="mx.validators::CreditCardValidator" /> + <SetProperty target="ccv" propertyName="required" value="true" /> + </setup> + <body> + <!-- to test methods that return complex objects, assign value to the return and match against the + return value. You can just enter "foo", let it run and fail and see what it prints out and + copy that in. Once you get past this step you test the complex object using AssertPropertyValue. + Note also that if the method can throw an error, assign the error in the catch block --> + <AssertMethodValue method="try { value=application.ccv.validate({}); } catch (e:Error) { value = e.message } " > + <!-- arrays start with [ but the MXML parser effectively strips those so if you need to match against + an array, you have to use this pattern instead --> + <value> + <mx:String>[Event type="invalid" bubbles=false cancelable=false eventPhase=2]</mx:String> + </value> + </AssertMethodValue> + <!-- until the next method call, script:value contains the complex return value, so you can use + AssertPropertyValue to test it --> + <AssertPropertyValue target="script:value.results" propertyName="length" value="3" /> + <AssertPropertyValue target="script:value.results.0" propertyName="errorCode" value="requiredField" /> + </body> + </TestCase> + <TestCase testID="myValidatorTest1a"> + <setup> + <ResetComponent target="ccv" className="mx.validators::CreditCardValidator" /> + <SetProperty target="ccv" propertyName="required" value="true" /> + </setup> + <body> + <!-- you can create object literals like this with {} --> + <AssertMethodValue method="try { value=application.ccv.validate({ cardType: 'Visa', cardNumber: '4321123443211234'}); } catch (e:Error) { value = e.message } " > + <value> + <mx:String>[Event type="valid" bubbles=false cancelable=false eventPhase=2]</mx:String> + </value> + </AssertMethodValue> + </body> + </TestCase> + <TestCase testID="myValidatorTest1b"> + <setup> + <ResetComponent target="ccv" className="mx.validators::CreditCardValidator" /> + <SetProperty target="ccv" propertyName="required" value="true" /> + <!-- or you can create objects using ResetComponent and SetProperty --> + <ResetComponent target="script:validationObject" className="Object" /> + <SetProperty target="script:validationObject" propertyName="cardType" value="Visa" /> + <SetProperty target="script:validationObject" propertyName="cardNumber" value="4321123443211234" /> + </setup> + <body> + <AssertMethodValue method="try { value=application.ccv.validate(validationObject); } catch (e:Error) { value = e.message } " > + <value> + <mx:String>[Event type="valid" bubbles=false cancelable=false eventPhase=2]</mx:String> + </value> + </AssertMethodValue> + </body> + </TestCase> + <TestCase testID="myValidatorTest2"> + <setup> + <ResetComponent target="ccv" className="mx.validators::CreditCardValidator" /> + <SetProperty target="ccv" propertyName="required" value="true" /> + </setup> + <body> + <SetProperty target="ccv" propertyName="allowedFormatChars" value="1" /> + <AssertError value="foo" /> + </body> + </TestCase> + <TestCase testID="myValidatorTest3"> + <setup> + <ResetComponent target="ccv" className="mx.validators::CreditCardValidator" /> + <SetProperty target="ccv" propertyName="required" value="true" /> + </setup> + <body> + <SetProperty target="ccv" propertyName="allowedFormatChars" value="-!\\/" /> + <AssertError value="null" /> + </body> + </TestCase> + <TestCase testID="myMethodTest1"> + <body> + <AssertMethodValue method="value=DateField.dateToString(new Date(2005, 2, 4), 'YY/MM/DD')" value="05/03/04" /> + </body> + </TestCase> + <TestCase testID="myMethodTest2"> + <body> + <AssertMethodValue method="value=application.cb.itemToLabel({ label: 'Alex', data: 1})" value="Alex" /> + </body> + </TestCase> + <TestCase testID="myMethodTest3"> + <body> + <AssertMethodValue method="value=scriptFunction('Flex', 1)" value="Flex:1" /> + </body> + </TestCase> + <TestCase testID="myButtonTest1"> + <body> + <DispatchMouseClickEvent target="btn" localX="10" localY="10" /> + <AssertEvent target="btn" eventName="click" eventClass="flash.events::MouseEvent" /> + </body> + </TestCase> + <TestCase testID="myDFTest1"> + <body> + <SetProperty target="df" propertyName="selectedDate" valueExpression="value=new Date(2005, 2, 5)" waitEvent="valueCommit" waitTarget="df" /> + <AssertPropertyValue target="df" propertyName="selectedDate" valueExpression="value=new Date(2005, 2, 5)" /> + </body> + </TestCase> + <TestCase testID="myTest1"> + <setup> + <ResetComponent target="cb" className="mx.controls::ComboBox" /> + <SetProperty target="cb" propertyName="dataProvider" value="[1,2,3,4]" waitEvent="updateComplete" waitTarget="cb" /> + <Pause timeout="1000" /> + </setup> + <body> + <SetProperty target="cb" propertyName="selectedIndex" value="1" waitEvent="valueCommit" waitTarget="cb" /> + <AssertPropertyValue target="cb.getChildAt(0)" propertyName="width" value="51" /> + <AssertPropertyValue target="cb" propertyName="selectedItem" value="3" /> + </body> + </TestCase> + <TestCase testID="myTestError"> + <setup> + <ResetComponent target="cb" className="mx.controls::ComboBox" /> + <SetProperty target="cb" propertyName="dataProvider" value="[1,2,3,4]" waitEvent="updateComplete" waitTarget="cb" /> + </setup> + <body> + <AssertMethodValue method="value = 0; try { application.cb.dataProvider[8] = 51 } catch (e:Error) { value = e.message }" + value="Index '8' specified is out of bounds." /> + </body> + </TestCase> + <TestCase testID="myTest2"> + <setup> + <ResetComponent target="cb" className="mx.controls::ComboBox" /> + <SetProperty target="cb" propertyName="dataProvider" value="[2,3,4]" /> + <AssertPropertyValue waitEvent="updateComplete" waitTarget="cb" target="cb" propertyName="selectedItem" value="2" /> + </setup> + <body> + <SetProperty target="cb" propertyName="selectedIndex" value="2" /> + <AssertPropertyValue target="cb" propertyName="selectedItem" value="4" /> + </body> + <cleanup> + <!-- this is bs just making the call --> + <SetProperty target="cb" propertyName="selectedIndex" value="1" /> + </cleanup> + </TestCase> + <TestCase testID="myTest3"> + <setup> + <ResetComponent target="cb" className="mx.controls::ComboBox" /> + <SetProperty target="cb" propertyName="dataProvider" value="[8,9,10]" /> + <AssertPropertyValue waitEvent="updateComplete" waitTarget="cb" target="cb" propertyName="selectedItem" value="8" /> + </setup> + <body> + <SetProperty target="cb" propertyName="selectedIndex" value="1" waitEvent="updateComplete" /> + <AssertNoEvent target="cb" eventName="change" /> + <AssertPropertyValue target="cb" propertyName="selectedItem" value="9" /> + <AssertPropertyValue target="cb.getTextInput()" propertyName="text" value="9" /> + <AssertPropertyValue target="cb.getTextInput().getTextField()" propertyName="text" value="9" /> + <AssertPropertyValue target="cb.getTextInput().getTextField()" propertyName="antiAliasType" value="advanced" /> + <AssertPropertyValue target="cb.getTextInput().getTextField().getTextFormat()" propertyName="color" value="0x0B333C" /> + </body> + </TestCase> + <TestCase testID="myTest4"> + <setup> + <ResetComponent target="cb" className="mx.controls::ComboBox" /> + <SetProperty target="cb" propertyName="dataProvider" value="[1,2,3,4]" waitEvent="updateComplete" waitTarget="cb" /> + <DispatchMouseEvent target="cb.mx_internal:downArrowButton" type="mouseDown" localX="10" localY="10" waitEvent="open" waitTarget="cb" /> + <DispatchMouseEvent target="cb.mx_internal:downArrowButton" type="mouseUp" localX="10" localY="10"/> + </setup> + <body> + <DispatchMouseEvent target="cb.dropdown" type="mouseOver" localX="10" localY="50" /> + <DispatchMouseEvent target="cb.dropdown" type="mouseDown" localX="10" localY="50" /> + <DispatchMouseEvent target="cb.dropdown" type="mouseUp" localX="10" localY="50" waitEvent="change" waitTarget="cb" /> + <AssertPropertyValue target="cb" propertyName="selectedIndex" value="2" /> + <CompareBitmap target="cb" url="myTest4.png" timeout="5000" /> + </body> + </TestCase> + <TestCase testID="myTest4WithWait"> + <setup> + <ResetComponent target="cb" className="mx.controls::ComboBox" /> + <SetProperty target="cb" propertyName="dataProvider" value="[1,2,3,4]" waitEvent="updateComplete" waitTarget="cb" /> + <DispatchMouseEvent target="cb.mx_internal:downArrowButton" type="mouseDown" localX="10" localY="10"/> + <WaitForEffectsToEnd /> + <DispatchMouseEvent target="cb.mx_internal:downArrowButton" type="mouseUp" localX="10" localY="10"/> + </setup> + <body> + <DispatchMouseEvent target="cb.dropdown" type="mouseOver" localX="10" localY="50" /> + <DispatchMouseEvent target="cb.dropdown" type="mouseDown" localX="10" localY="50" /> + <DispatchMouseEvent target="cb.dropdown" type="mouseUp" localX="10" localY="50" waitEvent="change" waitTarget="cb" /> + <AssertPropertyValue target="cb" propertyName="selectedIndex" value="2" /> + <AssertPropertyValue target="cb.dropdown.mx_internal:rendererArray.2.0.getLabel()" propertyName="text" value="3" /> + <CompareBitmap target="cb" url="myTest4.png" timeout="5000" /> + </body> + </TestCase> + <TestCase testID="myTest5"> + <setup> + <ResetComponent target="cb" className="mx.controls::ComboBox" /> + <SetProperty target="cb" propertyName="dataProvider" value="[1,2,3,4]" waitEvent="updateComplete" waitTarget="cb" /> + <DispatchMouseEvent target="cb.mx_internal:downArrowButton" type="mouseDown" localX="10" localY="10" waitEvent="open" waitTarget="cb" /> + <DispatchMouseEvent target="cb.mx_internal:downArrowButton" type="mouseUp" localX="10" localY="10" /> + </setup> + <body> + <DispatchKeyEvent key="ESCAPE" waitEvent="close" waitTarget="cb" /> + <DispatchKeyEvent char="2" waitEvent="change" waitTarget="cb" /> + <AssertPropertyValue target="cb" propertyName="selectedIndex" value="1" /> + </body> + </TestCase> + <TestCase testID="myTestImage"> + <setup> + <ResetComponent target="cb" className="mx.controls::ComboBox" /> + <SetProperty target="cb" propertyName="dataProvider" value="[1,2,3,4]" waitEvent="updateComplete" waitTarget="cb" /> + <DispatchMouseEvent target="cb.mx_internal:downArrowButton" type="mouseDown" localX="10" localY="10" waitEvent="open" waitTarget="cb" /> + <DispatchMouseEvent target="cb.mx_internal:downArrowButton" type="mouseUp" localX="10" localY="10" /> + </setup> + <body> + <DispatchKeyEvent key="ESCAPE" waitEvent="close" waitTarget="cb" /> + <DispatchKeyEvent char="2" waitEvent="change" waitTarget="cb" /> + <AssertEvent target="cb" eventName="change" eventClass="flash.events::Event" /> + <AssertEventPropertyValue propertyName="type" value="change" /> + <CompareBitmap target="cb" url="myBitmap.png" timeout="8000" /> + </body> + </TestCase> + <TestCase testID="myStyleTest1"> + <setup> + <ResetComponent target="cb" className="mx.controls::ComboBox" /> + <SetProperty target="cb" propertyName="dataProvider" value="[1,2,3,4]" waitEvent="updateComplete" waitTarget="cb" /> + <SetStyle target="cb" styleName="rollOverColor" value="0xFF0000" waitEvent="updateComplete" waitTarget="cb" /> + </setup> + <body> + <DispatchMouseEvent target="cb.mx_internal:downArrowButton" type="mouseDown" localX="10" localY="10" waitEvent="open" waitTarget="cb" /> + <DispatchMouseEvent target="cb.mx_internal:downArrowButton" type="mouseUp" localX="10" localY="10" /> + <DispatchMouseEvent target="cb.dropdown" type="mouseOver" localX="10" localY="50" /> + <AssertStyleValue target="cb" styleName="rollOverColor" value="0xFF0000" /> + <AssertStyleValue target="cb.dropdown" styleName="rollOverColor" value="0xFF0000" /> + <AssertPixelValue target="cb.dropdown" x="50" y="50" value="0xFF0000" /> + <AssertPixelValue target="cb.dropdown" x="50" y="30" value="0xFF0000" /> + </body> + </TestCase> + </testCases> +</UnitTester> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/27eb06f5/mustella/src/main/flex/ChangeState.as ---------------------------------------------------------------------- diff --git a/mustella/src/main/flex/ChangeState.as b/mustella/src/main/flex/ChangeState.as new file mode 100644 index 0000000..bcb0db6 --- /dev/null +++ b/mustella/src/main/flex/ChangeState.as @@ -0,0 +1,96 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 mx.core.UIComponent; +import mx.effects.EffectManager; + +/** + * A test step that runs an arbitrary set of actionscript + * MXML attributes + * code (a sequence of actionscript) + */ +public class ChangeState extends TestStep +{ + public var changeTarget:String; + public var toState:String; + + public function ChangeState():void + { + waitEvent = "currentStateChange"; + super(); + } + + /** + * Execute the code by passing it an event. + */ + override protected function doStep():void + { + var actualTarget:UIComponent; + + UnitTester.blockFocusEvents = false; + + actualTarget = context.stringToObject(this.changeTarget) as UIComponent; + + try + { + if((toState) && (actualTarget)) + { + if(actualTarget.currentState != toState) + { + EffectManager.suspendEventHandling(); + actualTarget.currentState = this.toState; + EffectManager.resumeEventHandling(); + } + else + { + this.stepComplete(); + } + } + + } + catch (e1:Error) + { + TestOutput.logResult("Exception thrown in ChangeState."); + testResult.doFail (e1.getStackTrace()); + UnitTester.blockFocusEvents = true; + return; + } + + UnitTester.blockFocusEvents = true; + } + + /* + public var code:Function; // Event metadata takes care of this + */ + + /** + * customize string representation + */ + override public function toString():String + { + var s:String = "RunCode: (code attribute cannot be shown)"; + return s; + } +} + +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/27eb06f5/mustella/src/main/flex/CheckEmbeddedFonts.as ---------------------------------------------------------------------- diff --git a/mustella/src/main/flex/CheckEmbeddedFonts.as b/mustella/src/main/flex/CheckEmbeddedFonts.as new file mode 100644 index 0000000..21e2459 --- /dev/null +++ b/mustella/src/main/flex/CheckEmbeddedFonts.as @@ -0,0 +1,44 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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; + +[Mixin] +/** + * A "marker" class that causes test scripts to write out + * bitmaps to the urls instead of reading and comparing + * so that baselines/reference-points can be created for + * future comparing. + */ +public class CheckEmbeddedFonts +{ + + /** + * Mixin callback that gets everything ready to go. + * The UnitTester waits for an event before starting + */ + public static function init(root:DisplayObject):void + { + UnitTester.checkEmbeddedFonts = true; + } + +} + +}