Update with current status
[gnash.git] / testsuite / misc-mtasc.all / extcomm.as
blob0f76c15f13d5f85b8bdc841ec9491580340156ee
1 // extcomm.as - Host container communication (ExternalInterface) tests
2 //
3 // Copyright (C) 2015, 2016 Free Software Foundation, Inc.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20 // Original author: Nutchanon Wetchasit <Nutchanon.Wetchasit@gmail.com>
23 import flash.external.*;
25 #include "check.as"
27 class ExternalCommTest
29 var testVariable = "Variable in this";
31 // Entry point
32 public static function main(mc:MovieClip):Void
34 var app:ExternalCommTest;
36 app = new ExternalCommTest(mc);
39 public function ExternalCommTest(mc:MovieClip)
41 var obj:Object;
43 obj = new Object();
44 obj.testVariable = "Variable in obj";
45 _root.testVariable = "Variable in _root";
47 // ExternalInterface should be available
48 check(ExternalInterface.available);
50 mc.script_call = function(arg1, arg2):String
52 // This function should NOT be called
53 check(false);
54 check_equals(arg1, "Hello");
55 check_equals(arg2, "World");
56 return "Too";
59 // Registering callback shouldn't fail
60 check(
61 ExternalInterface.addCallback("script_call", obj,
62 function(arg1, arg2):String
64 // This function should be called
65 check(true);
66 check_equals(arg1, "Hello");
67 check_equals(arg2, "World");
69 // `this` should point to user-specified object
70 check_equals(this.testVariable, "Variable in obj");
72 return "Too";
77 // Invalid callback registrations should fail
78 check(!ExternalInterface.addCallback("invalid_reg1", mc, null));
79 check(!ExternalInterface.addCallback("invalid_reg2", mc, undefined));
80 check(!ExternalInterface.addCallback("invalid_reg3", null, null));
81 check(!ExternalInterface.addCallback("invalid_reg4", null, undefined));
82 check(!ExternalInterface.addCallback("invalid_reg5", undefined, null));
83 check(!ExternalInterface.addCallback("invalid_reg6", undefined, undefined));
85 // Registering callbacks with no `this` instance shouldn't fail
86 check(
87 ExternalInterface.addCallback("script_nothis1", null,
88 function():Void
90 // `this` should be an "undefined" object like one in
91 // a function called via `function.call(null)`
92 check_equals(typeof(this), "object");
93 check(this == undefined);
94 check(this == null);
95 check(this !== undefined);
96 check(this !== null);
97 check_equals("" + this, "undefined");
98 check(this === _global);
99 this.nothis1_value = "script_nothis1";
103 check(
104 ExternalInterface.addCallback("script_nothis2", undefined,
105 function():Void
107 // `this` should be an "undefined" object like one in
108 // a function called via `function.call(undefined)`
109 check_equals(typeof(this), "object");
110 check(this == undefined);
111 check(this == null);
112 check(this !== undefined);
113 check(this !== null);
114 check_equals("" + this, "undefined");
115 check(this === _global);
116 this.nothis2_value = "script_nothis2";
121 // Registering callback for checking _global properties shouldn't fail
122 check(
123 ExternalInterface.addCallback("script_globalcheck", mc,
124 function():Void
126 check_equals(_global.nothis1_value, "script_nothis1");
127 check_equals(_global.nothis2_value, "script_nothis2");
132 // Registering another ordinary callback shouldn't fail
133 check(
134 ExternalInterface.addCallback("script_longarglist", mc,
135 function(arg1:String, arg2:String, arg3:String,
136 arg4:String, arg5:String, arg6:String,
137 arg7:String, arg8:String, arg9:String):String
139 // Long argument list should be passed correctly
140 check_equals(arg1, "The");
141 check_equals(arg2, "quick");
142 check_equals(arg3, "brown");
143 check_equals(arg4, "fox");
144 check_equals(arg5, "jumps");
145 check_equals(arg6, "over");
146 check_equals(arg7, "the");
147 check_equals(arg8, "lazy");
148 check_equals(arg9, "dog");
150 return "Pangram";
155 // Calling JavaScript function without any argument should give
156 // a correct return value
157 check_equals(ExternalInterface.call("js_simple"), "Correct");
159 // Calling JavaScript function 20 times in row should give all
160 // correct return value
161 var numreadings:Array = new Array(
162 "one", "two", "three", "four", "five", "six", "seven", "eight",
163 "nine", "ten", "eleven", "twelve", "thirteen", "fourteen",
164 "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"
166 var i:Number;
167 for(i = 0; i < numreadings.length; i++) {
168 check_equals(ExternalInterface.call("js_readnumber", i + 1),
169 numreadings[i]);