Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / dom / idl-union-type-unittest.html
1 <!DOCTYPE html>
2 <script src="../../resources/js-test.js"></script>
3 <script>
4 description('IDL union types unittests');
5
6 if (window.internals) {
7     // The conversion rule prefers string over double, hence a value which
8     // is neither double nor string will be converted using ToString().
9
10     var unionTypesTest = internals.unionTypesTest();
11
12     debug('Tests for attributes');
13     shouldBe('unionTypesTest.doubleOrStringAttribute', '0');
14     unionTypesTest.doubleOrStringAttribute = 3.14;
15     shouldBe('unionTypesTest.doubleOrStringAttribute', '3.14');
16     unionTypesTest.doubleOrStringAttribute = "foo";
17     shouldBeEqualToString('unionTypesTest.doubleOrStringAttribute', 'foo');
18     unionTypesTest.doubleOrStringAttribute = undefined;
19     shouldBeEqualToString('unionTypesTest.doubleOrStringAttribute', 'undefined');
20     unionTypesTest.doubleOrStringAttribute = null;
21     shouldBeEqualToString('unionTypesTest.doubleOrStringAttribute', 'null');
22     unionTypesTest.doubleOrStringAttribute = {};
23     shouldBeEqualToString('unionTypesTest.doubleOrStringAttribute', '[object Object]');
24     unionTypesTest.doubleOrStringAttribute = [];
25     shouldBeEqualToString('unionTypesTest.doubleOrStringAttribute', '');
26     debug('');
27
28     debug('Tests for method arguments');
29     shouldBeEqualToString('unionTypesTest.doubleOrStringArg(3.14)', 'double is passed: 3.14');
30     shouldBeEqualToString('unionTypesTest.doubleOrStringArg("foo")', 'string is passed: foo');
31     shouldBeEqualToString('unionTypesTest.doubleOrStringArg(undefined)', 'string is passed: undefined');
32     shouldBeEqualToString('unionTypesTest.doubleOrStringArg(null)', 'string is passed: null');
33     shouldBeEqualToString('unionTypesTest.doubleOrStringArg({})', 'string is passed: [object Object]');
34     shouldBeEqualToString('unionTypesTest.doubleOrStringArg([])', 'string is passed: ');
35     // ToString(Date) can contain timezone, so we can't specify the expectation.
36     // Just check that doubleOrStringArg() doesn't throw an exception.
37     shouldBeEqualToString('typeof unionTypesTest.doubleOrStringArg(new Date)', 'string');
38     shouldThrow('unionTypesTest.doubleOrStringArg()');
39 }
40 </script>