summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/webcomponents/test_document_shared_registry.html
blob: 76c2ea8ec6b2969d8b3e7e39c65b773120f47482 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=783129
-->
<head>
  <title>Test shared registry for associated HTML documents.</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<div id="container"></div>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=783129">Bug 783129</a>
<script>
var container = document.getElementById("container");

function createdCallbackFromMainDoc() {
  var createdCallbackCalled = false;
  var assocDoc = document.implementation.createHTMLDocument();

  var proto = Object.create(HTMLElement.prototype);
  proto.createdCallback = function() {
    is(createdCallbackCalled, false, "created callback should only be called once in this tests.");
    createdCallbackCalled = true;
    runNextTest();
  };

  assocDoc.registerElement("x-associated-doc-callback-elem", { prototype: proto });
  document.createElement("x-associated-doc-callback-elem");
}

function createdCallbackFromDocHTMLNamespace() {
  var createdCallbackCalled = false;
  var assocDoc = document.implementation.createDocument("http://www.w3.org/1999/xhtml", "html", null);
  var somediv = assocDoc.createElement("div");

  var proto = Object.create(HTMLElement.prototype);
  proto.createdCallback = function() {
    is(createdCallbackCalled, false, "created callback should only be called once in this tests.");
    createdCallbackCalled = true;
    runNextTest();
  };

  assocDoc.registerElement("x-assoc-doc-with-ns-callback-elem", { prototype: proto });
  document.createElement("x-assoc-doc-with-ns-callback-elem");
}

function registerNoRegistryDoc() {
  var assocDoc = document.implementation.createDocument(null, "html");
  try {
    assocDoc.registerElement("x-dummy", { prototype: Object.create(HTMLElement.prototype) });
    ok(false, "Registring element in document without registry should throw.");
  } catch (ex) {
    ok(true, "Registring element in document without registry should throw.");
  }

  runNextTest();
}

function runNextTest() {
  if (testFunctions.length > 0) {
    var nextTestFunction = testFunctions.shift();
    nextTestFunction();
  }
}

var testFunctions = [
  createdCallbackFromMainDoc,
  createdCallbackFromDocHTMLNamespace,
  registerNoRegistryDoc,
  SimpleTest.finish
];

SimpleTest.waitForExplicitFinish();

runNextTest();
</script>
</body>
</html>