Index: third_party/WebKit/Source/core/animation/CompositorAnimationsSimTest.cpp |
diff --git a/third_party/WebKit/Source/core/animation/CompositorAnimationsSimTest.cpp b/third_party/WebKit/Source/core/animation/CompositorAnimationsSimTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..dc89538b0d60487b46bebc5a2c372b1e3f14b18d |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/animation/CompositorAnimationsSimTest.cpp |
@@ -0,0 +1,66 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+ |
+#include "core/animation/AnimationTimeline.h" |
+#include "core/animation/ElementAnimations.h" |
+#include "web/tests/sim/SimCompositor.h" |
+#include "web/tests/sim/SimDisplayItemList.h" |
+#include "web/tests/sim/SimRequest.h" |
+#include "web/tests/sim/SimTest.h" |
+ |
+namespace blink { |
+ |
+class CompositorAnimationsSimTest : public SimTest { |
+public: |
+}; |
+ |
+TEST_F(CompositorAnimationsSimTest, CancelCompositorAnimationIfAnimationDisposed) |
+{ |
+ const String html = "<html><body>" |
+ "<div id=element></div>" |
+ "<script>" |
+ "element.animate([{opacity: 0}, {opacity: 1}], {duration: 1});" |
+ "requestAnimationFrame(() => {" |
+ " requestAnimationFrame(() => {" |
+ " element.animate([{opacity: 1}, {opacity: 0}], {duration: 1});" |
+ " });" |
+ "});" |
+ "</script>" |
+ "</body></html>"; |
+ SimRequest request("https://example.com/", "text/html"); |
+ |
+ loadURL("https://example.com/"); |
+ request.complete(html); |
+ |
+ // 1st animation frame. |
+ compositor().beginFrame(); |
+ |
+ Element* element = toHTMLElement(document().getElementById("element")); |
+ EXPECT_TRUE(element); |
+ EXPECT_TRUE(element->hasAnimations()); |
+ |
+ ElementAnimations* animations = element->elementAnimations(); |
+ EXPECT_EQ(1u, animations->animations().size()); |
+ |
+ for (const auto& entry : animations->animations()) { |
+ Animation* animation = entry.key; |
+ EXPECT_TRUE(animation->hasActiveAnimationsOnCompositor()); |
+ } |
+ |
+ // Destroy compositor animation players. |
+ document().timeline().dispose(); |
+ |
+ // 2nd animation frame. |
+ // Cancel incompatible compositor animations. This shouldn't crash. |
+ compositor().beginFrame(); |
+ |
+ EXPECT_EQ(2u, animations->animations().size()); |
+ for (const auto& entry : animations->animations()) { |
+ Animation* animation = entry.key; |
+ EXPECT_FALSE(animation->hasActiveAnimationsOnCompositor()); |
+ } |
+} |
+ |
+} // namespace blink |