2 <script src="../../../resources/testharness.js"></script>
3 <script src="../../../resources/testharnessreport.js"></script>
4 <script src="test-harness-utils.js"></script>
7 function TestRegistrationContextSharing(window, documentA, documentB) {
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';
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});
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 ' +
46 TestRegistrationContextSharing.prototype.
47 testRegisterInAInstantiateInB_shouldActivateDefinition = function () {
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>';
63 ['created document B element V with prototype tagged V'],
64 'the created callback should have been called for the x-v element');
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();
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();
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();
107 var t = async_test('registration context is shared with imported documents');
111 withFrame(t.step_func(function (frame) {
112 documentA = frame.contentDocument;
114 link = documentA.createElement('link');
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();
125 documentA.head.appendChild(link);