[JSC] Add tests for explicit serialization values
[WebKit.git] / LayoutTests / platform / chromium / fast / storage / serialized-script-value.html
1 <html>
2     <head>
3         <script src="../../../../fast/js/resources/js-test-pre.js"></script>
4         <script src="../../../../fast/storage/resources/serialized-script-value.js"></script>
5     </head>
6     <body>
7         <script>
8 /*
9     See LayoutTests/fast/storage/serialized-script-value.js for the
10     corresponding test of the JSC serialization format.
11 */
12
13 function testSerialization(obj, values, oldFormat, serializeExceptionValue) {
14     _testSerialization(2, obj, values, oldFormat, serializeExceptionValue);
15 }
16
17 // we only test a few cases of the "old" serialization format because
18 // that is all that was left around from previous tests. Those values
19 // are only persisted out in the world in IndexedDB stores that were
20 // written with implementations built before mid-2011.
21 testSerialization({foo: 'zoo', bar: {baz: 'myNewKey'}},
22                   [ 0x02ff, 0x003f, 0x3f6f, 0x5301, 0x6603,
23                     0x6f6f, 0x013f, 0x0353, 0x6f7a, 0x3f6f,
24                     0x5301, 0x6203, 0x7261, 0x013f, 0x3f6f,
25                     0x5302, 0x6203, 0x7a61, 0x023f, 0x0853,
26                     0x796d, 0x654e, 0x4b77, 0x7965, 0x017b,
27                     0x027b ]);
28
29 testSerialization({foo: 'zoo', bar: 'myNewKey'},
30                   [0x02ff, 0x003f, 0x3f6f, 0x5301, 0x6603,
31                    0x6f6f, 0x013f, 0x0353, 0x6f7a, 0x3f6f,
32                    0x5301, 0x6203, 0x7261, 0x013f, 0x0853,
33                    0x796d, 0x654e, 0x4b77, 0x7965, 0x027b]);
34
35 testSerialization([], [0x02ff, 0x003f, 0x0041, 0x0024, 0x0000 ]);
36 testSerialization({foo: "zoo"},
37                   [0x02ff, 0x003f, 0x3f6f, 0x5301, 0x6603, 0x6f6f,
38                    0x013f, 0x0353, 0x6f7a, 0x7b6f, 0x0001],
39                   [0x0353, 0x6f66, 0x536f, 0x7a03, 0x6f6f, 0x017b]);
40 testSerialization({foo: null},
41                   [0x02ff, 0x003f, 0x3f6f, 0x5301, 0x6603, 0x6f6f,
42                    0x013f, 0x7b30, 0x0001],
43                   [0x0353, 0x6f66, 0x306f, 0x017b]);
44 testSerialization({}, [0x02ff, 0x003f, 0x7b6f, 0x0000], [0x007b]);
45
46 testSerialization(undefined, [0x02ff, 0x003f, 0x005f]);
47 testSerialization(true, [0x02ff, 0x003f, 0x0054]);
48 testSerialization(false, [0x02ff, 0x003f, 0x0046]);
49 // Sparse array deserialization is broken.
50 // See: https://bugs.webkit.org/show_bug.cgi?id=96838
51 // testSerialization(new Array(100), [0x02ff, 0x003f, 0x6461, 0x0040, 0x0064]);
52 testSerialization(10, [0x02ff, 0x003f, 0x1449]);
53 testSerialization(-10, [0x02ff, 0x003f, 0x1349]);
54 testSerialization(Math.pow(2,30), [0x02ff, 0x003f, 0x8049, 0x8080, 0x0880]);
55 testSerialization(Math.pow(2,55), [0x02ff, 0x003f, 0x004e, 0x0000, 0x0000,
56                                    0x6000, 0x0043]);
57 testSerialization(1.23, [0x02ff, 0x003f, 0xae4e, 0xe147, 0x147a, 0xf3ae, 0x003f]);
58 testSerialization("", [0x02ff, 0x003f, 0x0053]);
59 testSerialization("abc", [0x02ff, 0x003f, 0x0353, 0x6261, 0x0063]);
60 testSerialization({integer: 123}, [0x02ff, 0x003f, 0x3f6f, 0x5301, 0x6907,
61                                    0x746e, 0x6765, 0x7265, 0x013f, 0xf649,
62                                    0x7b01, 0x0001]);
63 testSerialization({string: "str"}, [0x02ff, 0x003f, 0x3f6f, 0x5301, 0x7306,
64                                     0x7274, 0x6e69, 0x3f67, 0x5301, 0x7303,
65                                     0x7274, 0x017b]);
66 testSerialization({list: [1,2,3]}, [0x02ff, 0x003f, 0x3f6f, 0x5301, 0x6c04,
67                                     0x7369, 0x3f74, 0x4101, 0x3f03, 0x4902,
68                                     0x3f02, 0x4902, 0x3f04, 0x4902, 0x2406,
69                                     0x0300, 0x017b]);
70 testSerialization(null, [0x02ff, 0x003f, 0x0030]);
71 testSerialization(/abc/, [0x02ff, 0x003f, 0x0352, 0x6261, 0x0063]);
72
73 var innerObject = {hello: "there"};
74 var outerObject = {inner: innerObject};
75 outerObject['outer'] = innerObject;
76 testSerialization(outerObject, [0x02ff, 0x003f, 0x3f6f, 0x5301, 0x6905,
77                                 0x6e6e, 0x7265, 0x013f, 0x3f6f, 0x5302,
78                                 0x6805, 0x6c65, 0x6f6c, 0x023f, 0x0553,
79                                 0x6874, 0x7265, 0x7b65, 0x3f01, 0x5302,
80                                 0x6f05, 0x7475, 0x7265, 0x023f, 0x015e,
81                                 0x027b]);
82 testSerialization(innerObject, [0x02ff, 0x003f, 0x3f6f, 0x5301, 0x6805,
83                                 0x6c65, 0x6f6c, 0x013f, 0x0553, 0x6874,
84                                 0x7265, 0x7b65, 0x0001]);
85
86 var unicodeObject = {a: 'a', u: String.fromCharCode(0x03B1,0x03B2), d: 42};
87 testSerialization(unicodeObject,
88                   [0x02ff, 0x003f, 0x3f6f, 0x5301, 0x6101,
89                    0x013f, 0x0153, 0x3f61, 0x5301, 0x7501,
90                    0x013f, 0x0463, 0x03b1, 0x03b2, 0x013f,
91                    0x0153, 0x3f64, 0x4901, 0x7b54, 0x0003],
92                   [0x01ff, 0x003f, 0x3f6f, 0x5301, 0x6101,
93                    0x013f, 0x0153, 0x3f61, 0x5301, 0x7501,
94                    0x013f, 0x0453, 0xb1ce, 0xb2ce, 0x013f,
95                    0x0153, 0x3f64, 0x4901, 0x7b54, 0x0003]);
96 unicodeObject.a = 'ab';
97 testSerialization(unicodeObject,
98                   [0x02ff, 0x003f, 0x3f6f, 0x5301, 0x6101,
99                    0x013f, 0x0253, 0x6261, 0x013f, 0x0153,
100                    0x3f75, 0x0001, 0x0463, 0x03b1, 0x03b2,
101                    0x013f, 0x0153, 0x3f64, 0x4901, 0x7b54,
102                    0x0003],
103                   [0x01ff, 0x003f, 0x3f6f, 0x5301, 0x6101,
104                    0x013f, 0x0253, 0x6261, 0x013f, 0x0153,
105                    0x3f75, 0x5301, 0xce04, 0xceb1, 0x3fb2,
106                    0x5301, 0x6401, 0x013f, 0x5449, 0x037b]);
107
108 testSerialization(function(){}, [], null, DOMException.DATA_CLONE_ERR);
109         </script>
110         <script src="../../../../fast/js/resources/js-test-post.js"></script>
111     </body>
112 </html>