summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/layout/layout_progress_test.cc
blob: 82e287162c4fcd18c064ea7c85b3a354e1a9b6ed (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
// 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 "third_party/blink/renderer/core/layout/layout_progress.h"

#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/html/html_element.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"

namespace blink {

class LayoutProgressTest : public RenderingTest {
 public:
  static bool IsAnimationTimerActive(const LayoutProgress* o) {
    return o->IsAnimationTimerActive();
  }
  static bool IsAnimatiing(const LayoutProgress* o) { return o->IsAnimating(); }
};

TEST_F(LayoutProgressTest, AnimationScheduling) {
  RenderingTest::SetBodyInnerHTML(
      "<progress id=\"progressElement\" value=0.3 max=1.0></progress>");
  UpdateAllLifecyclePhasesForTest();
  Element* progress_element =
      GetDocument().getElementById(AtomicString("progressElement"));
  LayoutProgress* layout_progress =
      ToLayoutProgress(progress_element->GetLayoutObject());

  // Verify that we do not schedule a timer for a determinant progress element
  EXPECT_FALSE(LayoutProgressTest::IsAnimationTimerActive(layout_progress));
  EXPECT_FALSE(LayoutProgressTest::IsAnimatiing(layout_progress));

  progress_element->removeAttribute("value");
  UpdateAllLifecyclePhasesForTest();

  // Verify that we schedule a timer for an indeterminant progress element
  EXPECT_TRUE(LayoutProgressTest::IsAnimationTimerActive(layout_progress));
  EXPECT_TRUE(LayoutProgressTest::IsAnimatiing(layout_progress));

  progress_element->setAttribute(html_names::kValueAttr, "0.7");
  UpdateAllLifecyclePhasesForTest();

  // Verify that we cancel the timer for a determinant progress element
  EXPECT_FALSE(LayoutProgressTest::IsAnimationTimerActive(layout_progress));
  EXPECT_FALSE(LayoutProgressTest::IsAnimatiing(layout_progress));
}

}  // namespace blink