dom/tests/mochitest/webcomponents/test_document_shared_registry.html

branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
equal deleted inserted replaced
-1:000000000000 0:3fd479c20146
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=783129
5 -->
6 <head>
7 <title>Test shared registry for associated HTML documents.</title>
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
10 </head>
11 <body>
12 <div id="container"></div>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=783129">Bug 783129</a>
14 <script>
15 var container = document.getElementById("container");
16
17 function createdCallbackFromMainDoc() {
18 var createdCallbackCalled = false;
19 var assocDoc = document.implementation.createHTMLDocument();
20
21 var proto = Object.create(HTMLElement.prototype);
22 proto.createdCallback = function() {
23 is(createdCallbackCalled, false, "created callback should only be called once in this tests.");
24 createdCallbackCalled = true;
25 runNextTest();
26 };
27
28 assocDoc.registerElement("x-associated-doc-callback-elem", { prototype: proto });
29 document.createElement("x-associated-doc-callback-elem");
30 }
31
32 function createdCallbackFromAssociatedDoc() {
33 var createdCallbackCalled = false;
34 var assocDoc = document.implementation.createHTMLDocument();
35
36 var proto = Object.create(HTMLElement.prototype);
37 proto.createdCallback = function() {
38 is(createdCallbackCalled, false, "created callback should only be called once in this tests.");
39 createdCallbackCalled = true;
40 runNextTest();
41 };
42
43 assocDoc.registerElement("x-main-doc-callback-elem", { prototype: proto });
44 assocDoc.createElement("x-main-doc-callback-elem");
45 }
46
47 function createdCallbackFromDocHTMLNamespace() {
48 var createdCallbackCalled = false;
49 var assocDoc = document.implementation.createDocument("http://www.w3.org/1999/xhtml", "html", null);
50 var somediv = assocDoc.createElement("div");
51
52 var proto = Object.create(HTMLElement.prototype);
53 proto.createdCallback = function() {
54 is(createdCallbackCalled, false, "created callback should only be called once in this tests.");
55 createdCallbackCalled = true;
56 runNextTest();
57 };
58
59 assocDoc.registerElement("x-assoc-doc-with-ns-callback-elem", { prototype: proto });
60 document.createElement("x-assoc-doc-with-ns-callback-elem");
61 }
62
63 function registerNoRegistryDoc() {
64 var assocDoc = document.implementation.createDocument(null, "html");
65 try {
66 assocDoc.registerElement("x-dummy", { prototype: Object.create(HTMLElement.prototype) });
67 ok(false, "Registring element in document without registry should throw.");
68 } catch (ex) {
69 ok(true, "Registring element in document without registry should throw.");
70 }
71
72 runNextTest();
73 }
74
75 function runNextTest() {
76 if (testFunctions.length > 0) {
77 var nextTestFunction = testFunctions.shift();
78 nextTestFunction();
79 }
80 }
81
82 var testFunctions = [
83 createdCallbackFromAssociatedDoc,
84 createdCallbackFromMainDoc,
85 createdCallbackFromDocHTMLNamespace,
86 registerNoRegistryDoc,
87 SimpleTest.finish
88 ];
89
90 SimpleTest.waitForExplicitFinish();
91
92 runNextTest();
93 </script>
94 </body>
95 </html>

mercurial