4 <p>This tests that changing selection in an iframe does not fire selectionchange event in the parent document and vice versa.
</p>
6 <iframe id=
"child" src=
"about:blank"></iframe>
7 <div id=
"parent">WebKit rocks
</div>
13 var parent
= document
.getElementById('parent');
14 var child
= document
.getElementById('child');
15 var childDocument
= (child
.contentWindow
|| child
.contentDocument
).document
;
16 if (!childDocument
.body
)
17 childDocument
.appendChild(document
.createElement('body'));
18 childDocument
.body
.innerHTML
= 'hello world';
20 var selectionOfParent
= window
.getSelection();
21 var selectionOfChild
= child
.contentDocument
.getSelection();
25 selector: function() {
26 selectionOfParent
.selectAllChildren(document
.body
);
27 return "all of parent's document body";
33 selector: function() {
34 selectionOfChild
.selectAllChildren(childDocument
.body
);
35 return "all of parent's document body";
41 selector: function() {
42 var range
= document
.createRange();
43 range
.setStart(parent
.firstChild
, 7);
44 range
.setEnd(parent
.firstChild
, 12);
45 selectionOfParent
.removeAllRanges();
46 selectionOfParent
.addRange(range
);
47 return '"rocks" of "WebKit rocks" in the parent';
49 expected
: 'parent, parent',
50 alt_expected
: 'parent',
53 selector: function() {
54 var range
= childDocument
.createRange();
55 range
.setStart(childDocument
.body
.firstChild
, 6);
56 range
.setEnd(childDocument
.body
.firstChild
, 11);
57 selectionOfChild
.removeAllRanges();
58 selectionOfChild
.addRange(range
);
59 return '"world" of "hello world" in the child';
61 expected
: 'child, child',
62 alt_expected
: 'child',
68 if (window
.testRunner
) {
69 testRunner
.dumpAsText();
70 testRunner
.waitUntilDone();
75 function logger(event
) {
76 if (event
.target
== childDocument
)
78 else if (event
.target
== document
)
84 function verify(selected
, expected
, alt_expected
) {
85 setTimeout(function () {
86 var actual
= log
.length
? '' : 'none';
87 for (var i
= 0; i
< log
.length
; i
++) {
92 var result
= 'selecting ' + selected
+ ' fired selection change events from ' + actual
;
93 if (actual
== expected
|| actual
== alt_expected
)
94 result
= 'PASS: ' + result
;
96 result
= 'FAIL: ' + result
+ ' but expected ' + expected
+ (alt_expected
? ' or ' + alt_expected
: '');
97 var console
= document
.getElementById('console');
98 var listItem
= document
.createElement('li');
99 console
.appendChild(listItem
);
100 listItem
.appendChild(document
.createTextNode(result
));
104 // selects and verify in turn until all tests are ran
108 selected
= tests
[i
].selector();
110 verify(selected
, tests
[i
].expected
, tests
[i
].alt_expected
);
113 if (i
== tests
.length
) {
114 if (window
.testRunner
)
115 document
.getElementById('container').style
.display
= 'none';
116 testRunner
.notifyDone();
120 setTimeout(timer
, 0);
123 document
.addEventListener('selectionchange', logger
, false);
124 childDocument
.onselectionchange
= logger
;