Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / custom / registration-context-sharing.html
blob9a9e8f9fb06e7328aa04345620a0a139336fe42d
1 <!DOCTYPE html>
2 <script src="../../../resources/testharness.js"></script>
3 <script src="../../../resources/testharnessreport.js"></script>
4 <script src="test-harness-utils.js"></script>
5 <body>
6 <script>
7 function TestRegistrationContextSharing(window, documentA, documentB) {
8 this.window = window;
9 this.documentA = documentA;
10 this.documentB = documentB;
13 TestRegistrationContextSharing.prototype.
14 testRegistrationContextIsShared = function () {
15 this.testUpgrade_oneDefinitionShouldUpgradeMultipleDocuments();
16 this.testRegisterInAInstantiateInB_shouldActivateDefinition();
19 TestRegistrationContextSharing.prototype.
20 testUpgrade_oneDefinitionShouldUpgradeMultipleDocuments = function () {
21 var documentAUpgradeCandidate = this.documentA.createElement('x-u');
22 documentAUpgradeCandidate.dataset.name = 'document A upgrade candidate';
24 var documentBUpgradeCandidate = this.documentB.createElement('x-u');
25 documentBUpgradeCandidate.dataset.name = 'document B upgrade candidate';
27 var invocations = [];
28 function created() {
29 invocations.push('created ' + this.dataset.name + ' with prototype ' +
30 'tagged ' + this.prototypeTag);
33 var protoU = Object.create(this.window.HTMLElement.prototype);
34 protoU.prototypeTag = 'U';
35 protoU.createdCallback = created;
36 this.documentB.registerElement('x-u', {prototype: protoU});
38 assert_array_equals(
39 invocations,
40 ['created document A upgrade candidate with prototype tagged U',
41 'created document B upgrade candidate with prototype tagged U'],
42 'the created callback should have been called for both elements ' +
43 'in creation order');
46 TestRegistrationContextSharing.prototype.
47 testRegisterInAInstantiateInB_shouldActivateDefinition = function () {
48 var invocations = [];
49 function created() {
50 invocations.push('created ' + this.dataset.name + ' with prototype ' +
51 'tagged ' + this.prototypeTag);
54 var protoV = Object.create(this.window.HTMLElement.prototype);
55 protoV.prototypeTag = 'V';
56 protoV.createdCallback = created;
57 this.documentA.registerElement('x-v', {prototype: protoV});
59 var div = this.documentB.createElement('div');
60 div.innerHTML = '<x-v data-name="document B element V"></x-v>';
61 assert_array_equals(
62 invocations,
63 ['created document B element V with prototype tagged V'],
64 'the created callback should have been called for the x-v element');
67 (function () {
69 var t = async_test('registration context is shared with some ' +
70 'DOMImplementation-created documents');
72 withFrame(t.step_func(function (frame) {
73 var documentA = frame.contentDocument;
74 var documentB = documentA.implementation.createHTMLDocument();
75 var tester = new TestRegistrationContextSharing(
76 frame.contentWindow, documentA, documentB);
77 tester.testRegistrationContextIsShared();
78 frame.remove();
79 }));
81 withFrame(t.step_func(function (frame) {
82 var documentA = frame.contentDocument;
83 var documentB = documentA.implementation.createDocument(
84 'http://www.w3.org/1999/xhtml', 'html');
85 var tester = new TestRegistrationContextSharing(
86 frame.contentWindow, documentA, documentB);
87 tester.testRegistrationContextIsShared();
88 frame.remove();
89 }));
91 withFrame(t.step_func(function (frame) {
92 var documentA = frame.contentDocument;
93 var documentB = documentA.implementation.createDocument(
94 'http://www.w3.org/1999/xhtml', 'html');
95 var documentC = documentB.implementation.createHTMLDocument();
96 var tester = new TestRegistrationContextSharing(
97 frame.contentWindow, documentA, documentC);
98 tester.testRegistrationContextIsShared();
99 frame.remove();
100 t.done();
101 }));
103 })();
105 (function () {
107 var t = async_test('registration context is shared with imported documents');
108 var link;
109 var documentA;
111 withFrame(t.step_func(function (frame) {
112 documentA = frame.contentDocument;
114 link = documentA.createElement('link');
115 link.rel = 'import';
116 link.href = 'resources/empty-document.html';
117 link.onload = t.step_func(function () {
118 var documentB = link.import;
119 var tester = new TestRegistrationContextSharing(window,
120 documentA, documentB);
121 tester.testRegistrationContextIsShared();
122 t.done();
125 documentA.head.appendChild(link);
126 }));
128 })();
130 </script>