| <html> | |
| <head> | |
| <script> | |
| function doTest() | |
| { | |
| if (window.testRunner) | |
| testRunner.dumpAsText(); | |
| if (window.objCPlugin) { | |
| // Type should be "object" | |
| alert("typeof(objCPlugin)=" + typeof(objCPlugin)); | |
| // Calling objCPlugin() should raise an exception. | |
| var result; | |
| try { | |
| result = objCPlugin(); | |
| } catch (e) { | |
| result = e.name; | |
| } | |
| alert("objCPlugin()=" + result); | |
| } | |
| if (window.objCPluginFunction) { | |
| // Type should be "function" | |
| alert("typeof(objCPluginFunction)=" + typeof(objCPluginFunction)); | |
| // Calling objCPluginFunction() should return "test" | |
| var result; | |
| try { | |
| result = objCPluginFunction(); | |
| } catch (e) { | |
| result = e.name; | |
| } | |
| alert("objCPluginFunction()=" + result); | |
| function echoTest(arg) { | |
| var echo = objCPlugin.echo(arg); | |
| var sameVal = (arg == echo) ? "same" : "different"; | |
| var sameType = (typeof(arg) == typeof(echo)) ? "same" : "different"; | |
| alert(arg + " = " + echo + " (" + sameVal + ")"); | |
| alert(typeof(arg) + " = " + typeof(echo) + " (" + sameType + ")"); | |
| } | |
| // Test the echo function | |
| echoTest("hello"); | |
| echoTest(42); | |
| echoTest(null); | |
| echoTest(undefined); | |
| echoTest(new Array("one", "two")); | |
| // Test exceptions | |
| function exceptionTest(arg) { | |
| try { | |
| objCPlugin.throwIfArgumentIsNotHello(arg); | |
| } catch (e) { | |
| alert("String " + arg + " != Hello"); | |
| return; | |
| } | |
| alert("String " + arg + " == Hello"); | |
| } | |
| exceptionTest("Hello"); | |
| exceptionTest("Not Hello"); | |
| } | |
| } | |
| </script> | |
| </head> | |
| <body onload="doTest();"> | |
| <p>This page tests invoking as functions JavaScript objects that are provided by objective-c plugins.</p> | |
| <embed id="testCPlugin" type="application/x-webkit-test-netscape"></embed> | |
| </body> | |
| </html> |