Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / cc / output / begin_frame_args_unittest.cc
blobc6f5a4203c9afc109ec628ccb19dacd708024bc8
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <string>
7 #include "cc/output/begin_frame_args.h"
8 #include "cc/test/begin_frame_args_test.h"
9 #include "testing/gtest/include/gtest/gtest-spi.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace cc {
13 namespace {
15 TEST(BeginFrameArgsTest, Helpers) {
16 // Quick create methods work
17 BeginFrameArgs args0 = CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE);
18 EXPECT_TRUE(args0.IsValid()) << args0;
20 BeginFrameArgs args1 =
21 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 0, -1);
22 EXPECT_FALSE(args1.IsValid()) << args1;
24 BeginFrameArgs args2 =
25 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 1, 2, 3);
26 EXPECT_TRUE(args2.IsValid()) << args2;
27 EXPECT_EQ(1, args2.frame_time.ToInternalValue());
28 EXPECT_EQ(2, args2.deadline.ToInternalValue());
29 EXPECT_EQ(3, args2.interval.ToInternalValue());
30 EXPECT_EQ(BeginFrameArgs::NORMAL, args2.type);
32 BeginFrameArgs args3 =
33 CreateExpiredBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE);
34 EXPECT_TRUE(args3.IsValid()) << args3;
35 EXPECT_GT(base::TimeTicks::Now(), args3.deadline);
36 EXPECT_EQ(BeginFrameArgs::NORMAL, args3.type);
38 BeginFrameArgs args4 = CreateBeginFrameArgsForTesting(
39 BEGINFRAME_FROM_HERE, 1, 2, 3, BeginFrameArgs::MISSED);
40 EXPECT_TRUE(args4.IsValid()) << args4;
41 EXPECT_EQ(1, args4.frame_time.ToInternalValue());
42 EXPECT_EQ(2, args4.deadline.ToInternalValue());
43 EXPECT_EQ(3, args4.interval.ToInternalValue());
44 EXPECT_EQ(BeginFrameArgs::MISSED, args4.type);
46 // operator==
47 EXPECT_EQ(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 4, 5, 6),
48 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 4, 5, 6));
50 EXPECT_NONFATAL_FAILURE(
51 EXPECT_EQ(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 7, 8, 9,
52 BeginFrameArgs::MISSED),
53 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 7, 8, 9)),
54 "");
56 EXPECT_NONFATAL_FAILURE(
57 EXPECT_EQ(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 4, 5, 6),
58 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 7, 8, 9)),
59 "");
61 // operator<<
62 std::stringstream out1;
63 out1 << args1;
64 EXPECT_EQ("BeginFrameArgs(NORMAL, 0, 0, -1us)", out1.str());
65 std::stringstream out2;
66 out2 << args2;
67 EXPECT_EQ("BeginFrameArgs(NORMAL, 1, 2, 3us)", out2.str());
69 // PrintTo
70 EXPECT_EQ(std::string("BeginFrameArgs(NORMAL, 0, 0, -1us)"),
71 ::testing::PrintToString(args1));
72 EXPECT_EQ(std::string("BeginFrameArgs(NORMAL, 1, 2, 3us)"),
73 ::testing::PrintToString(args2));
76 TEST(BeginFrameArgsTest, Create) {
77 // BeginFrames are not valid by default
78 BeginFrameArgs args1;
79 EXPECT_FALSE(args1.IsValid()) << args1;
80 EXPECT_TRUE(args1.on_critical_path);
82 BeginFrameArgs args2 = BeginFrameArgs::Create(
83 BEGINFRAME_FROM_HERE, base::TimeTicks::FromInternalValue(1),
84 base::TimeTicks::FromInternalValue(2),
85 base::TimeDelta::FromInternalValue(3), BeginFrameArgs::NORMAL);
86 EXPECT_TRUE(args2.IsValid()) << args2;
87 EXPECT_EQ(1, args2.frame_time.ToInternalValue()) << args2;
88 EXPECT_EQ(2, args2.deadline.ToInternalValue()) << args2;
89 EXPECT_EQ(3, args2.interval.ToInternalValue()) << args2;
90 EXPECT_EQ(BeginFrameArgs::NORMAL, args2.type) << args2;
93 #ifndef NDEBUG
94 TEST(BeginFrameArgsTest, Location) {
95 tracked_objects::Location expected_location = BEGINFRAME_FROM_HERE;
97 BeginFrameArgs args = CreateBeginFrameArgsForTesting(expected_location);
98 EXPECT_EQ(expected_location.ToString(), args.created_from.ToString());
100 #endif
102 } // namespace
103 } // namespace cc