3 <script src=
"../../../resources/testharness.js"></script>
4 <script src=
"../../../resources/testharnessreport.js"></script>
5 <script src=
"test-harness-utils.js"></script>
10 var test
= async_test('callbacks created in the outer frame\'s context are ' +
11 'invoked in that context');
13 withFrame(function (frame
) {
14 var outerDocument
= document
;
15 var proto
= Object
.create(frame
.contentWindow
.HTMLElement
.prototype);
16 proto
.createdCallback
= test
.step_func(function () {
17 assert_equals(document
, outerDocument
,
18 'the context should be the outer window');
20 var doc
= frame
.contentDocument
;
21 doc
.registerElement('x-a', {prototype: proto
});
22 var script
= doc
.createElement('script');
23 script
.textContent
= 'document.body.innerHTML = "<x-a></x-a>";';
24 doc
.body
.appendChild(script
);
34 var test
= async_test('callbacks created in the inner frame\'s context are ' +
35 'invoked in that context');
37 withFrame(function (frame
) {
38 document
.name
= 'outer document';
40 var doc
= frame
.contentDocument
;
41 doc
.name
= 'inner document';
43 var step
= test
.step_func(function (event
) {
44 switch (event
.data
.step
) {
46 doc
.body
.firstChild
.remove();
50 window
.removeEventListener('message', step
);
51 assert_equals(event
.data
.name
, 'inner document',
52 'the context should be the inner window');
60 window
.addEventListener('message', step
);
62 var script
= doc
.createElement('script');
64 'var proto = Object.create(HTMLElement.prototype); ' +
65 'proto.detachedCallback = function () { ' +
66 ' window.parent.postMessage(' +
67 ' {step: "assert", name: document.name}, "*");' +
69 'document.registerElement("x-a", {prototype: proto}); ' +
70 'document.body.innerHTML = "<x-a></x-a>"; ' +
71 'window.parent.postMessage({step: "remove"}, "*");';
72 doc
.body
.appendChild(script
);