summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/css-generated-content/pseudo-transition.html
blob: 5b6b1fe00110f97972428779e50ebbe97f19c52b (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
<!DOCTYPE html>

<script src="../../resources/js-test.js"></script>

<style>
#before:before,
#after:after {
    content: "";
    display: block;
    height: 50px;
    width: 50px;
    top: 50px;
    position: relative;
    -webkit-transition: width 2s, top 2s;
    -moz-transition: width 2s, top 2s;
    transition: width 2s, top 2s;
}

#before.transition:before,
#after.transition:after {
    top: 200px;
    height: 10px;
    width: 10px;
}

#before,
#after {
    display: inline-block;
    border: 1px solid black;
    background: red;
}

#after.transition,
#before.transition {
    background: green;
}
</style>

<div id="before"></div>
<div id="after"></div>

<script>
description('Transitions on :before and :after pseudo elements should run');

if (window.testRunner)
    testRunner.dumpAsText();

function getPseudoComputedTop(id)
{
    return Math.round(parseFloat(getComputedStyle(document.getElementById(id), ':' + id).top));
}

// FIXME: This test should be modified so subpixel doesn't cause off by one
// below and it no longer needs shouldBeCloseTo.

function testTransition(id)
{
    var div = document.getElementById(id);
    div.className = 'transition';
    window.div = div;
    shouldBe('div.offsetWidth', '52');
    if (window.internals) {
        internals.pauseAnimations(1);
        shouldBeCloseTo('div.offsetWidth', 20, 1);
        computedTop = getPseudoComputedTop(id);
        shouldBeCloseTo('computedTop', 170, 1);
        internals.pauseAnimations(2);
        shouldBeCloseTo('div.offsetWidth', 12, 1);
        computedTop = getPseudoComputedTop(id);
        shouldBeCloseTo('computedTop', 200, 1);
    } else {
        // This will be flaky, but it's a reasonable approximation for testing
        // in a browser instead of DRT.
        setTimeout(function() {
            window.div = div;
            shouldBeCloseTo('div.offsetWidth', 20, 1);
            computedTop = getPseudoComputedTop(id);
            shouldBeCloseTo('computedTop', 170, 1);
        }, 1000);
        setTimeout(function() {
            window.div = div;
            shouldBeCloseTo('div.offsetWidth', 12, 1);
            computedTop = getPseudoComputedTop(id);
            shouldBeCloseTo('computedTop', 200, 1);
        }, 2000);
    }
}

onload = function() {
    testTransition('before');
    testTransition('after');
    if (window.internals)
        isSuccessfullyParsed();
    else
        setTimeout(isSuccessfullyParsed, 2000);
};
</script>