Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / custom / callback-context.html
blobbbb9cbd42af8994f02a6a77c1b82c7f599491125
1 <!DOCTYPE html>
2 <!DOCTYPE html>
3 <script src="../../../resources/testharness.js"></script>
4 <script src="../../../resources/testharnessreport.js"></script>
5 <script src="test-harness-utils.js"></script>
6 <body>
7 <script>
8 (function () {
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');
19 });
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);
25 frame.remove();
26 test.done();
27 });
29 })();
32 (function () {
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) {
45 case 'remove':
46 doc.body.firstChild.remove();
47 break;
49 case 'assert':
50 window.removeEventListener('message', step);
51 assert_equals(event.data.name, 'inner document',
52 'the context should be the inner window');
53 frame.remove();
54 test.done();
56 default:
57 assert_not_reached();
59 });
60 window.addEventListener('message', step);
62 var script = doc.createElement('script');
63 script.textContent =
64 'var proto = Object.create(HTMLElement.prototype); ' +
65 'proto.detachedCallback = function () { ' +
66 ' window.parent.postMessage(' +
67 ' {step: "assert", name: document.name}, "*");' +
68 '}; ' +
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);
73 });
75 })();
76 </script>