Adding Peter Thatcher to the owners file.
[chromium-blink-merge.git] / cc / output / begin_frame_args_unittest.cc
blob877a857c63215235dc1148f017d7455545645806
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"
11 #include "ui/gfx/frame_time.h"
13 namespace cc {
14 namespace {
16 TEST(BeginFrameArgsTest, Helpers) {
17 // Quick create methods work
18 BeginFrameArgs args0 = CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE);
19 EXPECT_TRUE(args0.IsValid()) << args0;
21 BeginFrameArgs args1 =
22 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 0, -1);
23 EXPECT_FALSE(args1.IsValid()) << args1;
25 BeginFrameArgs args2 =
26 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 1, 2, 3);
27 EXPECT_TRUE(args2.IsValid()) << args2;
28 EXPECT_EQ(1, args2.frame_time.ToInternalValue());
29 EXPECT_EQ(2, args2.deadline.ToInternalValue());
30 EXPECT_EQ(3, args2.interval.ToInternalValue());
31 EXPECT_EQ(BeginFrameArgs::NORMAL, args2.type);
33 BeginFrameArgs args3 =
34 CreateExpiredBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE);
35 EXPECT_TRUE(args3.IsValid()) << args3;
36 EXPECT_GT(gfx::FrameTime::Now(), args3.deadline);
37 EXPECT_EQ(BeginFrameArgs::NORMAL, args3.type);
39 BeginFrameArgs args4 = CreateBeginFrameArgsForTesting(
40 BEGINFRAME_FROM_HERE, 1, 2, 3, BeginFrameArgs::MISSED);
41 EXPECT_TRUE(args4.IsValid()) << args4;
42 EXPECT_EQ(1, args4.frame_time.ToInternalValue());
43 EXPECT_EQ(2, args4.deadline.ToInternalValue());
44 EXPECT_EQ(3, args4.interval.ToInternalValue());
45 EXPECT_EQ(BeginFrameArgs::MISSED, args4.type);
47 // operator==
48 EXPECT_EQ(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 4, 5, 6),
49 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 4, 5, 6));
51 EXPECT_NONFATAL_FAILURE(
52 EXPECT_EQ(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 7, 8, 9,
53 BeginFrameArgs::MISSED),
54 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 7, 8, 9)),
55 "");
57 EXPECT_NONFATAL_FAILURE(
58 EXPECT_EQ(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 4, 5, 6),
59 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 7, 8, 9)),
60 "");
62 // operator<<
63 std::stringstream out1;
64 out1 << args1;
65 EXPECT_EQ("BeginFrameArgs(NORMAL, 0, 0, -1us)", out1.str());
66 std::stringstream out2;
67 out2 << args2;
68 EXPECT_EQ("BeginFrameArgs(NORMAL, 1, 2, 3us)", out2.str());
70 // PrintTo
71 EXPECT_EQ(std::string("BeginFrameArgs(NORMAL, 0, 0, -1us)"),
72 ::testing::PrintToString(args1));
73 EXPECT_EQ(std::string("BeginFrameArgs(NORMAL, 1, 2, 3us)"),
74 ::testing::PrintToString(args2));
77 TEST(BeginFrameArgsTest, Create) {
78 // BeginFrames are not valid by default
79 BeginFrameArgs args1;
80 EXPECT_FALSE(args1.IsValid()) << args1;
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