Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / dom / HTMLDocument / active-element-frames.html
1 <!DOCTYPE html>
2 <body>
3 <p>When the contents of an iframe have focus, the activeElement in the parent document should be the iframe element.</p>
4 <input id="input-0">
5 <iframe id="frame-1"></iframe>
6 <iframe id="frame-2"></iframe>
7 <pre id="out"></pre>
8 <script>
9
10 var doc0 = document;
11 var input0 = doc0.getElementById('input-0');
12
13 var iframe1 = doc0.getElementById('frame-1');
14 var doc1 = iframe1.contentDocument;
15 var input1 = doc1.body.appendChild(doc1.createElement('input'));
16
17 var iframe2 = doc0.getElementById('frame-2');
18 var doc2 = iframe2.contentDocument;
19 var input2 = doc2.body.appendChild(doc2.createElement('input'));
20
21 var iframe3 = doc1.body.appendChild(doc1.createElement('iframe'));
22 var doc3 = iframe3.contentDocument;
23 var input3 = doc3.body.appendChild(doc3.createElement('input'));
24
25 var iframe4 = doc2.body.appendChild(doc2.createElement('iframe'));
26 var doc4 = iframe4.contentDocument;
27 var input4 = doc4.body.appendChild(doc4.createElement('input'));
28
29 // Set up IDs for logging.
30 for (var i = 0; i < 5; i++) {
31     window['doc' + i].body.id = 'body-' + i;
32     if (i > 0)
33         window['iframe' + i].id = 'iframe-' + i;
34     window['input' + i].id = 'input-' + i;
35 }
36
37 function describe(obj)
38 {
39     if (obj === document)
40         return 'top';
41     if (obj.defaultView && obj.defaultView.frameElement)
42         return describe(obj.defaultView.frameElement);
43     return describe(obj.ownerDocument) + '/' + obj.id;
44 }
45
46 function print(s)
47 {
48     document.getElementById('out').textContent += s + '\n';
49 }
50
51 function assertActiveElement(doc, expected)
52 {
53     if (doc.activeElement === expected)
54         print('PASS: ' + describe(doc) + ' document.activeElement is ' + describe(doc.activeElement));
55     else
56         print('FAIL: ' + describe(doc) + ' document.activeElement is ' + describe(doc.activeElement) + ' but expected ' + describe(expected));
57 }
58
59 if (window.testRunner)
60     testRunner.dumpAsText();
61
62 print('Focusing ' + describe(input0));
63 input0.focus();
64 assertActiveElement(doc0, input0);
65 assertActiveElement(doc1, doc1.body);
66 assertActiveElement(doc2, doc2.body);
67 assertActiveElement(doc3, doc3.body);
68 assertActiveElement(doc4, doc4.body);
69
70 print('\nFocusing ' + describe(input1));
71 input1.focus();
72 assertActiveElement(doc0, iframe1);
73 assertActiveElement(doc1, input1);
74 assertActiveElement(doc2, doc2.body);
75 assertActiveElement(doc3, doc3.body);
76 assertActiveElement(doc4, doc4.body);
77
78 print('\nFocusing ' + describe(input2));
79 input2.focus();
80 assertActiveElement(doc0, iframe2);
81 assertActiveElement(doc1, doc1.body);
82 assertActiveElement(doc2, input2);
83 assertActiveElement(doc3, doc3.body);
84 assertActiveElement(doc4, doc4.body);
85
86 print('\nFocusing ' + describe(input3));
87 input3.focus();
88 assertActiveElement(doc0, iframe1);
89 assertActiveElement(doc1, iframe3);
90 assertActiveElement(doc2, doc2.body);
91 assertActiveElement(doc3, input3);
92 assertActiveElement(doc4, doc4.body);
93
94 print('\nFocusing ' + describe(input4));
95 input4.focus();
96 assertActiveElement(doc0, iframe2);
97 assertActiveElement(doc1, doc1.body);
98 assertActiveElement(doc2, iframe4);
99 assertActiveElement(doc3, doc3.body);
100 assertActiveElement(doc4, input4);
101 </script>
102 </body>