dom/tests/mochitest/webcomponents/test_document_shared_registry.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/webcomponents/test_document_shared_registry.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=783129
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test shared registry for associated HTML documents.</title>
    1.11 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body>
    1.15 +<div id="container"></div>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=783129">Bug 783129</a>
    1.17 +<script>
    1.18 +var container = document.getElementById("container");
    1.19 +
    1.20 +function createdCallbackFromMainDoc() {
    1.21 +  var createdCallbackCalled = false;
    1.22 +  var assocDoc = document.implementation.createHTMLDocument();
    1.23 +
    1.24 +  var proto = Object.create(HTMLElement.prototype);
    1.25 +  proto.createdCallback = function() {
    1.26 +    is(createdCallbackCalled, false, "created callback should only be called once in this tests.");
    1.27 +    createdCallbackCalled = true;
    1.28 +    runNextTest();
    1.29 +  };
    1.30 +
    1.31 +  assocDoc.registerElement("x-associated-doc-callback-elem", { prototype: proto });
    1.32 +  document.createElement("x-associated-doc-callback-elem");
    1.33 +}
    1.34 +
    1.35 +function createdCallbackFromAssociatedDoc() {
    1.36 +  var createdCallbackCalled = false;
    1.37 +  var assocDoc = document.implementation.createHTMLDocument();
    1.38 +
    1.39 +  var proto = Object.create(HTMLElement.prototype);
    1.40 +  proto.createdCallback = function() {
    1.41 +    is(createdCallbackCalled, false, "created callback should only be called once in this tests.");
    1.42 +    createdCallbackCalled = true;
    1.43 +    runNextTest();
    1.44 +  };
    1.45 +
    1.46 +  assocDoc.registerElement("x-main-doc-callback-elem", { prototype: proto });
    1.47 +  assocDoc.createElement("x-main-doc-callback-elem");
    1.48 +}
    1.49 +
    1.50 +function createdCallbackFromDocHTMLNamespace() {
    1.51 +  var createdCallbackCalled = false;
    1.52 +  var assocDoc = document.implementation.createDocument("http://www.w3.org/1999/xhtml", "html", null);
    1.53 +  var somediv = assocDoc.createElement("div");
    1.54 +
    1.55 +  var proto = Object.create(HTMLElement.prototype);
    1.56 +  proto.createdCallback = function() {
    1.57 +    is(createdCallbackCalled, false, "created callback should only be called once in this tests.");
    1.58 +    createdCallbackCalled = true;
    1.59 +    runNextTest();
    1.60 +  };
    1.61 +
    1.62 +  assocDoc.registerElement("x-assoc-doc-with-ns-callback-elem", { prototype: proto });
    1.63 +  document.createElement("x-assoc-doc-with-ns-callback-elem");
    1.64 +}
    1.65 +
    1.66 +function registerNoRegistryDoc() {
    1.67 +  var assocDoc = document.implementation.createDocument(null, "html");
    1.68 +  try {
    1.69 +    assocDoc.registerElement("x-dummy", { prototype: Object.create(HTMLElement.prototype) });
    1.70 +    ok(false, "Registring element in document without registry should throw.");
    1.71 +  } catch (ex) {
    1.72 +    ok(true, "Registring element in document without registry should throw.");
    1.73 +  }
    1.74 +
    1.75 +  runNextTest();
    1.76 +}
    1.77 +
    1.78 +function runNextTest() {
    1.79 +  if (testFunctions.length > 0) {
    1.80 +    var nextTestFunction = testFunctions.shift();
    1.81 +    nextTestFunction();
    1.82 +  }
    1.83 +}
    1.84 +
    1.85 +var testFunctions = [
    1.86 +  createdCallbackFromAssociatedDoc,
    1.87 +  createdCallbackFromMainDoc,
    1.88 +  createdCallbackFromDocHTMLNamespace,
    1.89 +  registerNoRegistryDoc,
    1.90 +  SimpleTest.finish
    1.91 +];
    1.92 +
    1.93 +SimpleTest.waitForExplicitFinish();
    1.94 +
    1.95 +runNextTest();
    1.96 +</script>
    1.97 +</body>
    1.98 +</html>

mercurial