Running a FlexUnit4 test in IntelliJ

When trying to run a FlexUnit4 test in IntelliJ I get following error:


SecurityError: Error #2148: SWF file file:///C|/Users/LIC/Projects/ProgramJef/out/production/Flex%2DClient%2DTests/%5Fflexunit.swf cannot access local resource file:///C|/Users/LIC/Projects/ProgramJef/out/production/Flex%2DClient%2DTests/textLayout_1.1.0.604.swf. Only local-with-filesystem and trusted local SWF files may access local resources.
 at flash.net::URLStream/load()
 at flash.net::URLLoader/load()
 at mx.core::CrossDomainRSLItem/load()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\CrossDomainRSLItem.as:240]
 at mx.core::RSLListLoader/loadNext()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\RSLListLoader.as:184]
 at mx.core::RSLListLoader/load()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\RSLListLoader.as:156]
 at mx.preloaders::Preloader/initialize()[E:\dev\4.x\frameworks\projects\framework\src\mx\preloaders\Preloader.as:279]
 at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::initialize()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\SystemManager.as:1925]
 at mx.managers::SystemManager/initHandler()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\SystemManager.as:2419]


I really have no idea why I'm getting this error. I'm using the RC1 from FlexUnit4 and IntelliJ 9.0.2

Anybody that can help me with this?

I have created a Flex Module with no mxml in it. Just one class:

package {
import org.flexunit.Assert;
public class FirstTest {
    [Test]
    public function goodTest():void{
        Assert.assertEquals(2 * 2, 4);   
    }
}
}

If I look in the directory where this textLayout...swf is searched, there isn't such a file.

2 comments

The most likely cause of the SecurityError: Error #2148 when running unit tests is that the SWF created to run the tests is not trusted. Below is a copy of a note I put together when I first started Flex development and that I send to new developers on the project. It should help you.


In order to run FlexUnit tests through your IDE, or to run Flex application files created and run locally or via your IDE, you need to specify global trust for local test SWF files. This can be done either globally for the entire PC, or for the user only. You need to make an entry in a config file (with an extension of .cfg) in a predefined location as shown below. The name of the file can be anything, as long as the extension is .cfg. Note that you may need to create the FlashPlayerTrust  directory shown in the paths below. **IMPORTANT**: After making the configuration changes, you will need to restart your web browser since the flash player reads the configuration files when it initializes the first time.

        SYSTEM:
            To set globally for the system, create cfg file in:
                C:\WINDOWS\system32\Macromed\Flash\FlashPlayerTrust
        USER:
            To set for a user, create cfg file in:
                C:\Documents and Settings\UserName\Application Data\Macromedia\Flash Player\#Security\FlashPlayerTrust
            (Yes, you need the '#' in the '#Security' directory)

   Create a .cfg file with any name. For example myProject.cfg, ide.cfg, safeList.cfg, etc
   Add one entry per line. Each entry specifies the absolute path to a swf file that you want to trust, or to a directory that you want to trust all SWF files in that directory or any of its sub-directories. Some Examples:

      D:\dev\proj\MyProject\FlexComponents\FlexUI\target\_flexunit.swf
      D:\dev\proj\MyProject\FlexComponents\FlexUI\target\
      D:\dev\proj\MyProject\FlexComponents
      D:\dev\proj\MyProject\

The first line shows an example of the default name of the swf file created when running flexunit tests via IntelliJ IDEA. It may or may not be applicable to all IDEs. It is likely easier to specify the project's target directory. **Be cautious of specifying too general of a rule.** For example, specifying "C:\" would introduce a huge security risk to your PC since any SWF file on your PC could then fully access the network. So a downloaded internet video or such could now act as a virus or trojan.

You can add multiple entries in a single file. For example, you could have a line to the root directory of each flex project on your PC.

For more information, see: http://livedocs.adobe.com/flex/3/html/help.html?content=05B_Security_03.html

0

Hi Lieven,
please look at <Flex SDK>/frameworks/flex-config.xml file. This file is usually used as base compiler configuration file (in case of flexunit IDEA's test runner compilation as well). By default it contains textLayout.swc as RSL library which is either downloaded from fpdownload.adobe.com or is looked for on local drive in the same folder where main swf file persists (.../out/production/Flex Client Tests/ in your case). So to make it possible to run tests you should make this file achievable. Here are 3 ways to do this:
- make it not an RSL but merged into code (just remove respective <runtime-shared-library-path> block from flex-config.xml file)
- make it achievable by default url or specify a different url where respective file exists
- run your flexunit test trusted (as Mark wrote) and copy <Flex SDK>/rsls/textLayout_1.1.0.604.swf to out/production/Flex Client Tests/ or change path to file in flex-config.xml from textLayout_1.1.0.604.swf to <Flex SDK>/rsls/textLayout_1.1.0.604.swf

0

Please sign in to leave a comment.