Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / dom / domstring-attribute-reflection.html
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../../resources/js-test.js"></script>
5 <script>
6 var element;
7
8 function testDOMStringReflection(elementName, contentAttributeName, idlAttributeName, treatNullAsEmptyString) {
9     idlAttributeName = idlAttributeName || contentAttributeName;
10     element = document.createElement(elementName);
11     debug('Reflected DOMString attribute test for ' + elementName + '/@' + contentAttributeName);
12     debug('Initial value:');
13     shouldBeEqualToString('element.' + idlAttributeName, '');
14     shouldBeNull('element.getAttribute("' + contentAttributeName + '")');
15
16     debug('Setting a value via the IDL attribute:');
17     shouldBeEqualToString('element.' + idlAttributeName + ' = "foo"; element.' + idlAttributeName, 'foo');
18     shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', 'foo');
19
20     debug('Setting a value via the content attribute:');
21     shouldBeEqualToString('element.setAttribute("' + contentAttributeName + '", " bar\\n"); element.' + idlAttributeName, ' bar\n');
22     shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', ' bar\n');
23
24     debug('Setting null via the IDL attribute:');
25     if (treatNullAsEmptyString) {
26         shouldBeEqualToString('element.' + idlAttributeName + ' = null; element.' + idlAttributeName, '');
27         shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', '');
28     } else {
29         shouldBeEqualToString('element.' + idlAttributeName + ' = null; element.' + idlAttributeName, 'null');
30         shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', 'null');
31     }
32
33     debug('Setting null via the content attribute:');
34     shouldBeEqualToString('element.setAttribute("' + contentAttributeName + '", null); element.' + idlAttributeName, 'null');
35     shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', 'null');
36
37     debug('Setting undefined via the IDL attribute:');
38     shouldBeEqualToString('element.' + idlAttributeName + ' = undefined; element.' + idlAttributeName, 'undefined');
39     shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', 'undefined');
40
41     debug('Setting undefined via the content attribute:');
42     shouldBeEqualToString('element.setAttribute("' + contentAttributeName + '", undefined); element.' + idlAttributeName, 'undefined');
43     shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', 'undefined');
44
45     debug('Setting non-string via the IDL attribute:');
46     shouldBeEqualToString('element.' + idlAttributeName + ' = 123; element.' + idlAttributeName, '123');
47     shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', '123');
48
49     debug('Setting non-string via the content attribute:');
50     shouldBeEqualToString('element.setAttribute("' + contentAttributeName + '", 456); element.' + idlAttributeName, '456');
51     shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', '456');
52
53     debug('\n');
54 }
55
56 testDOMStringReflection('button', 'name');
57 testDOMStringReflection('fieldset', 'name');
58 testDOMStringReflection('form', 'name');
59 testDOMStringReflection('input', 'name');
60 testDOMStringReflection('input', 'step');
61 testDOMStringReflection('keygen', 'name');
62 testDOMStringReflection('menu', 'type');
63 testDOMStringReflection('menu', 'label');
64 testDOMStringReflection('menuitem', 'type');
65 testDOMStringReflection('menuitem', 'label');
66 testDOMStringReflection('object', 'name');
67 testDOMStringReflection('output', 'name');
68 testDOMStringReflection('select', 'name');
69 testDOMStringReflection('textarea', 'name');
70
71 // [TreatNullAs=EmptyString]
72 testDOMStringReflection('frame', 'marginheight', 'marginHeight', true);
73 testDOMStringReflection('frame', 'marginwidth', 'marginWidth', true);
74 testDOMStringReflection('iframe', 'marginheight', 'marginHeight', true);
75 testDOMStringReflection('iframe', 'marginwidth', 'marginWidth', true);
76 testDOMStringReflection('body', 'text', 'text', true);
77 testDOMStringReflection('body', 'link', 'link', true);
78 testDOMStringReflection('body', 'alink', 'aLink', true);
79 testDOMStringReflection('body', 'vlink', 'vLink', true);
80 testDOMStringReflection('body', 'bgcolor', 'bgColor', true);
81 testDOMStringReflection('font', 'color', 'color', true);
82 testDOMStringReflection('img', 'border', 'border', true);
83 testDOMStringReflection('object', 'border', 'border', true);
84 testDOMStringReflection('table', 'bgcolor', 'bgColor', true);
85 testDOMStringReflection('table', 'cellpadding', 'cellPadding', true);
86 testDOMStringReflection('table', 'cellspacing', 'cellSpacing', true);
87 testDOMStringReflection('td', 'bgcolor', 'bgColor', true);
88 testDOMStringReflection('th', 'bgcolor', 'bgColor', true);
89 testDOMStringReflection('tr', 'bgcolor', 'bgColor', true);
90
91
92 // Add more DOMString attributes!
93
94 </script>
95 </body>
96 </html>