OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <html> | |
3 <!-- | |
4 Copyright (c) 2010 The Ginsu Authors. All rights reserved. | |
5 Use of this source code is governed by a BSD-style license that can be | |
6 found in the LICENSE file. | |
7 --> | |
8 <head> | |
9 <title>c_salt Integration Tests</title> | |
10 <link rel="stylesheet" type="text/css" href="jsunit/css/jsUnitStyle.css"> | |
11 <script type="text/javascript" src="closure/closure/goog/base.js"/> | |
12 <script type="text/javascript" src="jsunit/app/jsUnitCore.js"></script> | |
13 <script type="text/javascript"> | |
14 goog.require('goog.testing.jsunit'); | |
15 </script> | |
16 | |
17 <script type="text/javascript"> | |
18 c_saltIntegrationTestModule = null; // Global application object. | |
19 | |
20 function moduleDidLoad() { | |
21 c_saltIntegrationTestModule = document.getElementById('c_salt_integration_
test'); | |
22 } | |
23 | |
24 // The UnaryOperations class just provides two simple unary functions. | |
25 function UnaryOperations() { | |
26 // Return the square of the given number. | |
27 this.square = function(x) { return x*x; } | |
28 // Return true if the given number is odd. | |
29 this.isOdd = function(x) { return x%2 ? true : false; } | |
30 } | |
31 | |
32 // TODO(c_salt authors): Add tests of other c_salt features here. | |
33 // e.g., make a PropertyTester ScriptableNativeObject, test it from | |
34 // a JavaScript function. | |
35 function testMethods() { | |
36 try { | |
37 // Get the the MethodTester for testing method marshalling behavior. | |
38 var methodTester = c_saltIntegrationTestModule.getMethodTester(); | |
39 // Call the methods and make sure the return value is correct. | |
40 assertEquals("Hello world!", | |
41 methodTester.appendStrings("Hello ", "world!")); | |
42 assertEquals(4.24159, | |
43 methodTester.addDoubles(1.1, "3.14159")); | |
44 assertEquals(42, | |
45 methodTester.addInts("30", 12)); | |
46 assertEquals(false, | |
47 methodTester.andBools(true, false)); | |
48 assertEquals(true, | |
49 methodTester.andBools("Yes", "Truck")); | |
50 // Create a UnaryOperations object that we will pass to methodTester | |
51 // to ensure it can invoke methods on JavaScript objects. | |
52 var x = new UnaryOperations; | |
53 // We should expect: | |
54 // methodTester.callMethodOnScriptObject("method_name", object, arg); | |
55 // to have the same effect as: | |
56 // object.method_name(arg); | |
57 assertEquals(x.square(4), | |
58 methodTester.callMethodOnScriptObject("square", x, "4")); | |
59 assertEquals(x.square(10), | |
60 methodTester.callMethodOnScriptObject("square", x, 10)); | |
61 assertEquals(x.square(1.7), | |
62 methodTester.callMethodOnScriptObject("square", x, 1.7)); | |
63 assertEquals(x.isOdd(10), | |
64 methodTester.callMethodOnScriptObject("isOdd", x, 10)); | |
65 assertEquals(x.isOdd(3), | |
66 methodTester.callMethodOnScriptObject("isOdd", x, 3)); | |
67 assertEquals(x.isOdd(-32), | |
68 methodTester.callMethodOnScriptObject("isOdd", x, -32)); | |
69 assertEquals('Invoked!', | |
70 methodTester.callAnonymousFunction(function(x) { return x;
}, | |
71 'Invoked!')); | |
72 } catch(e) { | |
73 fail(e.message); | |
74 } | |
75 } | |
76 | |
77 function testProperties() { | |
78 try { | |
79 // Get the the PropertyTester for testing property behavior. | |
80 var propertyTester = c_saltIntegrationTestModule.getPropertyTester(); | |
81 | |
82 assertEquals(42, propertyTester.intProp); | |
83 // intProp is immutable, so we shouldn't be able to change its value. | |
84 propertyTester.intProp = 10; | |
85 assertEquals(42, propertyTester.intProp); | |
86 // intProp is static, so we shouldn't be able to delete it. | |
87 assertEquals(false, delete propertyTester.intProp); | |
88 assertEquals(42, propertyTester.intProp); | |
89 | |
90 assertEquals("A string.", propertyTester.stringProp); | |
91 // stringProp is mutable, so we should be able to change its value. | |
92 propertyTester.stringProp = "A different string."; | |
93 assertEquals("A different string.", propertyTester.stringProp); | |
94 // stringProp is static, so we shouldn't be able to delete it. | |
95 assertEquals(false, delete propertyTester.stringProp); | |
96 assertEquals("A different string.", propertyTester.stringProp); | |
97 | |
98 // I should be able to add dynamic properties, and c_salt will manage | |
99 // them automatically. | |
100 propertyTester.dynamicProp = 3.1415; | |
101 assertEquals(3.1415, propertyTester.dynamicProp); | |
102 // dynamic properties are always mutable. | |
103 propertyTester.dynamicProp = 12345; | |
104 assertEquals(12345, propertyTester.dynamicProp); | |
105 // dynamic properties can be deleted. | |
106 assertEquals(true, delete propertyTester.dynamicProp); | |
107 assertUndefined(propertyTester.dynamicProp); | |
108 } | |
109 catch (e) { | |
110 fail(e.message); | |
111 } | |
112 } | |
113 </script> | |
114 </head> | |
115 <body> | |
116 <!-- Load the published .nexe. This includes the 'nexes' attribute which | |
117 shows how to load multi-architecture modules. Each entry in the | |
118 table is a key-value pair: the key is the runtime ('x86-32', | |
119 'x86-64', etc.); the value is a URL for the desired NaCl module. | |
120 --> | |
121 <div id="c_salt_integration_test_content"/> | |
122 <script type="text/javascript"> | |
123 contentDiv = document.getElementById('c_salt_integration_test_content'); | |
124 var nexes = 'ARM: c_salt_integration_test_arm.nexe\n' | |
125 + 'x86-32: c_salt_integration_test_x86_32.nexe\n' | |
126 + 'x86-64: c_salt_integration_test_x86_64.nexe '; | |
127 contentDiv.innerHTML = '<embed name="nacl_module" ' | |
128 + 'id="c_salt_integration_test" ' | |
129 + 'width=0 height=0 ' | |
130 + 'type="application/x-nacl-srpc" ' | |
131 + 'onload="moduleDidLoad();" />'; | |
132 // Note: this code is here to work around a bug in Chromium build | |
133 // #47357. See also | |
134 // http://code.google.com/p/nativeclient/issues/detail?id=500 | |
135 document.getElementById('c_salt_integration_test').nexes = nexes; | |
136 </script> | |
137 </p> | |
138 </body> | |
139 </html> | |
OLD | NEW |