OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "cc/output/begin_frame_args.h" | 7 #include "cc/output/begin_frame_args.h" |
8 #include "cc/test/begin_frame_args_test.h" | 8 #include "cc/test/begin_frame_args_test.h" |
9 #include "testing/gtest/include/gtest/gtest-spi.h" | 9 #include "testing/gtest/include/gtest/gtest-spi.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/gfx/frame_time.h" | 11 #include "ui/gfx/frame_time.h" |
12 | 12 |
13 namespace cc { | 13 namespace cc { |
14 namespace { | 14 namespace { |
15 | 15 |
16 TEST(BeginFrameArgsTest, Helpers) { | 16 TEST(BeginFrameArgsTest, Helpers) { |
17 // Quick create methods work | 17 // Quick create methods work |
18 BeginFrameArgs args0 = CreateBeginFrameArgsForTesting(); | 18 BeginFrameArgs args0 = CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
19 EXPECT_TRUE(args0.IsValid()) << args0; | 19 EXPECT_TRUE(args0.IsValid()) << args0; |
20 | 20 |
21 BeginFrameArgs args1 = CreateBeginFrameArgsForTesting(0, 0, -1); | 21 BeginFrameArgs args1 = |
| 22 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 0, -1); |
22 EXPECT_FALSE(args1.IsValid()) << args1; | 23 EXPECT_FALSE(args1.IsValid()) << args1; |
23 | 24 |
24 BeginFrameArgs args2 = CreateBeginFrameArgsForTesting(1, 2, 3); | 25 BeginFrameArgs args2 = |
| 26 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 1, 2, 3); |
25 EXPECT_TRUE(args2.IsValid()) << args2; | 27 EXPECT_TRUE(args2.IsValid()) << args2; |
26 EXPECT_EQ(1, args2.frame_time.ToInternalValue()); | 28 EXPECT_EQ(1, args2.frame_time.ToInternalValue()); |
27 EXPECT_EQ(2, args2.deadline.ToInternalValue()); | 29 EXPECT_EQ(2, args2.deadline.ToInternalValue()); |
28 EXPECT_EQ(3, args2.interval.ToInternalValue()); | 30 EXPECT_EQ(3, args2.interval.ToInternalValue()); |
| 31 EXPECT_EQ(BeginFrameArgs::NORMAL, args2.type); |
29 | 32 |
30 BeginFrameArgs args3 = CreateExpiredBeginFrameArgsForTesting(); | 33 BeginFrameArgs args3 = |
| 34 CreateExpiredBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
31 EXPECT_TRUE(args3.IsValid()) << args3; | 35 EXPECT_TRUE(args3.IsValid()) << args3; |
32 EXPECT_GT(gfx::FrameTime::Now(), args3.deadline); | 36 EXPECT_GT(gfx::FrameTime::Now(), args3.deadline); |
| 37 EXPECT_EQ(BeginFrameArgs::NORMAL, args3.type); |
| 38 |
| 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); |
33 | 46 |
34 // operator== | 47 // operator== |
35 EXPECT_EQ(CreateBeginFrameArgsForTesting(4, 5, 6), | 48 EXPECT_EQ(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 4, 5, 6), |
36 CreateBeginFrameArgsForTesting(4, 5, 6)); | 49 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 4, 5, 6)); |
37 | 50 |
38 EXPECT_NONFATAL_FAILURE(EXPECT_EQ(CreateBeginFrameArgsForTesting(4, 5, 6), | 51 EXPECT_NONFATAL_FAILURE( |
39 CreateBeginFrameArgsForTesting(7, 8, 9)), | 52 EXPECT_EQ(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 7, 8, 9, |
40 ""); | 53 BeginFrameArgs::MISSED), |
| 54 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 7, 8, 9)), |
| 55 ""); |
| 56 |
| 57 EXPECT_NONFATAL_FAILURE( |
| 58 EXPECT_EQ(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 4, 5, 6), |
| 59 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 7, 8, 9)), |
| 60 ""); |
41 | 61 |
42 // operator<< | 62 // operator<< |
43 std::stringstream out1; | 63 std::stringstream out1; |
44 out1 << args1; | 64 out1 << args1; |
45 EXPECT_EQ("BeginFrameArgs(0, 0, -1us)", out1.str()); | 65 EXPECT_EQ("BeginFrameArgs(NORMAL, 0, 0, -1us)", out1.str()); |
46 std::stringstream out2; | 66 std::stringstream out2; |
47 out2 << args2; | 67 out2 << args2; |
48 EXPECT_EQ("BeginFrameArgs(1, 2, 3us)", out2.str()); | 68 EXPECT_EQ("BeginFrameArgs(NORMAL, 1, 2, 3us)", out2.str()); |
49 | 69 |
50 // PrintTo | 70 // PrintTo |
51 EXPECT_EQ(std::string("BeginFrameArgs(0, 0, -1us)"), | 71 EXPECT_EQ(std::string("BeginFrameArgs(NORMAL, 0, 0, -1us)"), |
52 ::testing::PrintToString(args1)); | 72 ::testing::PrintToString(args1)); |
53 EXPECT_EQ(std::string("BeginFrameArgs(1, 2, 3us)"), | 73 EXPECT_EQ(std::string("BeginFrameArgs(NORMAL, 1, 2, 3us)"), |
54 ::testing::PrintToString(args2)); | 74 ::testing::PrintToString(args2)); |
55 } | 75 } |
56 | 76 |
57 TEST(BeginFrameArgsTest, Create) { | 77 TEST(BeginFrameArgsTest, Create) { |
58 // BeginFrames are not valid by default | 78 // BeginFrames are not valid by default |
59 BeginFrameArgs args1; | 79 BeginFrameArgs args1; |
60 EXPECT_FALSE(args1.IsValid()) << args1; | 80 EXPECT_FALSE(args1.IsValid()) << args1; |
61 | 81 |
62 BeginFrameArgs args2 = | 82 BeginFrameArgs args2 = BeginFrameArgs::Create( |
63 BeginFrameArgs::Create(base::TimeTicks::FromInternalValue(1), | 83 BEGINFRAME_FROM_HERE, base::TimeTicks::FromInternalValue(1), |
64 base::TimeTicks::FromInternalValue(2), | 84 base::TimeTicks::FromInternalValue(2), |
65 base::TimeDelta::FromInternalValue(3)); | 85 base::TimeDelta::FromInternalValue(3), BeginFrameArgs::NORMAL); |
66 EXPECT_TRUE(args2.IsValid()) << args2; | 86 EXPECT_TRUE(args2.IsValid()) << args2; |
67 EXPECT_EQ(1, args2.frame_time.ToInternalValue()) << args2; | 87 EXPECT_EQ(1, args2.frame_time.ToInternalValue()) << args2; |
68 EXPECT_EQ(2, args2.deadline.ToInternalValue()) << args2; | 88 EXPECT_EQ(2, args2.deadline.ToInternalValue()) << args2; |
69 EXPECT_EQ(3, args2.interval.ToInternalValue()) << args2; | 89 EXPECT_EQ(3, args2.interval.ToInternalValue()) << args2; |
| 90 EXPECT_EQ(BeginFrameArgs::NORMAL, args2.type) << args2; |
| 91 } |
70 | 92 |
71 base::TimeTicks now = base::TimeTicks::FromInternalValue(1); | 93 #ifndef NDEBUG |
72 EXPECT_EQ(CreateBeginFrameArgsForTesting(1, 0, 16666), | 94 TEST(BeginFrameArgsTest, Location) { |
73 BeginFrameArgs::CreateForSynchronousCompositor(now)); | 95 tracked_objects::Location* loc = BEGINFRAME_FROM_HERE; |
| 96 std::string expected_str; |
| 97 loc->Write(true, true, &expected_str); |
| 98 |
| 99 BeginFrameArgs args = CreateBeginFrameArgsForTesting(loc); |
| 100 std::string actual_str; |
| 101 args.created_by.Write(true, true, &actual_str); |
| 102 EXPECT_EQ(expected_str, actual_str); |
74 } | 103 } |
| 104 #endif |
75 | 105 |
76 } // namespace | 106 } // namespace |
77 } // namespace cc | 107 } // namespace cc |
OLD | NEW |