blob: ef85344807c3bdef778a3d7df3a13f0d932b1222 [file]
<?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 testDir="resources/ResourceManager/Events/" xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" testSWF="ResourceManagerApp.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.resources.ResourceManager;
import mx.resources.ResourceBundle;
import mx.events.ResourceEvent;
public var ed1:IEventDispatcher;
public var ed2:IEventDispatcher;
public var ed3:IEventDispatcher;
public var ed4:IEventDispatcher;
public var ed5:IEventDispatcher;
private function clearAllLocaleData():void{
ResourceManager.getInstance().localeChain = [];
var numLocales:int = ResourceManager.getInstance().getLocales().length;
for(var i:int = numLocales; i > 0; --i){
ResourceManager.getInstance().removeResourceBundlesForLocale(ResourceManager.getInstance().getLocales()[i-1]);
}
}
private function handleErrorEvent(e:ResourceEvent):void{trace("handleErrorEvent: " + e.toString())}
private function handleProgressEvent(e:ResourceEvent):void{trace("handleProgressEvent: " + e.toString())}
private function handleCompleteEvent(e:ResourceEvent):void{trace("handleCompleteEvent: " + e.toString())}
]]></mx:Script>
<!--
General approach:
<setup>
- Remove all locales.
- Clear the locale chain.
- Verify that there are no resources left.
</setup>
<body>
- Initiate the loading
- Set up event listeners for the returned IEventDispatcher.
- Make sure events do (or do not) occur.
</body>
-->
<testCases>
<!--
It is a bug to wait for 2 error events instead of just one. Bug 203857. Excluding.
-->
<TestCase frequency="all" testID="RTL_Event_ResourceManagerErrorEvent_ExactlyOne" description="Confirm that loadResourceModule triggers an error event when the parameter is invalid." keywords="[Runtime Localization,loadResourceModule]" >
<setup>
<RunCode code="clearAllLocaleData()" />
<AssertMethodValue method="value=ResourceManager.getInstance().getLocales().length" value="0" />
<AssertMethodValue method="value=ResourceManager.getInstance().localeChain.length" value="0" />
</setup>
<body>
<RunCode code="ed1=ResourceManager.getInstance().loadResourceModule('ThisDoesNotExist.swf')" />
<RunCode code="ed1.addEventListener(ResourceEvent.ERROR, handleErrorEvent)" />
<AssertEvent target="script:ed1" eventName="error" eventClass="mx.events::ResourceEvent" numExpectedEvents="1" />
</body>
</TestCase>
<!--
This is just like the above test, except that we don't care how many error events occur. That way we can exclude
the above test yet still confirm that an error event will get dispatched.
-->
<TestCase frequency="all" testID="RTL_Event_ResourceManagerErrorEvent_AtLeastOne" description="Confirm that loadResourceModule triggers an error event when the parameter is invalid." keywords="[Runtime Localization,loadResourceModule]" >
<setup>
<RunCode code="clearAllLocaleData()" />
<AssertMethodValue method="value=ResourceManager.getInstance().getLocales().length" value="0" />
<AssertMethodValue method="value=ResourceManager.getInstance().localeChain.length" value="0" />
</setup>
<body>
<RunCode code="ed1=ResourceManager.getInstance().loadResourceModule('ThisDoesNotExist.swf')" />
<RunCode code="ed1.addEventListener(ResourceEvent.ERROR, handleErrorEvent)" />
<AssertEvent target="script:ed1" eventName="error" eventClass="mx.events::ResourceEvent" numExpectedEvents="-1" />
</body>
</TestCase>
<TestCase frequency="all" testID="RTL_Event_ResourceManagerProgressEvent" description="Confirm that loadResourceModule triggers a progress event when loading." keywords="[Runtime Localization,loadResourceModule]" >
<setup>
<RunCode code="clearAllLocaleData()" />
<AssertMethodValue method="value=ResourceManager.getInstance().getLocales().length" value="0" />
<AssertMethodValue method="value=ResourceManager.getInstance().localeChain.length" value="0" />
</setup>
<body>
<RunCode code="ed2=ResourceManager.getInstance().loadResourceModule('assets/bundles/framework/resMod_events_001.swf')" />
<RunCode code="ed2.addEventListener(ResourceEvent.PROGRESS, handleProgressEvent)" />
<RunCode code="ed2.addEventListener(ResourceEvent.COMPLETE, handleCompleteEvent)" />
<AssertEvent target="script:ed2" eventName="progress" eventClass="mx.events::ResourceEvent" numExpectedEvents="-1" />
<AssertEvent target="script:ed2" eventName="complete" eventClass="mx.events::ResourceEvent" />
</body>
</TestCase>
<TestCase frequency="all" testID="RTL_Event_ResourceManagerCompleteEvent" description="Confirm that loadResourceModule triggers a complete event when it is done loading." keywords="[Runtime Localization,loadResourceModule]" >
<setup>
<RunCode code="clearAllLocaleData()" />
<AssertMethodValue method="value=ResourceManager.getInstance().getLocales().length" value="0" />
<AssertMethodValue method="value=ResourceManager.getInstance().localeChain.length" value="0" />
</setup>
<body>
<RunCode code="ed3=ResourceManager.getInstance().loadResourceModule('assets/bundles/framework/resMod_events_002.swf')" />
<RunCode code="ed3.addEventListener(ResourceEvent.COMPLETE, handleCompleteEvent)" />
<AssertEvent target="script:ed3" eventName="complete" eventClass="mx.events::ResourceEvent" />
</body>
</TestCase>
<TestCase frequency="all" testID="RTL_Event_ResourceManagerNoCompleteEventWithError" description="Confirm that loadResourceModule() does not trigger a complete event when there is an error." keywords="[Runtime Localization,loadResourceModule]" >
<setup>
<RunCode code="clearAllLocaleData()" />
<AssertMethodValue method="value=ResourceManager.getInstance().getLocales().length" value="0" />
<AssertMethodValue method="value=ResourceManager.getInstance().localeChain.length" value="0" />
</setup>
<body>
<RunCode code="ed4=ResourceManager.getInstance().loadResourceModule('ThisDoesNotExist.swf')" />
<RunCode code="ed4.addEventListener(ResourceEvent.COMPLETE, handleCompleteEvent)" />
<RunCode code="ed4.addEventListener(ResourceEvent.ERROR, handleErrorEvent)" />
<AssertNoEvent target="script:ed4" eventName="complete" eventClass="mx.events::ResourceEvent" />
</body>
</TestCase>
<TestCase frequency="all" testID="RTL_Event_ResourceManagerNoErrorEventWithComplete" description="Confirm that loadResourceModule() does not trigger an error event when loading is successful." keywords="[Runtime Localization,loadResourceModule]" >
<setup>
<RunCode code="clearAllLocaleData()" />
<AssertMethodValue method="value=ResourceManager.getInstance().getLocales().length" value="0" />
<AssertMethodValue method="value=ResourceManager.getInstance().localeChain.length" value="0" />
</setup>
<body>
<RunCode code="ed5=ResourceManager.getInstance().loadResourceModule('assets/bundles/framework/resMod_events_003.swf')" />
<RunCode code="ed5.addEventListener(ResourceEvent.COMPLETE, handleCompleteEvent)" />
<RunCode code="ed5.addEventListener(ResourceEvent.ERROR, handleErrorEvent)" />
<AssertEvent target="script:ed5" eventName="complete" eventClass="mx.events::ResourceEvent" />
<AssertNoEvent target="script:ed5" eventName="error" eventClass="mx.events::ResourceEvent" />
</body>
</TestCase>
</testCases>
</UnitTester>