summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_anonymousContent_manipulate_content.html
blob: eb4bcb6be38561bc88153717631916128eb5f2db (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1020244
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1020244 - Manipulate content created with the AnonymousContent API</title>
  <script 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=1020244">Mozilla Bug 1020244</a>
<div>
  <div id="test-element" class="test-class" test="test">text content</div>
</div>
  <script type="application/javascript">

  // Insert content
  let chromeDocument = SpecialPowers.wrap(document);
  let testElement = document.querySelector("div");
  let anonymousContent = chromeDocument.insertAnonymousContent(testElement);

  // Test getting/setting text content.
  is(anonymousContent.getTextContentForElement("test-element"),
    "text content", "Textcontent for the test element is correct");

  anonymousContent.setTextContentForElement("test-element",
    "updated text content");
  is(anonymousContent.getTextContentForElement("test-element"),
    "updated text content",
    "Textcontent for the test element is correct after update");

  // Test that modifying the original DOM element doesn't change the inserted
  // element.
  testElement.removeAttribute("test");
  is(anonymousContent.getAttributeForElement("test-element", "test"),
    "test",
    "Removing attributes on the original DOM node does not change the inserted node");

  testElement.setAttribute("test", "test-updated");
  is(anonymousContent.getAttributeForElement("test-element", "test"),
    "test",
    "Setting attributes on the original DOM node does not change the inserted node");

  // Test getting/setting/removing attributes on the inserted element and test
  // that this doesn't change the original DOM element.
  is(anonymousContent.getAttributeForElement("test-element", "class"),
    "test-class", "Class attribute for the test element is correct");

  anonymousContent.setAttributeForElement("test-element", "class",
    "updated-test-class");
  is(anonymousContent.getAttributeForElement("test-element", "class"),
    "updated-test-class",
    "Class attribute for the test element is correct after update");
  ok(testElement.getAttribute("class") !== "updated-test-class",
    "Class attribute change on the inserted node does not change the original DOM node");

  anonymousContent.removeAttributeForElement("test-element", "class");
  is(anonymousContent.getAttributeForElement("test-element", "class"), null,
    "Class attribute for the test element was removed");

  let anim = anonymousContent.setAnimationForElement("test-element", [
    { transform: 'translateY(0px)' },
    { transform: 'translateY(-300px)' }
  ], 2000);
  is(anim.playState, "running", "Animation should be running");
  anim.cancel();
  is(anim.playState, "idle", "Animation should have stopped immediately");

  chromeDocument.removeAnonymousContent(anonymousContent);
  </script>
</body>
</html>