summaryrefslogtreecommitdiffstats
path: root/browser/components/extensions/test/browser/browser_ext_contentscript_animate.js
blob: bbe90207a457907f97b9299f80109aab61efad9a (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";

add_task(async function test_animate() {
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    "http://mochi.test:8888/"
  );

  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      content_scripts: [
        {
          matches: ["http://mochi.test/*"],
          js: ["content-script.js"],
        },
      ],
    },

    files: {
      "content-script.js": function () {
        let elem = document.getElementsByTagName("body")[0];
        elem.style.border = "2px solid red";

        let anim = elem.animate({ opacity: [1, 0] }, 2000);
        let frames = anim.effect.getKeyframes();
        browser.test.assertEq(
          frames.length,
          2,
          "frames for Element.animate should be non-zero"
        );
        browser.test.assertEq(
          frames[0].opacity,
          "1",
          "first frame opacity for Element.animate should be specified value"
        );
        browser.test.assertEq(
          frames[0].computedOffset,
          0,
          "first frame offset for Element.animate should be 0"
        );
        browser.test.assertEq(
          frames[1].opacity,
          "0",
          "last frame opacity for Element.animate should be specified value"
        );
        browser.test.assertEq(
          frames[1].computedOffset,
          1,
          "last frame offset for Element.animate should be 1"
        );

        browser.test.notifyPass("contentScriptAnimate");
      },
    },
  });

  await extension.startup();
  await extension.awaitFinish("contentScriptAnimate");
  await extension.unload();

  BrowserTestUtils.removeTab(tab);
});

add_task(async function test_KeyframeEffect() {
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    "http://mochi.test:8888/"
  );

  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      content_scripts: [
        {
          matches: ["http://mochi.test/*"],
          js: ["content-script.js"],
        },
      ],
    },

    files: {
      "content-script.js": function () {
        let elem = document.getElementsByTagName("body")[0];
        elem.style.border = "2px solid red";

        let effect = new KeyframeEffect(
          elem,
          [
            { opacity: 1, offset: 0 },
            { opacity: 0, offset: 1 },
          ],
          { duration: 1000, fill: "forwards" }
        );
        let frames = effect.getKeyframes();
        browser.test.assertEq(
          frames.length,
          2,
          "frames for KeyframeEffect ctor should be non-zero"
        );
        browser.test.assertEq(
          frames[0].opacity,
          "1",
          "first frame opacity for KeyframeEffect ctor should be specified value"
        );
        browser.test.assertEq(
          frames[0].computedOffset,
          0,
          "first frame offset for KeyframeEffect ctor should be 0"
        );
        browser.test.assertEq(
          frames[1].opacity,
          "0",
          "last frame opacity for KeyframeEffect ctor should be specified value"
        );
        browser.test.assertEq(
          frames[1].computedOffset,
          1,
          "last frame offset for KeyframeEffect ctor should be 1"
        );

        let animation = new Animation(effect, document.timeline);
        animation.play();

        browser.test.notifyPass("contentScriptKeyframeEffect");
      },
    },
  });

  await extension.startup();
  await extension.awaitFinish("contentScriptKeyframeEffect");
  await extension.unload();

  BrowserTestUtils.removeTab(tab);
});