6 document
.getElementById("log").appendChild(
7 document
.createTextNode(msg
+ "\n"));
10 function setFrameHandler(frameId
)
13 window
.onfocus = function()
15 log("main frame focused.");
18 window
.onblur = function()
20 log("main frame blurred.");
23 var frameWin
= document
.getElementById(frameId
).contentWindow
;
24 frameWin
.onfocus = function()
26 log(frameId
+ " focused.");
29 frameWin
.onblur = function()
31 log(frameId
+ " blurred.");
36 function setFrameFocus(frameId
)
41 var frameWin
= document
.getElementById(frameId
).contentWindow
;
46 function testMainFrameToIFrameFocus()
48 log("\nTest: main frame to iframe.");
50 setFrameFocus("iframe1");
53 function testIFrameToMainFrameFocus()
55 log("\nTest: iframe to main frame.");
56 setFrameFocus("iframe1");
60 function testIFrameToIFrameFocus()
62 log("\nTest: iframe1 to iframe2.");
63 setFrameFocus("iframe1");
64 setFrameFocus("iframe2");
65 setFrameFocus("iframe1");
68 function testFrame1OnBlurSetFrame2Focus()
70 var frameWin1
= document
.getElementById("iframe1").contentWindow
;
71 frameWin1
.onfocus = function()
73 log("iframe1 focused.");
76 frameWin1
.onblur = function()
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");
84 log("\nTest: iframe1 onblur sets iframe2 focus.");
86 setFrameFocus("iframe1");
90 function testFrame1OnBlurSetFrame1Focus()
92 var frameWin1
= document
.getElementById("iframe1").contentWindow
;
93 frameWin1
.onfocus = function()
95 log("iframe1 focused.");
98 frameWin1
.onblur = function()
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");
106 log("\nTest: iframe1 onblur sets iframe1 focus.");
108 setFrameFocus("iframe1");
112 function testFrame1OnFocusSetFrame2Focus()
114 var frameWin1
= document
.getElementById("iframe1").contentWindow
;
115 frameWin1
.onfocus = function()
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");
123 frameWin1
.onblur = function()
125 log("iframe1 blurred.");
128 log("\nTest: iframe1 onfocus sets iframe2 focus.");
130 setFrameFocus("iframe1");
133 function testFrame1OnFocusSetFrame1Focus()
135 var frameWin1
= document
.getElementById("iframe1").contentWindow
;
136 frameWin1
.onfocus = function()
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");
144 frameWin1
.onblur = function()
146 log("iframe1 blurred.");
149 log("\nTest: iframe1 onfocus sets iframe1 focus.");
151 setFrameFocus("iframe1");
156 if (window
.testRunner
) {
157 testRunner
.dumpAsText();
161 setFrameHandler("iframe1");
162 setFrameHandler("iframe2");
164 // Test the correct frame is focused when switching focus from
165 // one frame to another.
166 testMainFrameToIFrameFocus();
167 testIFrameToMainFrameFocus();
168 testIFrameToIFrameFocus();
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();
177 // Restore iframe1 onfocus and onblur handlers.
178 setFrameHandler("iframe1");
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:
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
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.