summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/webcomponents/test_fallback_dest_insertion_points.html
blob: 4eefa165f2e2a76f4b131db0bd2475bd8eef6389 (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=999999
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 999999</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=999999">Mozilla Bug 999999</a>
<p id="display"></p>
<div id="content">
<div id="shadowhost"></div>
</div>
<pre id="test">
</pre>
<script type="application/javascript">

/** Test for Bug 999999 **/
var host = document.getElementById("shadowhost");

// Test destination insertion points of node distributed to content element.
var shadowRoot = host.createShadowRoot();
shadowRoot.innerHTML = '<div id="innerhost"><content id="innercontent"></content></div>';

var fallback = document.createElement("span");
var innerContent = shadowRoot.getElementById("innercontent");

innerContent.appendChild(fallback);

is(fallback.getDestinationInsertionPoints().length, 1, "Active fallback content should be distributed to insertion point.");
is(fallback.getDestinationInsertionPoints()[0], innerContent, "Insertion point should be in list of destination insertion points.");

// Test destination insertion points of reprojected fallback content.
var innerHost = shadowRoot.getElementById("innerhost");
var innerShadowRoot = innerHost.createShadowRoot();
innerShadowRoot.innerHTML = '<content id="innerinnercontent"></content>';

var innerInnerContent = innerShadowRoot.getElementById("innerinnercontent");

is(fallback.getDestinationInsertionPoints().length, 2, "Fallback content should have been distributed into parent and reprojected into another insertion point.");
is(fallback.getDestinationInsertionPoints()[1], innerInnerContent, "Destination insertion points should contain content element to which the node was reprojected.");

// Test destination insertion points of fallback content that was dropped due to content element matching a node in the host.
var span = document.createElement("span");
host.appendChild(span);

is(fallback.getDestinationInsertionPoints().length, 0, "After dropping insertion points, fallback content should not have any nodes in destination insertion points list.");

// Test destination insertion points of fallback content after reactivating by dropping matched content on host.
host.removeChild(span);
is(fallback.getDestinationInsertionPoints().length, 2, "Fallback content should have 2 destination insertion points after being reactivated.");
is(fallback.getDestinationInsertionPoints()[0], innerContent, "First destination insertion point should be the parent content");
is(fallback.getDestinationInsertionPoints()[1], innerInnerContent, "Second destination insertion point should be the content to which the node is reprojected.");

// Test destination insertion points of fallback content after removed from the tree.
innerContent.removeChild(fallback);
is(fallback.getDestinationInsertionPoints().length, 0, "Fallback content is no longer fallback content, destination insertion points should be empty.");

// Test destination insertion points of child of non-insertion point content element.
var notInsertionPointContent = document.createElement("content");
var notFallback = document.createElement("span");
notInsertionPointContent.appendChild(notFallback);
is(notFallback.getDestinationInsertionPoints().length, 0, "Child of non-insertion point content should not be distributed to any nodes.");

</script>
</body>
</html>