[Release] Webkit-EFL Ver. 2.0_beta_118996_0.6.22
[framework/web/webkit-efl.git] / LayoutTests / fast / events / change-frame-focus.html
1 <html>
2 <head>
3     <script>
4         function log(msg)
5         {
6             document.getElementById("log").appendChild(
7                 document.createTextNode(msg + "\n"));
8         }
9         
10         function setFrameHandler(frameId)
11         {
12             if (frameId == "") {
13                 window.onfocus = function()
14                 {
15                     log("main frame focused.");
16                 }
17             
18                 window.onblur = function()
19                 {
20                     log("main frame blurred.");
21                 }
22             } else {
23                 var frameWin = document.getElementById(frameId).contentWindow;
24                 frameWin.onfocus = function()
25                 {
26                     log(frameId + " focused.");
27                 }
28
29                 frameWin.onblur = function()
30                 {
31                     log(frameId + " blurred.");
32                 }
33             }
34         }
35
36         function setFrameFocus(frameId)
37         {
38             if (frameId == "") {
39                 window.focus();
40             } else {
41                 var frameWin = document.getElementById(frameId).contentWindow;
42                 frameWin.focus();
43             }
44         }
45
46         function testMainFrameToIFrameFocus()
47         {
48             log("\nTest: main frame to iframe.");
49             setFrameFocus("");
50             setFrameFocus("iframe1");
51         }
52
53         function testIFrameToMainFrameFocus()
54         {
55             log("\nTest: iframe to main frame.");
56             setFrameFocus("iframe1");
57             setFrameFocus("");
58         }
59
60         function testIFrameToIFrameFocus()
61         {
62             log("\nTest: iframe1 to iframe2.");
63             setFrameFocus("iframe1");
64             setFrameFocus("iframe2");
65             setFrameFocus("iframe1");
66         }
67
68         function testFrame1OnBlurSetFrame2Focus()
69         {
70             var frameWin1 = document.getElementById("iframe1").contentWindow;
71             frameWin1.onfocus = function()
72             {
73                 log("iframe1 focused.");
74             }
75
76             frameWin1.onblur = function()
77             {
78                 log("iframe1 blurred.");
79                 // This set focus request will be ignored because the FocusController
80                 // is in the middle of changing focused frame.
81                 setFrameFocus("iframe2");
82             }
83
84             log("\nTest: iframe1 onblur sets iframe2 focus.");
85             setFrameFocus("");
86             setFrameFocus("iframe1");
87             setFrameFocus("");
88         }
89
90         function testFrame1OnBlurSetFrame1Focus()
91         {
92             var frameWin1 = document.getElementById("iframe1").contentWindow;
93             frameWin1.onfocus = function()
94             {
95                 log("iframe1 focused.");
96             }
97
98             frameWin1.onblur = function()
99             {
100                 log("iframe1 blurred.");
101                 // This set focus request will be ignored because the FocusController
102                 // is in the middle of changing focused frame.
103                 setFrameFocus("iframe1");
104             }
105
106             log("\nTest: iframe1 onblur sets iframe1 focus.");
107             setFrameFocus("");
108             setFrameFocus("iframe1");
109             setFrameFocus("");
110         }
111
112         function testFrame1OnFocusSetFrame2Focus()
113         {
114             var frameWin1 = document.getElementById("iframe1").contentWindow;
115             frameWin1.onfocus = function()
116             {
117                 log("iframe1 focused.");
118                 // This set focus request will be ignored because the FocusController
119                 // is in the middle of changing focused frame.
120                 setFrameFocus("iframe2");
121             }
122
123             frameWin1.onblur = function()
124             {
125                 log("iframe1 blurred.");
126             }
127
128             log("\nTest: iframe1 onfocus sets iframe2 focus.");
129             setFrameFocus("");
130             setFrameFocus("iframe1");
131         }
132
133         function testFrame1OnFocusSetFrame1Focus()
134         {
135             var frameWin1 = document.getElementById("iframe1").contentWindow;
136             frameWin1.onfocus = function()
137             {
138                 log("iframe1 focused.");
139                 // This set focus request will be ignored because the FocusController
140                 // is in the middle of changing focused frame.
141                 setFrameFocus("iframe1");
142             }
143
144             frameWin1.onblur = function()
145             {
146                 log("iframe1 blurred.");
147             }
148
149             log("\nTest: iframe1 onfocus sets iframe1 focus.");
150             setFrameFocus("");
151             setFrameFocus("iframe1");
152         }
153
154         function test()
155         {
156             if (window.layoutTestController) {
157                 layoutTestController.dumpAsText();
158             }
159
160             setFrameHandler("");
161             setFrameHandler("iframe1");
162             setFrameHandler("iframe2");
163
164             // Test the correct frame is focused when switching focus from
165             // one frame to another.
166             testMainFrameToIFrameFocus();
167             testIFrameToMainFrameFocus();
168             testIFrameToIFrameFocus();
169             
170             // New setting focus request will be ignored if the focus controller
171             // is in the middle of switching focused frame (onblur, onfocus events).
172             testFrame1OnBlurSetFrame2Focus();
173             testFrame1OnBlurSetFrame1Focus();
174             testFrame1OnFocusSetFrame2Focus();
175             testFrame1OnFocusSetFrame1Focus();
176             
177             // Restore iframe1 onfocus and onblur handlers.
178             setFrameHandler("iframe1");
179         }
180
181     </script>
182 </head>
183 <body onload="test()">
184     <iframe id="iframe1" style="width: 100px; height: 100px;"></iframe>
185     <iframe id="iframe2" style="width: 100px; height: 100px;"></iframe>
186     <p>Test the focus controller working properly when switching focused frame. Here are the cases tested:
187     <br>
188     <br>-. Correct frame is focused when switching focus from one frame to another:
189     <br>1. main frame -> iframe
190     <br>2. iframe to main frame
191     <br>3. iframe 1 to iframe 2
192     <br>
193     <br>-. New setting focus request will be ignored if the focus controller is in the middle of switching focused frame (onblur, onfocus events):
194     <br>1. iframe 1 onblur sets iframe 2 focus.
195     <br>2. iframe 1 onblur sets iframe 1 focus.
196     <br>3. iframe 1 onfocus sets iframe 2 focus.
197     <br>4. iframe 1 onfocus sets iframe 1 focus.
198     </p>
199     <pre id="log"></pre>
200 </body>
201 </html>